Spring security LDAP:错误代码34-给定的DN不正确
我是active directory和spring security的新手,事实上,我想更改我的spring安全配置,以便在Authentification中使用active directory,所以我在我的SecurityConfig中使用它:Spring security LDAP:错误代码34-给定的DN不正确,spring-security,active-directory,ldap,Spring Security,Active Directory,Ldap,我是active directory和spring security的新手,事实上,我想更改我的spring安全配置,以便在Authentification中使用active directory,所以我在我的SecurityConfig中使用它: @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(a
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
auth.eraseCredentials(false);
}
@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider authenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(
"dc=example,dc=com", "ldap://localhost:10389/dc=example,dc=com");
authenticationProvider.setConvertSubErrorCodesToExceptions(true);
authenticationProvider.setUseAuthenticationRequestCredentials(true);
authenticationProvider.setUserDetailsContextMapper(mapper);
return authenticationProvider;
}
active directory studio我有一个分区:dc=example,dc=com
,其中包含一个条目ou=people
当我尝试输入用户名和密码时,出现以下错误:
javax.naming.InvalidNameException:[LDAP:错误代码34-给定的DN不正确:admin@dc=例如,dc=com(0x73 0x79 0x73 0x61 0x64 0x6D 0x69 0x6E 0x40 0x64 0x63 0x3D 0x70 0x75 0x70 0x75 0x74 0x2C 0x64 0x63 0x3D 0x63 0x6F 0x6D)无效]
位于com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3076)
位于com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2883)
在com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2797)上
您知道吗?
ActiveDirectoryLdapAuthenticationProvider
旨在让您使用特定于广告的表单中的用户名进行身份验证user@example.com
,这不是标准的LDAP DN格式。因此,构造函数中的第一个参数应该是域(example.com
),而不是LDAP DN。当您以admin
身份登录时,代码使用配置的域来构建字符串admin@example.com
并将其传递给AD
由于您使用的是
dc=example,dc=com
作为域名,因此最终会得到admin@dc=示例,dc=com
,无效 谢谢你的回答,但我以前试过,我也有同样的错误[LDAP:错误代码34-给定的DN不正确:user@example.comTheuser@domain
name格式仅适用于AD配置为进行身份验证的域。它在引擎盖下使用LDAP几乎无关紧要。如果您创建了其他分区,我怀疑它是否有效,您将不得不使用普通LDAP方法。谢谢您是Shaun先生,但您使用普通LDAP方法是什么意思?我的意思是您必须将AD视为标准LDAP服务器。但是,如果您不熟悉LDAP、AD和Spring安全,那么这可能会是一场斗争,您需要做些研究。我建议您从一个简单的main
f编写的普通Java LDAP客户端开始函数(无Spring),然后查看是否可以首先将其作为用户成功绑定。如果您在Mac上,请确保build.xml文件中没有任何“
”