title: Unable to set a custom authentication failure handler in 4.0 spring security
body: <p>I want to set up custom AuthenticationFailureHandler in my project. Even though I configure my authenticationFailureHandler as below , it is not properly picked up when the sign-in fails.</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
  ..................
  @Inject
  private AjaxAuthenticationFailureHandler ajaxAuthenticationFailureHandler;
  ..................
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
                  .antMatchers("/resources/**").permitAll()
                  .anyRequest().authenticated().and()
              .formLogin().loginPage("/signin").failureHandler(ajaxAuthenticationFailureHandler)
                  .permitAll()
                  .failureUrl("/signin")
                  .defaultSuccessUrl("/search").and()
              .logout()
                  .logoutRequestMatcher(new AntPathRequestMatcher("/signout"))
                  .logoutSuccessUrl("/signin")
                  .permitAll().and().csrf();
      }
  </code></pre>
  
  <p>My custom AuthenticationFailureHandler Class</p>
  
  <pre><code>@Component
  public class AjaxAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
  
      @Override
      public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
                                      AuthenticationException exception) throws IOException, ServletException {
          // Custom code
      }
  }
  </code></pre>
  
  <p>When I debug the application, the method <code>onAuthenticationFailure</code> is called from <code>SimpleUrlAuthenticationFailureHandler</code>, but not in my custom <code>AjaxAuthenticationFailureHandler</code> even though I extend the same <code>SimpleUrlAuthenticationFailureHandler</code>.</p>
  
  <p>What could be the mistake or any missed configuration to resolve the problem?</p>