我正在使用SpringBoot2.0(利用SpringSecurity5.0)。我正在尝试在我的AuthenticationProvider子类中向AuthenticationManager添加一个自定义的WebSecurityConfigurerAdapter。如果我重写configure(AuthenticationManagerBuilder)
方法来提供新的提供程序,那么我就不知道如何以bean的形式检索AuthenticationManager。
例如:
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.authenticationProvider(customAuthenticationProvider);
}
}
其中customAuthenticationProvider
实现了AuthenticationProvider
。
在春季医生中,它似乎指定这两者是不兼容的:
5.8.4 AuthenticationProvider您可以通过将自定义AuthenticationProvider公开为bean来定义自定义身份验证。例如,假设SpringAuthenticationProvider实现了AuthenticationProvider,下面将定制身份验证: 注意,只有在未填充AuthenticationManagerBuilder的情况下才使用此方法。
实际上,如果我尝试使用以下方法检索AuthenticationManager bean:
@Bean
public AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManagerBean();
}
那么configure()
方法甚至从未被调用过。
那么,如何将自己的自定义提供程序添加到默认的提供程序列表中,并且仍然能够检索AuthenticationManager?
发布于 2018-03-21 08:14:10
您只需重写WebSecurityConfigurerAdapter.authenticationManagerBean()
方法并用@Bean
注释对其进行注释。
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
而且没有SpringBoot5.0,最新的版本是SpringBoot2.0。我相信你说的是SpringSecurity5.0。
https://stackoverflow.com/questions/49410977
复制