1

I need to add a new user entry to my ldap. Following is my code:

     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);

Although when this piece of code is executed I get the following exception:

 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'

I am following the example specified at http://kaustuvmaji.blogspot.in/2014/12/simple-example-of-spring-ldap.html for the code. Can someone help me in understanding the root cause for this error or the right code.

1 Answer 1

7

The problem here is that the path ou=Users,dc=wso2,dc=org doesn't exist in your LDAP tree, so you cannot create a child at that path.

If you specified a base path for your ContextSource that should be omitted from all DNs in code, as all paths will be relative to the specified base.

Sign up to request clarification or add additional context in comments.

3 Comments

I picked up the path from the LDAP tree itself using Apache Directory Studio. For eg: another existing entry has DN = "cn=newName,ou=Users,dc=wso2,dc=org". Could the case(uppercase/lowercase) of the terms in the path be a problem? Is there a way to verify the path?
Updated answer with tip on base path
Thanks @marthursson !! Removing the base path from the DN worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.