Which class/method in JNDI can add entries into LDAP? Thanks. [ April 15, 2002: Message edited by: Xinyi Zhang ]
Xinyi
kiran nori
Greenhorn
Joined: May 28, 2001
Posts: 12
posted
0
javax.naming.InitialContext package has a method bind(name, object) used to add entried to a directory. here is the code that will do the needful. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import javax.naming.*; import javax.naming.directory.*; public class AddEntries {
final String INITIAL_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory"; Hashtable htbEnvironment = new Hashtable(); //DirContext to connect to Directory. DirContext objDirCtx = null; public AddEntries() { htbEnvironment.put( Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); htbEnvironment.put( Context.PROVIDER_URL, "ldap://10.10.10.10:389"); htbEnvironment.put( Context.SECURITY_PRINCIPAL, "userid" ); htbEnvironment.put( Context.SECURITY_CREDENTIALS,"password"); objDirCtx = new InitialDirContext(htbEnvironment); } public void addToDirectory() { // This is the object to be added to the directory. This class implements DirContext. DirectoryObject objDirObject = new DirectoryObject(); try { objDirCtx.bind( "cn=object1,ou=blah,o=blah1", objDirObject ); System.out.println("Directory Object added successfully"); } catch(Exception objExcep) { System.out.println("Got Exception While Adding"); } } } [ April 17, 2002: Message edited by: kiran nori ]