【问题标题】:LDAP: error code 34 - Incorrect DN givenLDAP:错误代码 34 - 给定的 DN 不正确
【发布时间】:2017-02-24 00:09:08
【问题描述】:

我是 Active Directory 和 Spring Security 的新手,事实上,我想更改我的 Spring Security 配置以便在身份验证中使用 Active Directory,所以我在我的 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 0xC 0x76 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)..

请问你有什么想法吗?

【问题讨论】:

  • 如果您使用的是 Mac,请确保您的 build.xml 文件中没有任何 "

标签: spring-security active-directory ldap


【解决方案1】:

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 是无效的。

【讨论】:

  • 感谢您的回答,但我之前尝试过,但我遇到了同样的错误 [LDAP:错误代码 34 - 给出的 DN 不正确:user@example.com
  • user@domain 名称格式仅适用于配置 AD 进行身份验证的域。它在后台使用 LDAP 几乎是无关紧要的。如果您创建了其他分区,我怀疑它是否会起作用,您将不得不使用普通的 LDAP 方法。
  • 谢谢您,Shaun 先生,但您所说的使用普通 LDAP 方法是什么意思?
  • 我的意思是您必须将 AD 视为标准 LDAP 服务器。但是,如果您是 LDAP、AD 和 Spring Security 的新手,那么这可能会很困难,您需要做一些研究。我建议你从一个普通的 Java LDAP 客户端开始,用一个简单的 main 函数(没有 Spring)编写,看看你是否可以先成功地绑定为你的用户。
猜你喜欢
  • 2013-09-20
  • 1970-01-01
  • 2023-03-20
  • 2014-11-24
  • 1970-01-01
  • 2017-05-24
  • 2021-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多