【发布时间】:2014-08-16 14:57:43
【问题描述】:
我仍在学习 LDAP / Active Directory,如果我的术语完全错误,请纠正我 :)
在我们的 Java Web 应用程序中,我尝试使用 Spring Security LDAP 来保护它。我设法让 Spring Security 使用内存身份验证,但我们需要将它绑定到我们的 AD 服务器。
我将使用 com.test
来掩盖我们的实际域这是我尝试从我的应用程序登录时收到的错误
13:39:55,701 错误 ActiveDirectoryLdapAuthenticationProvider:133 - 无法找到经过身份验证的用户的目录条目:johnsmit javax.naming.NameNotFoundException:[LDAP:错误代码 32 - 0000208D: NameErr: DSID-0310020A, 问题 2001 (NO_OBJECT), 数据 0, 最佳匹配 of: 'CN=Users,DC=ad,DC=test,DC=com'
我在 Spring 中使用基于类的配置 这是我的 SecurityConfiguration 类
@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
provider = new ActiveDirectoryLdapAuthenticationProvider("ad.test.com", "ldap://servername.ad.test.com:389/cn=Users,dc=ad,dc=test,dc=com");
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin().failureUrl("/login?error")
.loginPage("/login")
.permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login")
.permitAll()
.and()
.httpBasic();
}
}
所以这就是问题所在(至少我认为)... 在我们的 AD 服务器中,我们有我们的 cn、name、sAMAccountName 和 uid 作为我们登录时使用的用户名,johnsmit 在我上面的例子中。
我们的 userPrincipalName(在我们的 AD 服务器中)是我们的电子邮件地址,所以 john.smith@test.com。
我正在查看 ActiveDirectoryLdapAuthenticationProvider 类,它说它使用 userPrincipalName。查看代码here on github 它表明它正在使用userPrincipalName。我检查了尚未通用的 Spring Security 的较新版本,但它是同一件事。
必须以某种方式让我可以使用用户名“johnsmit”而不是“john.smith@test.com”来搜索 AD...
如果 searchFilter 是
String searchFilter = "(&(objectClass=user)(sAMAccountName={0}))"; 那将是理想的情况,但我不知道这是否可以在任何地方覆盖并且我找不到任何文档?
【问题讨论】:
标签: java spring spring-mvc spring-security active-directory