如何在Spring Boot中为预验证检查和后验证检查配置UserDetailsChecker

如何在Spring Boot中为预验证检查和后验证检查配置UserDetailsChecker,spring,spring-boot,spring-security,Spring,Spring Boot,Spring Security,我正在搜索一个“最佳实践”解决方案,用于在Spring Boot中为预验证检查和/或后验证检查配置UserDetailsChecker(请参阅AbstractUserDetailsAuthenticationProvider和daonauthenticationprovider) 是否绝对需要创建自定义的DaoAuthenticationProvider 无法通过WebSecurityConfigurerAdapter或AuthenticationManagerBuilder自定义它?回答我自己

我正在搜索一个“最佳实践”解决方案,用于在Spring Boot中为预验证检查和/或后验证检查配置
UserDetailsChecker
(请参阅
AbstractUserDetailsAuthenticationProvider
daonauthenticationprovider

是否绝对需要创建自定义的
DaoAuthenticationProvider


无法通过
WebSecurityConfigurerAdapter
AuthenticationManagerBuilder
自定义它?

回答我自己的问题:我用
grep
搜索了spring启动源代码(v1.5.13.RELEASE和v2.0.2.RELEASE)——没有结果

至少在这个版本中,如果您想使用额外的认证前或认证后检查,您必须创建一个自定义的
DaoAuthenticationProvider

编辑:短语“您必须创建一个自定义的
DaoAuthenticationProvider
”有点误导。在最近的一个项目中,我以以下方式完成:

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig {

    @Autowired
    public void configureGlobal(
            AuthenticationManagerBuilder auth,
            MyUserAccountService myUserAccountService,
            PasswordEncoder passwordEncoder,
            MessageSourceAccessor messageSourceAccessor
    ) throws Exception {
        DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
        daoAuthenticationProvider.setPasswordEncoder(passwordEncoder);
        daoAuthenticationProvider.setUserDetailsService(myUserAccountService);
        daoAuthenticationProvider.setPostAuthenticationChecks(new UserAccountChecker(messageSourceAccessor));
        auth.authenticationProvider(daoAuthenticationProvider);
        auth.userDetailsService(myUserAccountService).passwordEncoder(passwordEncoder);
    }

[...]

}

此处
UserAccountChecker实现UserDetailsChecker
是一个进行(后期)身份验证测试的类(另请参见
AbstractUserDetailsAuthenticationProvider
中的类
DefaultPostAuthenticationChecks
)。

扩展
daothenticationprovider
后的下一步是什么?您覆盖哪些方法?我对认证后检查特别感兴趣。