title: How to correctly update the login date time after successful login with Spring security?
body: <p>I'm using Spring 3.2.0 and the same version of Spring security. On successful login, a user is redirected to one of the protected pages as follows.</p>
  
  <pre><code>public final class LoginSuccessHandler implements AuthenticationSuccessHandler
  {
      @Override
      public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException
      {
          Set&lt;String&gt; roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
          if (roles.contains("ROLE_ADMIN"))
          {
              response.sendRedirect("admin_side/Home.htm");
              return;
          }
      }
  }
  </code></pre>
  
  <p>I'm using Hibernate. How  can I update the login date-time (Last Login) in the database on successful login? I have a submit button on the login page whose <code>POST</code> request doesn't seem to map to a method in its corresponding login controller. The login form's action is actually mapped to the Servlet - <code>j_spring_security_check</code>.</p>
  
  <hr>
  
  <p>The entire <code>spring-security.xml</code> file is as follows, if it is required.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
             http://www.springframework.org/schema/security
             http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
      &lt;http pattern="/Login.htm*" security="none"&gt;&lt;/http&gt;    
  
      &lt;http auto-config='true'&gt;
      &lt;!--&lt;remember-me key="myAppKey"/&gt;--&gt;
          &lt;session-management session-fixation-protection="newSession"&gt;
              &lt;concurrency-control max-sessions="1" error-if-maximum-exceeded="true" /&gt;
          &lt;/session-management&gt;
  
          &lt;intercept-url pattern="/admin_side/**" access="ROLE_ADMIN" requires-channel="any"/&gt;
          &lt;form-login login-page="/" default-target-url="/admin_side/Home.htm" authentication-failure-url="/LoginFailed.htm" authentication-success-handler-ref="loginSuccessHandler"/&gt;
          &lt;logout logout-success-url="/Login.htm" invalidate-session="true" delete-cookies="JSESSIONID"/&gt;
      &lt;/http&gt;
  
      &lt;authentication-manager&gt;
         &lt;authentication-provider&gt;
              &lt;jdbc-user-service data-source-ref="dataSource"
                 users-by-username-query="select email_id, password, enabled from user_table where lower(email_id)=lower(?)"
                 authorities-by-username-query="select ut.email_id, ur.authority from user_table ut, user_roles ur where ut.user_id=ur.user_id and lower(ut.email_id)=lower(?)"/&gt;
         &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
      &lt;beans:bean id="loginSuccessHandler" class="loginsuccesshandler.LoginSuccessHandler"/&gt;
  
      &lt;global-method-security&gt;
          &lt;protect-pointcut expression="execution(* dao.*.*(..))" access="ROLE_ADMIN"/&gt;
      &lt;/global-method-security&gt;
  
      &lt;!--&lt;global-method-security secured-annotations="enabled" /&gt;--&gt;
  &lt;/beans:beans&gt;
  </code></pre>