I have a weird problem with LdapContext.modifyAttributes(name,mods) method. It gives me a NameNotFoundException, even though that object exists on the same path. (I already checked with a small piece of code which returns *distinguishedName*s) Here is my sample code;
ModificationItem[] mods = new ModificationItem[1];
for(Group g: this.groups)
{
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("member", g.getMembers()));
this.context.modifyAttributes("cn="+g.getGroupName()+", ou=OU_MyGroups", mods);
}
This is my connection strings if it helps:
this.setConnectionUrl("ldap://10.77.162.187:389/dc=C4test");
Also, I tried to get attributes from same object, using same name string.
Attributes attr = this.context.getAttributes("cn="+g.getGroupName()+", ou=OU_MyGroups");
And it worked just fine. So I'm out of ideas right now.
And this is my stack trace:
Exception in thread "main" javax.naming.NameNotFoundException: [LDAP: error code 32 - 00000525: NameErr: DSID-031A0F80, problem 2001 (NO_OBJECT), data 0, best match of: ''
; remaining name 'cn=INSAN KAYNAKLARI DIREKTORLUGU, ou=OU_MyGroups'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_modifyAttributes(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_modifyAttributes(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.modifyAttributes(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.modifyAttributes(Unknown Source)
at javax.naming.directory.InitialDirContext.modifyAttributes(Unknown Source)
at com.carrefour.activeDirectory.GroupUpdater.updateGroups(GroupUpdater.java:140)
at com.carrefour.activeDirectory.GroupUpdater.<init>(GroupUpdater.java:129)
at com.carrefour.activeDirectory.ActiveDirectoryUpdater.main(ActiveDirectoryUpdater.java:101)
What's the DN of this.context()? If it is 'ou=OU_MyGroups', you don't need to specify that again in modifyAttributes(). In general you only need to specify the RDN of the item to modify relative to the context you are calling modifyAttributes() on.