LDAP:错误代码34 - 给出的DN不正确

时间:2016-10-14 14:06:32

标签: spring-security active-directory ldap

我是新的活动目录和spring安全性,事实上,我想更改我的spring安全配置,以便在authentififation中使用active目录,所以我在SecurityConfig中使用它:

@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;
}

和活动目录工作室我有一个分区:dc=example,dc=com,其中包含一个条目ou=people

当我尝试输入用户名和密码时出现此错误:

  

javax.naming.InvalidNameException:[LDAP:错误代码34 - 给出不正确的DN:admin @ dc = 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)无效]       at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3076)       at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2883)       在com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2797)..

请问您有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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

由于您使用dc=example,dc=com作为域名,因此最终会导致admin@dc=example,dc=com无效。