title: How to Intercept Spring Security login request before its processing?
body: <p>I am trying to intercept the login request <strong>before</strong> spring security start its processing or it reaches to spring security interceptor. I want to do this because I have to do some validations on the user's input. So, I have created a interceptor from <strong>HandlerInterceptorAdapter</strong> class but it is not working.</p>
  
  <p><strong>So what I want to do is :</strong></p>
  
  <p>When any user try to login with username and password then this request must reaches to <strong>LoginRequestInterceptor</strong> first. Do some validation on user inputs and on success pass this request to <strong>spring security login processing url</strong> other wise to some other url.</p>
  
  <p>But in my case the request is reaching directly to the spring security without visiting the interceptor.</p>
  
  <p><strong>Interceptor class</strong></p>
  
  <pre><code>public class LoginRequestInterceptor extends HandlerInterceptorAdapter {
  
      private static final Logger logger = LogManager.getLogger(LoginRequestInterceptor.class);
  
      @Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
              throws Exception {
          logger.debug("Interceptor working pre");
          return super.preHandle(request, response, handler);
      }
  </code></pre>
  
  <p><strong>Spring Security xml</strong> </p>
  
  <pre><code>&lt;http auto-config="true" use-expressions="true"&gt;
      &lt;intercept-url  pattern="/Candidate/**" access="hasRole('ROLE_USER')" /&gt;
      &lt;!-- access denied page --&gt;
      &lt;access-denied-handler error-page="/403" /&gt;
      &lt;form-login 
          login-processing-url="/login"
          login-page="/" 
          default-target-url="/Candidate"
          authentication-failure-url="/error=1" 
          username-parameter="registerationid"
          password-parameter="password" 
          /&gt;
      &lt;logout logout-success-url="/?logout" /&gt;
      &lt;custom-filter ref="loginRequestInterceptors" position="FIRST"/&gt;
      &lt;!-- enable csrf protection --&gt;
      &lt;csrf /&gt;
  &lt;/http&gt;
  
  &lt;authentication-manager id="authenticationManager"&gt;
      &lt;authentication-provider user-service-ref="candidateDetailServices" /&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p><strong>Spring dispatcher xml</strong></p>
  
  <pre><code>    &lt;bean id="loginRequestInterceptor" class="org.ibps.clerk.inteceptors.login.LoginRequestInterceptor"&gt;&lt;/bean&gt;
      &lt;mvc:interceptors&gt;
          &lt;mvc:interceptor&gt;
              &lt;mvc:mapping path="/login"/&gt;
              &lt;ref bean="loginRequestInterceptor"/&gt;
          &lt;/mvc:interceptor&gt;
      &lt;/mvc:interceptors&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>So at last I wanted to know whether it is possible or not? If Yes then please share the link or solution. </p>