我有两个 AuthenticationProviders ,并且不知道如何将其转换为 Spring Security 的新方式。 这就是我所说的“新方式”https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter
目前我正在扩展 WebSecurityConfigurerAdapter
并具有以下配置:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(inMemoryAuthenticationProvider);
auth.authenticationProvider(ldapAuthenticationProvider);
auth.userDetailsService(userDetailsService);
}
在不扩展 WebSecurityConfigurerAdapter
的情况下,配置必须是什么样子?
最佳答案
我通过使用@Elyobek建议的filterChain解决了这个问题,但使用了以下代码:
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authenticationProvider(inMemoryAuthenticationProvider);
http.authenticationProvider(ldapAuthenticationProvider);
http.userDetailsService(userDetailsService);
}
我没有意识到我可以在 HttpSecurity
上设置 AuthenticationProviders
和 UserDetailsService
。
关于spring-boot - 没有 WebSecurityConfigurerAdapter 和两个 AuthenticationProvider 的 Spring Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74094096/