2016-09-14 463 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中刪除基本路徑爲我工作。 –