2016-04-27 51 views
0

私は複数のAuthenticationProviders(MyOwn、Kerberos、Local)を持っています。私は、認証成功後にパスワードを使っていくつかの情報を保存したい。しかし、すべてのプロバイダの後のコードは異なります。ですから、私はこのコードをauthenticationProviderの成功の直後に実行したいと思います。どうやってやるの?SpringSecurityでAuthenticationProviderが成功した後に何かしますか

私がAuthenticationSuccessHandlerを使用する場合、プロバイダからの成功後に実行されます。 CustomUserDetailsS​​erviceの中にコードを書くと、その中のパスワード情報にアクセスできません。

答えて

0

AuthenticationSuccessEventのリスナーを登録できます。

ProviderManagerそれぞれに認証を委任するAuthenticationProviderです。 AuthenticationProviderのいずれかで正常に認証された後、ProviderManagerAuthenticationEventPublisherを通じてAuthenticationSuccessEventを公開します。

あなたはこのイベントを受け取り、Authenticationへのアクセスを得るためにしたい場合は、以下のJavaの設定は、このイベントのために文脈でApplicationListener Beanを登録します:ApplicationListenerため

@Bean 
public ApplicationListener<AuthenticationSuccessEvent> authenticationSuccessEventListener() { 
    return new ApplicationListener<AuthenticationSuccessEvent>() { 

     @Override 
     void onApplicationEvent(AuthenticationSuccessEvent event) { 
       Authentication authentication = event.getAuthentication(); 
       // TODO 
     } 
    }; 
} 

さらにドキュメントはhere見つけることができます:

関連する問題