Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Modifying an attribute in LDAP using JNDI

Posts: 7
  • Mark post as helpful
  • send pies
  • 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.*;
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", "");
// 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
  • 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

Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic