3

i created a custom authentication failure handler like this:

public class TrackerAuthFailureHandler extends SimpleUrlAuthenticationFailureHandler{

        @Override
        public void onAuthenticationFailure(HttpServletRequest request,
                HttpServletResponse response, AuthenticationException exception)
                throws IOException, ServletException {
            super.onAuthenticationFailure(request, response, exception);

            if(exception.getClass().isAssignableFrom(DisabledException.class)){
                setDefaultFailureUrl("/accountRecovery");
            }
        }
    }

and i created a bean like this:

@Bean
    public AuthenticationFailureHandler trackerAuthFailureHandler(){
        SimpleUrlAuthenticationFailureHandler handler=new SimpleUrlAuthenticationFailureHandler();
        return handler;
    }

and spring config like this:

    @Autowired
    private TrackerAuthFailureHandler trackerAuthFailureHandler;

    @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .authorizeRequests()
                    .anyRequest().authenticated()
                    .and()
                .formLogin()
                    .loginPage("/login")
                    .permitAll()
                    .failureHandler(trackerAuthFailureHandler);
    }

But bean not found exception occurred . any ideas?

1
  • 1
    you initialized SimpleUrlAuthenticationFailureHandler instead of TrackerAuthFailureHandler try new TrackerAuthFailureHandler () Commented Sep 8, 2015 at 7:50

1 Answer 1

4

When you use annotation injection way then you must use @Component in top of class TrackerAuthFailureHandler. like this:.

@Component
public class TrackerAuthFailureHandler extends SimpleUrlAuthenticationFailureHandler{
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.