在我的 Spring Boot 项目中,我想提供 2 个身份验证提供程序。
1. 从数据库
验证用户 2. 从 LDAP 验证用户。
如何在 Spring Boot 中配置多个身份验证提供程序。
在我的 Spring Boot 项目中,我想提供 2 个身份验证提供程序。
1. 从数据库
验证用户 2. 从 LDAP 验证用户。
如何在 Spring Boot 中配置多个身份验证提供程序。
@Component
公共 CustomAuthenticationProvider 实现 AuthenticationProvider {
@Override
Authentication authenticate(Authentication authentication)
throws AuthenticationException {
//TODO write your authentication logic
}
}
公共类 CustomSessionBasedWebSecurityConfig 扩展 WebSecurityConfigurerAdapter {
@Autowired
private CustomAuthenticationProvider customAuthenticationProvider;
@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder.authenticationProvider(customAuthenticationProvider);
//在这里我们可以添加尽可能多的提供者。} }