
September 21st, 2011, 01:00 PM
|
|
Contributing User
|
|
Join Date: Feb 2010
Posts: 42
Time spent in forums: 10 h 49 m 5 sec
Reputation Power: 3
|
|
Please look through what i did so far but still having problem. Please help:
Code:
Hashtable Env = new Hashtable();
Env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
String url = "ldap://XX.XX.XX.XX:XXX/";
Env.put(Context.PROVIDER_URL, url);
try {
DirContext dctx = new InitialDirContext(Env);
SearchControls sc = new SearchControls();
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = "(userid="+userName+")";
String base="ou=Users Data,o=userINFO,ou=userDEV,O=user-D";
NamingEnumeration results = dctx.search(base, filter, sc);
// Here i would like to implement if the "userName" is there then say "True" or "False"
// But don't know how :(
System.out.print(results.toString());
// Close the context when we're done
dctx.close();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
|