title: How to maintain how many failed login attempts made by user in a session spring
body: <p>My requirement is , i want to lock a user if user tries to login more than 3 times with wrong credentials in a session. I want to store the count in a (pre authenticated ) session. </p>
  
  <p>I am using form authentication</p>
  
  <p>spring-security.xml</p>
  
  <pre><code>  &lt;security:form-login login-page="/login" default-target-url="/home" authentication-failure-url="/loginFailed" /&gt;
     &lt;security:logout logout-success-url="/" /&gt;
  </code></pre>
  
  <p>Login Controller: </p>
  
  <pre><code>  @RequestMapping(value = "/login", method = RequestMethod.GET)
      public ModelAndView login() throws Exception {
      return new ModelAndView(UrlRegistry.SIMPLEFI_LOGIN_PAGE);
     }
  
     @RequestMapping(value = "/loginFailed", method = RequestMethod.GET)
      public ModelAndView loginFailed() {
       return new ModelAndView(UrlRegistry.SIMPLEFI_LOGIN_PAGE, "error", "true");
      }
  </code></pre>
  
  <p>From search. I got to know about use of ApplicationListener , but there I can't access the session object so can't store the count there.</p>
  
  <p>Can any one suggest how to implement it?</p>