title: How to redirect to the homepage if the user accesses the login page after being logged in?
body: <p>Here is my spring security config:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;http pattern="/auth/login" security="none" /&gt;
  &lt;http pattern="/auth/loginFailed" security="none" /&gt;
  &lt;http pattern="/resources/**" security="none" /&gt;
  
  &lt;http auto-config="true" access-decision-manager-ref="accessDecisionManager"&gt;
      &lt;intercept-url pattern="/auth/logout" access="permitAll"/&gt;
      &lt;intercept-url pattern="/admin/**" access="ADMINISTRATIVE_ACCESS"/&gt;
      &lt;intercept-url pattern="/**" access="XYZ_ACCESS"/&gt;
  
      &lt;form-login
          login-page="/auth/login"
          authentication-failure-url="/auth/loginFailed"
          authentication-success-handler-ref="authenticationSuccessHandler" /&gt;
      &lt;logout logout-url="/auth/logout" logout-success-url="/auth/login" /&gt;
  &lt;/http&gt;
  </code></pre>
  
  <p>The <code>authenticationSuccessHandler</code> extends the <code>SavedRequestAwareAuthenticationSuccessHandler</code> ensuring that the user is redirected to the page he originally requested.</p>
  
  <p>However, since <code>/auth/login</code> is marked as <code>security="none"</code>, I am unable to successfully redirect the user to the homepage if he accesses the login page after being logged in. I believe this is the right <a href="https://ux.stackexchange.com/questions/26100/what-should-happen-if-the-login-page-is-accessed-post-login">user experience</a> too.</p>
  
  <p>I tried the below too but the <code>Principal</code> object is always <code>null</code>, presumably because of the <code>security="none"</code> attribute again.</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = "/auth/login", method = GET)
  public String showLoginForm(HttpServletRequest request, Principal principal) {
      if(principal != null) {
          return "redirect:/";
      }
  
      return "login";
  }
  </code></pre>