我的問題是,我想有兩個身份驗證提供春天啓動的安全性 - 多個身份驗證提供
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