我的问题是,我想有两个身份验证提供春天启动的安全性 - 多个身份验证提供
BEFORE: 我有我的UserDetailServiceImpl,我验证了用户对DB(不知道供应商是)用户根据数据库中的数据得到了作用
NOW: 我已经使用ActiveDirectoryLdapAuthentication提供如下
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
super.configure(auth);
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailService);
}
@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
}
@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
MyActiveDirectoryLdapAuthenticationProvider provider = new MyActiveDirectoryLdapAuthenticationProvider(domain, url, rootDN);
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
我做了它的工作,所以我能够进行身份验证。
问题:
- 我现在无法再与数据库用户登录,现在只有LDAP。
- UserDetailsService未使用,因此用户拥有哪个角色?
- 有没有办法如何添加一些默认角色到LDAP认证用户?
那么如何启用这两个提供商? 如何向用户添加角色,通过LDAP auth.provider进行身份验证?
我也很欣赏“大图片”描述了这里发生了什么(引擎盖下)。这里使用的每个类的作用是什么,它真的不清楚它是如何工作的(AuthenticationManager,AuthenticationManagerBuilder,AuthenticationProvider等)。也许它只是被自动配置隐藏等等,但是即使直接看Spring Security也不会让我任何智慧。
感谢任何提示
UPDATE 此代码似乎是正确
工作@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailService);
}
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
MyActiveDirectoryLdapAuthenticationProvider provider = new MyActiveDirectoryLdapAuthenticationProvider(domain, url, rootDN);
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
provider.setAuthoritiesMapper(new SimpleAuthorityMapper());
return provider;
}
这是否意味着我无法一次对两个提供者进行身份验证?在数据库中拥有超级用户,如果LDAP关闭等能够登录。AuthoritiesMapper可能会有所帮助,我们也可能在AD中有一些组,我会检查。明天会尝试你的建议。现在感谢。 – Zveratko 2015-02-10 20:40:04
如果没有'@Bean public AuthenticationManager authenticationManager()'它完全停止工作: -/ – Zveratko 2015-02-11 07:24:35
有两个AuthenticationManagerBuilder被创建,我认为应该只有一个。我不明白。 – Zveratko 2015-02-11 08:35:03