簡體   English   中英

如何在Spring-Security LDAP中使用ActiveDirectory

[英]How to use ActiveDirectory with Spring-Security LDAP

我正在嘗試在Spring MVC應用程序上為LDAP身份驗證設置Spring Security。 我似乎無法使用簡單/主要身份驗證來與LdapAuthenticationProvider一起使用,因此我嘗試使用ActiveDirectoryLdapAuthenticationProvider,默認情況下會執行此操作。

在創建上下文之后(我認為已發生LDAP綁定),從這一行(ActiveDirectoryLdapAuthenticationProvider.java中的310),我收到了帶有detailMessage的NameNotFoundException:

return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context,
                searchControls, searchRoot, searchFilter,
                new Object[] { bindPrincipal });

錯誤信息:

[LDAP: error code 32 - 0000208D: NameErr: DSID-03100213, problem 2001 (NO_OBJECT), data 0, best match of:
'DC=my,DC=company,DC=com']

搜索過濾器正在查找類為“ user”且其userPrincipalName等於我通過身份驗證並與我的域的域名串聯在一起的用戶名的對象。 例如,“ me@my.company.com”。 存在具有該值的屬性,因為我可以在此方法中使用JXplorer進行身份驗證,然后執行該搜索以查找我的用戶對象。

我在AuthenticationManagerBuilder中連接的WebSecurityConfigurerAdapter子類的配置基本上是這樣的:

@Autowired
public void init(AuthenticationManagerBuilder auth) throws Exception {
   ActiveDirectoryLdapAuthenticationProvider provider =
            new ActiveDirectoryLdapAuthenticationProvider("my.company.com", "LDAPS://ad.my.company.com:636/dc=my,dc=company,dc=com");
   provider.setConvertSubErrorCodesToExceptions(true);
   auth.authenticationProvider(provider);
}

是什么導致NameNotFoundException? 這是配置ActiveDirectory身份驗證的正確方法嗎?

臉掌。 至少在我的目錄中,LDAP服務器的URL不應包括X.501域組件部分。 我想這很有意義,因為第一個構造函數參數是域的名稱(采用FQDN樣式)。 因此,構造函數參數應為...

new ActiveDirectoryLdapAuthenticationProvider("my.company.com", "ldaps://ad.my.company.com:636");

綁定完成,但錯誤消息提示了這一點,但是搜索失敗。 確切的錯誤有“ NO_OBJECT”作為原因,這是搜索庫已關閉的線索。 我最初配置的搜索實際上添加了兩次搜索庫(DC)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM