2016-10-14 139 views
1

我是新的活动目录和弹簧安全性,实际上,我想更改我的弹簧安全配置,以便在验证中使用活动目录,因此我在我的SecurityConfig中使用此目录:LDAP:错误代码34 - 错误的DN给出

@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: error code 34 - Incorrect DN given : [email protected]=example,dc=com (0x73 0x79 0x73 0x61 0x64 0x6D 0x69 0x6E 0x40 0x64 0x63 0x3D 0x70 0x75 0x70 0x70 0x75 0x74 0x2C 0x64 0x63 0x3D 0x63 0x6F 0x6D) is invalid] at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3076) at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2883) at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2797)..

你有什么想法吗?

+0

如果你在Mac上,请确保你的build.xml文件中没有任何'"' – Archmede

回答

0

ActiveDirectoryLdapAuthenticationProvider旨在让您使用特定于AD的表格[email protected]中的用户名进行身份验证,该格式不是标准的LDAP DN格式。因此,构造函数中的第一个参数应该是域(example.com)而不是LDAP DN。当您登录为admin时,代码使用配置的域来构建字符串[email protected]并将其传递给AD。

由于您使用的是dc=example,dc=com作为域名,因此以[email protected]=example,dc=com结尾,这是无效的。

+0

谢谢你的回答,但是我之前试过并且我有同样的错误[LDAP:error code 34 - 给出的DN不正确:[email protected] – FoufaFaFa

+0

我仍然有相同的错误:/ – FoufaFaFa

+0

'user @ domain'名称格式只适用于AD配置为进行身份验证的域。它在底层使用LDAP几乎是毫不相干的。如果你已经创建了一些其他分区,我怀疑它是否可行,你将不得不使用普通的LDAP方法。 –