How list out my domain users using LDAP
Hi all,
I am new LDAP server applications.
I want to list out all my local domain user list by using java & ldap. When i tried a sample application from this forum i found its working find but i am not getting any records to display.
public void importDomainUsers() throws UnknownHostException
{
InetAddress inet2 = InetAddress.getLocalHost();
String mydomain = inet2.getCanonicalHostName();
mydomain = serverName.substring(serverName.indexOf("."), serverName.lastIndexOf("."));
System.out.println("Host Name1 :"+inet2.getCanonicalHostName());
System.out.println("My Domain :"+mydomain);
Hashtable env = new Hashtable();
//Must use either the userPrincipalName or samAccountName,
//Cannot use the distinguished name
//String adminName = "Administrator@antipodes.com";
String adminName = userName;
String adminPassword = password;
String ldapURL = "ldap://"+serverName+":389";
System.out.println("ldap Url :"+ldapURL);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
//set security credentials, note using DIGEST-MD5
//Requires user account to be stored with reversible encryption
env.put(Context.SECURITY_AUTHENTICATION,"DIGEST-MD5");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
//Could also use DIGEST-MD5 to protect the communications
//Eg. auth-int;integrity, auth-conf;confidentiality
//env.put("javax.security.sasl.qop","auth-conf");
//And could also request the level of crypto
//Eg. low, medium, high
//env.put("javax.security.sasl.strength","high");
//connect to my domain controller
env.put(Context.PROVIDER_URL,ldapURL);
try {
// Create the initial directory context
DirContext ctx = new InitialLdapContext(env,null);
// Create the search controls
SearchControls searchCtls = new SearchControls();
//Specify the attributes to return
String returnedAtts[]={"sn","givenName","mail"};
searchCtls.setReturningAttributes(returnedAtts);
//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//specify the LDAP search filter
String searchFilter = "(&(objectClass=user)(mail=*))";
//Specify the Base for the search
String searchBase = "DC="+mydomain+",DC=com";
//initialize counter to total the results
int totalResults = 0;
// Search for objects using the filter
NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
//Loop through the search results
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
totalResults++;
System.out.println(">>>" + sr.getName());
// Print out some of the attributes, catch the exception if the attributes have no values
Attributes attrs = sr.getAttributes();
if (attrs != null) {
try {
System.out.println("mail: " + attrs.get("mail").get());
}
catch (NullPointerException e){
System.out.println();
}
}
}
System.out.println("Total results: " + totalResults);
ctx.close();
}
catch (NamingException e) {
System.err.println("Problem searching directory: " + e);
}
}
i used the above sample program, i passed our domain server as "server.eaglesoft.com and user name is "administrator" and password "*****" was given by the system admin.
when i run this program i m getting ,,
Total Results : 0
plz help me to solve the issue. my requirment is list out all the users userid and user type only..
regards,
dhaya.

