我正在尝试在我的Spring MVC应用程序上为LDAP身份验证设置Spring Security。我似乎无法使用LdapAuthenticationProvider进行简单的/主体身份验证,所以我尝试使用ActiveDirectoryLdapAuthentication Provider,默认情况下它会这样做。
在创建上下文之后(我认为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进行身份验证,然后执行该搜索以查找我的用户对象。
我的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)。