将用户添加到 LDAP 时,LDAP 错误代码 32

ada*_*gde 1 java ldap spring-ldap

我需要向我的 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);
Run Code Online (Sandbox Code Playgroud)

尽管执行这段代码时我得到以下异常:

 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'
Run Code Online (Sandbox Code Playgroud)

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

mar*_*son 7

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

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