【问题标题】:Ldap error code 32 while adding user to ldap将用户添加到 ldap 时出现 ldap 错误代码 32
【发布时间】:2017-01-22 11:03:37
【问题描述】:

我需要向我的 ldap 添加一个新用户条目。以下是我的代码:

     javax.naming.Name name = new DistinguishedName("cn=" + userName +",ou=Users,dc=wso2,dc=org");


     Attribute objectClass = new BasicAttribute("objectClass");
        {
         objectClass.add("top");
         objectClass.add("inetOrgPerson");
         objectClass.add("person");
         objectClass.add("organizationalPerson");
        }
        Attributes userAttributes = new BasicAttributes();
        userAttributes.put(objectClass);
        userAttributes.put("cn", userName);
        userAttributes.put("sn", "abctest");
        userAttributes.put(ATTRIBUTE_USER_PASSWORD, password);
        LdapTemplate ldapTemplate = (LdapTemplate) SpringBeanFactory
                .getBean("ldapTemplate");
        ldapTemplate.bind(name, null, userAttributes);

虽然执行这段代码时出现以下异常:

 org.apache.cxf.interceptor.Fault: [LDAP: error code 32 - No Such Object];       
 nested exception is javax.naming.NameNotFoundException: 
 [LDAP: error code 32 -      No Such Object]; remaining name 'cn=myname,ou=Users,dc=wso2,dc=org'

我正在遵循http://kaustuvmaji.blogspot.in/2014/12/simple-example-of-spring-ldap.html 指定的示例代码。有人可以帮助我了解此错误的根本原因或正确的代码。

【问题讨论】:

    标签: java ldap spring-ldap


    【解决方案1】:

    这里的问题是路径 ou=Users,dc=wso2,dc=org 在您的 LDAP 树中不存在,因此您无法在该路径上创建子路径。

    如果您为 ContextSource 指定了基本路径,代码中的所有 DN 都应省略该基本路径,因为所有路径都将相对于指定的基本路径。

    【讨论】:

    • 我使用 Apache Directory Studio 从 LDAP 树本身获取了路径。例如:另一个现有条目的 DN = "cn=newName,ou=Users,dc=wso2,dc=org"。路径中术语的大小写(大写/小写)是否有问题?有没有办法验证路径?
    • 更新了答案,提示基本路径
    • 谢谢@marthursson !!从 DN 中删除基本路径对我有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    • 2016-08-19
    相关资源
    最近更新 更多