Spring 如何将自定义ProviderManager注入AuthenticationManagerBuilder
在我的Spring Boot应用程序中,我推出了我的定制Spring 如何将自定义ProviderManager注入AuthenticationManagerBuilder,spring,spring-security,Spring,Spring Security,在我的Spring Boot应用程序中,我推出了我的定制MyProviderManager,我想在其中控制方法身份验证 但是,我现在很难将自定义的MyProviderManager注入AuthenticationManagerBuilder,这样AuthenticationManagerBuilder中的performBuild()方法将返回MyProviderManager,而不是Spring Security中的默认方法 我甚至试着拿出我的自定义MyAuthenticationManager
MyProviderManager
,我想在其中控制方法身份验证
但是,我现在很难将自定义的MyProviderManager
注入AuthenticationManagerBuilder,这样AuthenticationManagerBuilder中的performBuild
()方法将返回MyProviderManager
,而不是Spring Security中的默认方法
我甚至试着拿出我的自定义MyAuthenticationManagerBuilder
exendsAuthenticationManagerBuilder
并重写performBuild
()方法,但我面临着如何将自定义AuthenticationManagerBuilder注入Spring Boot的同样问题
如果有人能在这里阐明这些问题,或者有更好的替代方案来解决我的特殊需求,我将不胜感激如果您有一个自定义的AuthenticationManager实现,您将不再使用AuthenticationManager Builder(这是构建AuthenticationManager的方法,但您已经有了AuthenticationManager)。而是将AuthenticationManager作为bean公开,并且不使用AuthenticationManagerBuilder
@Bean
CustomAuthenticationManager customAuthenticationManager() {
return new CustomAuthenticationManager();
}
这回答了你的问题吗?ProviderManager迭代所有AuthenticationProvider(包括自定义AuthenticationProvider)。我希望有一个自定义ProviderManager,在这里我可以更好地控制哪个AuthenticationProvider将用于哪个URL路径它是否指示我不应覆盖
受保护的无效配置(AuthenticationManagerBuilder auth)
和受保护的无效配置(AuthenticationManagerBuilder auth)
在扩展了websecurityconfig适配器的MySecurityConfig中
?相反,CustomAuthenticationManager
应该自己实例化所有必要的AuthenticationProvider
列表,对吗?
@Bean
CustomAuthenticationManager customAuthenticationManager() {
return new CustomAuthenticationManager();
}