• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Modifying an attribute in LDAP using JNDI

Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

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.
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic