• Post Reply Bookmark Topic Watch Topic
  • New Topic

question on LDAP  RSS feed

 
Xinyi Zhang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which class/method in JNDI can add entries into LDAP? Thanks.
[ April 15, 2002: Message edited by: Xinyi Zhang ]
 
kiran nori
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!