aspose file tools*
The moose likes Security and the fly likes Modifying an attribute  in LDAP using JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Modifying an attribute  in LDAP using JNDI" Watch "Modifying an attribute  in LDAP using JNDI" New topic
Author

Modifying an attribute in LDAP using JNDI

suse singularity
Greenhorn

Joined: Apr 29, 2009
Posts: 7
please see my code to modify an attribute. It doesn't seem to have any errors but it does not produce the result as indicated in the error message.
My directory has 50 users.

[code] import java.util.Hashtable;
import java.util.Date;
import javax.naming.*;
import javax.naming.directory.*;
class Modattrs {
public static void main(String[] args) {
Hashtable env = new Hashtable(5, 0.75f);

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
/* Specify host and port to use for directory service */
env.put(Context.PROVIDER_URL, "ldap://localhost:389/cn=Doug Smith,dc=test,dc=com");
/* specify authentication information */
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=test,dc=com");
env.put(Context.SECURITY_CREDENTIALS, "openldap");
try {
/* get a handle to an Initial DirContext */
DirContext ctx = new InitialDirContext(env);
/* construct the list of modifications to make */
ModificationItem[] mods = new ModificationItem[2];
Attribute mod0 = new BasicAttribute("mail", "doug2.02@test.com");
// Update mail attribute
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
// Add another value to description attribute
Attribute mod1 =
new BasicAttribute("description",
"This entry was modified with the Modattrs program on " +
(new Date()).toString());
mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod1);
/* Delete the description attribute altogether */
/*
Attribute mod1 = new BasicAttribute("description");
mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, mod1);
*/
/* make the change */
ctx.modifyAttributes("cn=Doug Smith,dc=test,dc=com", mods);
System.out.println( "modification was successful." );
} catch (NamingException e) {
System.err.println("modification failed. " + e);
}
}
}
[/code]


Errors:
modification failed. javax.naming.OperationNotSupportedException: [LDAP: error code 53 - no global superior knowledge]; remaining name 'cn=Doug Smith,dc=test,dc=com'

PLease let me know where I am wrong and what I need to do to remove the error.
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
is your code compiling? how can you declare the same name "mod1" for variable declaration?

another one: you declared ModificationItem[] mods = new ModificationItem[2];
an array with the size 2 only and you instantiate with mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, mod1);
it definitely give an arrayindex exception while executing your code.


once you clear them, try to do the following


try to remove the space btw Doug and Smith

cn=DougSmith


Thanks,
Kumar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Modifying an attribute in LDAP using JNDI