【发布时间】:2018-05-01 08:33:52
【问题描述】:
我的公司设置了 Active Directory。我正在制作一个应用程序,其登录系统应链接到该 AD,因此我设置了 Spring LDAP 身份验证来实现它。
但是当我尝试登录应用程序时,我得到了
Failed to locate directory entry for authenticated user: my.name
javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100213, problem 2001 (NO_OBJECT), data 0, best match of:
'DC=dev,DC=company,DC=corp'
我的 Spring Security 代码如下所示:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailsService());
}
@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
}
@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider("company.hr", "ldap://10.23.1.1:389/dc=dev,dc=company,dc=corp");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
}
其中一个问题是,我们的 AD 结构确实是分支出来的,而且每个组织单元都有进一步的细分:
阅读 LDAP,我认为只给它提供公共父文件夹的路径应该通过树进行递归搜索并找到匹配的用户,无论他们在什么 OU 中,事实上,如果我执行 @987654324 @ 从命令提示符返回查询的用户,无论他们在哪里。然而,这不会发生在春天。我已经阅读了有关该主题的所有内容,并调试了几个小时 - 但似乎我的参数设置正确,但我仍然被抛出异常。
我的问题是 - 如何让 Spring 看到用户实际上在 Active Directory 中,而不指定该特定用户的完整 URL(因为有几十个不同的 OU)?
【问题讨论】:
-
在 JXplorer 中执行搜索以获取正确的参数。您没有指明您正在使用的搜索的参数和值。看来您正在寻找 my.name。试试 dsquery user -samid my.name
标签: spring spring-security ldap spring-ldap