Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Try this code ,
Make sure u have ldap provider in yur classpath.
You have to download it from sun site.
Initial context would depend upon yur Ldap server.
You will have to provide these values while building an initial context like Server adds, Base DN, authentication (if the server does).
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
class Modattrs {
public static void main(String[] args) {
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CO
env.put(Context.PROVIDER_U
try {
// Create the initial context
DirContext ctx = new InitialDirContext(env);
String name = "cn=Ted Geisel, ou=People";
// Save original attributes
Attributes orig = ctx.getAttributes(name);
// Specify the changes to make
ModificationItem[] mods =new ModificationItem[3];
mods[0] = new ModificationItem(DirContex
mods[1] = new ModificationItem(DirContex
new BasicAttribute("cn", "chauhanvinit"));
mods[2] = new ModificationItem(DirContex
ctx.modifyAttributes(name,
// Check attributes
System.out.println("**** new attributes *****");
GetattrsAll.printAttrs(ctx
// Revert changes
ctx.modifyAttributes(name,
// Check that the attributes got restored
System.out.println("**** reverted to original attributes *****");
GetattrsAll.printAttrs(ctx
// Close the context when we're done
ctx.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
yu will get detailed explaination at :-
http://java.sun.com/products/jndi/tutorial/basics/directory/modattrs.html
Bye for now.