2016-09-14 443 views
0

我需要将新用户条目添加到我的ldap。以下是我的代码:将用户添加到ldap时Ldap错误代码32

 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的代码指定的例子。有人可以帮助我理解此错误或正确代码的根本原因。

回答

1

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

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

+0

我使用Apache Directory Studio从LDAP树本身获取路径。例如:另一个现有条目具有DN =“cn = newName,ou = Users,dc = wso2,dc = org”。该路径中的术语(大写/小写)可能会成为问题吗?有没有办法来验证路径? –

+0

在基本路径上提示最新答案 – marthursson

+0

Thanks @marthursson !!从DN中删除基本路径为我工作。 –

相关问题