PDA

View Full Version : Entry not found exception



rjeshg
Mar 22nd, 2007, 06:17 AM
Hii all, I am getting Entry not found; [LDAP: error code 32 ] exception while binding data

the following is my Dao implementation:


public static final String BASE_DN = "ou=system";

public void create(User user) {
Name dn = buildDn(user);
ldapTemplate.bind(dn, null, buildAttributes(user));
}

private Attributes buildAttributes(User user) {
Attributes attrs = new BasicAttributes();
BasicAttribute ocattr = new BasicAttribute("objectclass");
ocattr.add("top");
ocattr.add("person");
attrs.put(ocattr);
attrs.put("cn", "person");
attrs.put("telephonenumber", user.getUid());
attrs.put("userPassword", user.getUserPassword());
return attrs;
}

protected Name buildDn(User user) {
DistinguishedName dn = new DistinguishedName(BASE_DN);
dn.add("cn", user.getDisplayName());
dn.add("telephonenumber", user.getUid());
dn.add("userPassword", user.getUserPassword());

return dn;
}

attached image is my directory, please help me regarding this.

rasky
Mar 22nd, 2007, 07:54 AM
My guess is that the problem is caused by the base DN being included when you build your distinguished name. If you have specified a base path in you ContextSource configuration, that base should never be included in any DNs in your program.

rjeshg
Mar 22nd, 2007, 08:30 AM
here is my context definition :

<bean id="contextSource"
class="org.springframework.ldap.support.LdapContextSource">
<property name="url" value="ldap://localhost:10389" />
<property name="userName" value="uid=admin,ou=system" />
<property name="password" value="secret" />
</bean>

the following exception i am getting while binding data:

org.springframework.ldap.EntryNotFoundException: Entry not found; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - failed to add entry userpassword=test,sn=123,cn=test,ou=system: Parent sn=123, cn=test, ou=system not found]; remaining name 'userpassword=test, sn=123, cn=test, ou=system'
org.springframework.ldap.DefaultNamingExceptionTra nslator.translate(DefaultNamingExceptionTranslator .java:51)
org.springframework.ldap.LdapTemplate.executeWithC ontext(LdapTemplate.java:643)

rasky
Mar 22nd, 2007, 12:24 PM
Ah, sorry, I wasn't looking close enough...

I think you've misunderstood the DN concept. The DN is for identifying the entry - the prmary key if you will. You then specify Attributes to bind to the DN. In your example you are adding Attributes to your DN.

For more information on basic LDAP concepts, this introduction (http://www.ldapman.org/articles/intro_to_ldap.html) looks pretty good.