I am beginner for LDAP, Please any bosy help me.
2 posts in topic
Flat View  Flat View

Posted By:   Sudarshana_Nedle
Posted On:   Tuesday, July 1, 2003 07:36 AM

I am new to Directory server programming. Now, I
just instaled iPlanet directory server and created some
names with First and last names, along with phone
number and email address. My task would be to access
this dirctory using a java program and then search for
last name and then retieve all the info pertaing to that person.

If anybody helps me with the sample code that will be great.



Re: I am beginner for LDAP, Please any bosy help me.

Posted By:   Anonymous  
Posted On:   Saturday, July 26, 2003 03:53 AM

Hi Sudarshan,
Go through this programme. U will find what u need in this. If finding difficulty mail me.

Raju senthil kumar

/**Native java imports*/
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
import java.util.*;
import java.util.Enumeration;
public class JNDISearch{

//Initial Context...implementation
public static String INITCTX="com.sun.jndi.ldap.LdapCtxFactory";
public static String MYHOST="ldap://localhost:389";
public static String MSBASE="ou=people,dc=everse-blr,dc=everse,dc=com";
//public static String FLT="(cn=senthil kumar)";
public static String FLT="(uid=mbhandaria)";

public static void main(String args[]){
Hashtable env=new Hashtable();


env.put(Context.PROVIDER_URL ,MYHOST);
//Password of Directory manager=adminuser
// env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_PRINCIPAL, "uid=admin, ou=Administrators, ou=TopologyManagement, o=NetscapeRoot");

DirContext ctx=new InitialDirContext(env);

SearchControls con= new SearchControls();


// System.out.println("here it start search");
NamingEnumeration results=ctx.search(MSBASE,FLT,con);
//System.out.println("command is through");

while (results!=null && results.hasMore())
// System.out.println("command is through");
SearchResult sr=(SearchResult)results.next();
String dn=sr.getName();
System.out.println("Distinguished Name:"+dn);
Attributes attrs=sr.getAttributes();
for(NamingEnumeration ne=attrs.getAll();ne.hasMoreElements();){
Attribute attr= (Attribute)ne.next();
String attrID=attr.getID();
System.out.println("Attrib ID:"+attrID);
for(Enumeration vals=attr.getAll();vals.hasMoreElements();){
System.out.println(" "+vals.nextElement());
}}catch(Exception e)


Re: I am beginner for LDAP, Please any bosy help me.

Posted By:   neal_ravindran  
Posted On:   Friday, July 18, 2003 06:31 AM

Sudarshan, this is the best place to find ...


About | Sitemap | Contact