Java 在SpringSecurity中AuthenticationProvider成功后执行某些操作
我有多个身份验证提供程序(MyOwn、Kerberos、Local)。认证成功后,我想用密码保存一些信息。但是每个提供者后面的代码都是不同的。因此,我希望在authenticationProvider成功后立即运行此代码。我该怎么做Java 在SpringSecurity中AuthenticationProvider成功后执行某些操作,java,spring-security,Java,Spring Security,我有多个身份验证提供程序(MyOwn、Kerberos、Local)。认证成功后,我想用密码保存一些信息。但是每个提供者后面的代码都是不同的。因此,我希望在authenticationProvider成功后立即运行此代码。我该怎么做 若我使用AuthenticationSuccessHandler,它将在提供者的任何成功后运行。如果我在CustomUserDetails服务中编写代码,我将无法访问其中的密码信息。您可以注册一个侦听器,用于AuthenticationSuccessEvent Pr
若我使用AuthenticationSuccessHandler,它将在提供者的任何成功后运行。如果我在CustomUserDetails服务中编写代码,我将无法访问其中的密码信息。您可以注册一个侦听器,用于
AuthenticationSuccessEvent
ProviderManager
将身份验证委托给其注册的每个AuthenticationProvider
。其中一个AuthenticationProvider
成功验证后,ProviderManager
将通过其AuthenticationEventPublisher
发布AuthenticationSuccessEvent
如果您希望接收此事件并获得对身份验证的访问权
,以下Java配置将在该事件的上下文中注册ApplicationListener
bean:
@Bean
public ApplicationListener<AuthenticationSuccessEvent> authenticationSuccessEventListener() {
return new ApplicationListener<AuthenticationSuccessEvent>() {
@Override
void onApplicationEvent(AuthenticationSuccessEvent event) {
Authentication authentication = event.getAuthentication();
// TODO
}
};
}
@Bean
公共应用程序侦听器: