Results 1 to 2 of 2

Thread: Manually fire AuthenticationSuccessHandler

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    Default Manually fire AuthenticationSuccessHandler

    Hi, I want to provide the user an alternative means of logging in with a token. I already handle authenticating the user in the PreAuthenticationFilter class but then I need to fire my AuthenticationSuccessHandler.onAuthenticationSucce ss() which does a super.onAuthenticationSuccess() which fires the method in it's base class of SavedRequestAwareAuthenticationSuccessHandler.

    How can I fire the AuthenticationSuccessHandler from my preauthentication filter? I tried setting the authentication of the SecurityContextHolder thinking it would automatically fire off the AuthenticationSuccessHandler but it does not. This is how I tried to do that:

    Authentication authentication = new UsernamePasswordAuthenticationToken(Username, Password);
    SecurityContextHolder.getContext().setAuthenticati on(authentication);

    Unfortunately that doesn't work though. So I need to know how to fire the AuthenticationSuccessHandler from a preauthentication filter.

    Thank you!

  2. #2
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    AuthenticationSuccessHandler typically commits the response (i.e. by doing a redirect or forward). Since AbstractPreAuthenticatedProcessingFilter typically expects something further down in the FilterChain to commit the response it does not an AuthenticationSuccessHandler on it. Therefore your subclass will need to allow the AuthenticationSuccessHandler to be injected and invoke it in the successfulAuthentication method. Keep in mind that the FilterChain will continue, so you need to ensure that your AuthenticationSuccessHandler does not commit the response.
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •