Redirect to home page after login in spring mvc
<p>I have a problem. Suppose I login into the application and accessing different pages and leaving the application ideal for 5 min in <a href="http://localhost:8080/InformationManagement/smartapp/allFileNetStatus" rel="nofollow">http://localhost:8080/InformationManagement/smartapp/allFileNetStatus</a> and then trying to access once the session get expired and get redirected to login page.
Once I enter the credentials it get logged in it get me to <a href="http://localhost:8080/InformationManagement/smartapp/allFileNetStatus" rel="nofollow">http://localhost:8080/InformationManagement/smartapp/allFileNetStatus</a> instead of home page(<a href="http://localhost:8080/InformationManagement/" rel="nofollow">http://localhost:8080/InformationManagement/</a>)</p>

<p>Note: My Login page and Home page URL is same</p>

<p>How can I control this in spring security.</p>

<p>Code:</p>

<pre><code>    &lt;http pattern="/resources" security="none" /&gt;

&lt;http auto-config="true" use-expressions="true"&gt;
    &lt;intercept-url pattern="/login" access="permitAll" /&gt;
    &lt;intercept-url pattern="/logout" access="permitAll" /&gt;
    &lt;intercept-url pattern="/denied" access="hasRole('ROLE_USER')" /&gt;
    &lt;intercept-url pattern="/" access="permitAll" /&gt;
    &lt;intercept-url pattern="/user" access="hasRole('ROLE_USER')" /&gt;
    &lt;intercept-url pattern="/user/create" access="hasRole('ROLE_ADMIN')" /&gt;
    &lt;intercept-url pattern="/user/update"
        access="hasAnyRole('ROLE_READ','ROLE_ADMIN')" /&gt;
&lt;intercept-url pattern="/smartapp/getNewFileNetStatus" access="hasRole('ROLE_SMARTAPP')" /&gt;
&lt;intercept-url pattern="/smartapp/allFileNetStatus" access="hasRole('ROLE_SMARTAPP')" /&gt;
    &lt;intercept-url pattern="/user/alluser" access="hasAnyRole('ROLE_READ','ROLE_ADMIN')" /&gt;
    &lt;intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')" /&gt;

    &lt;form-login login-page="/login" authentication-failure-url="/login/failure"
        default-target-url="/" /&gt;

    &lt;access-denied-handler error-page="/denied" /&gt;

    &lt;logout invalidate-session="true" logout-success-url="/logout/success"
        logout-url="/logout" /&gt;
&lt;/http&gt;



&lt;beans:bean id="daoAuthenticationProvider"
    class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
    &lt;beans:property name="userDetailsService" ref="userDetailsService"&gt;&lt;/beans:property&gt;

&lt;/beans:bean&gt;

&lt;beans:bean id="authenticationManager"
    class="org.springframework.security.authentication.ProviderManager"&gt;
    &lt;beans:property name="providers"&gt;
        &lt;beans:list&gt;
            &lt;beans:ref local="daoAuthenticationProvider" /&gt;
        &lt;/beans:list&gt;
    &lt;/beans:property&gt;
&lt;/beans:bean&gt;

&lt;authentication-manager&gt;
    &lt;authentication-provider user-service-ref="userDetailsService"&gt;
        &lt;password-encoder hash="md5"&gt;&lt;/password-encoder&gt;
    &lt;/authentication-provider&gt;
&lt;/authentication-manager&gt;
</code></pre>

<p></p>

<p>HomeController.java</p>

<pre><code> @Controller
 @RequestMapping("/")
 public class HomeController {

/*
 * @Value("${msg}") private String msg;
 */

   @Autowired
  UserDetailsService userService;

Logger logger = Logger.getLogger(HomeController.class);

@RequestMapping(value = "/help", method = RequestMethod.GET)
public String getAdminPage() {
    return "help";
}

@RequestMapping(method = RequestMethod.GET)
public String getHomePage(Model model, HttpSession session) {

    Authentication auth = SecurityContextHolder.getContext()
            .getAuthentication();

    if (!(auth instanceof AnonymousAuthenticationToken)) {

        /* The user is logged in :) */
        if (logger.isInfoEnabled()) {
            logger.info("User got logged in...");
        }
        int passwordResetValue = userService.userPasswordReset(auth
                .getName());
        session.setAttribute("username",auth.getName());
        System.out.println("username-- set--&gt;"+session.getAttribute("username"));
        System.out.println("passwordResetValue" + passwordResetValue);
        if (passwordResetValue == 0) {
            return "home";
        } else {
            return "redirect:/password/changePassword?value=reset";
        }

    } else {
        if (logger.isInfoEnabled()) {
            logger.info("Redirected to Login Page");
        }
        return "access/login";
    }
}
</code></pre>

<p>AccessController.java</p>

<pre><code> @Controller
@RequestMapping
 public class AccessController {

@RequestMapping(value = "/denied")
public String denied() {
    return "access/denied";
}

@RequestMapping("/login")
public String login() {
    /*System.out.println("message--&gt;" + message);
    model.addAttribute("message", message);*/
    Authentication auth = SecurityContextHolder.getContext()
            .getAuthentication();

    if (!(auth instanceof AnonymousAuthenticationToken)) {
        auth.getPrincipal();
        /* The user is logged in :) */
        System.out.println("eeee");
        return "redirect:/";
    } else {
        System.out.println("Finalalaay" + auth.getDetails());
        return "access/login";
    }
}

@RequestMapping(value = "/login/failure")
public String loginFailure(final RedirectAttributes redirect) {
    String message = "Please verify username and password";
    Authentication auth = SecurityContextHolder.getContext()
            .getAuthentication();

    if (!(auth instanceof AnonymousAuthenticationToken)) {

        /* The user is logged in :) */
        return "redirect:/";
    } else {
        redirect.addFlashAttribute("message", message);
        return "redirect:/login";
    }
}

@RequestMapping(value = "/logout/success")
public String logoutSuccess(final RedirectAttributes redirect) {
    String message = "You have been successfully logged out.";
    redirect.addFlashAttribute("message", message);
    return "redirect:/login";
}
</code></pre>

<p>}</p>