• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

LDAP and NamingEnumeration

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This following my code search & get the last name and first name & email address of the user from Active Directory. Now I found onething that if any of user last name is empty in Active Directory, this code fails and misorder the last name with first name i.e If I have two users : John(which doesn't have last name) and Ed Lin then I see John Lin. Why???
try
{
verifyAuthentication(cookies);
// throw up if not already authenticated
String server = (String) cookies.ge(Constants.SERVER);
String user = (String)cookies.get(Constants.USER);
String password = (String)cookies.get(Constants.PASSWORD);
password = decrypt(password);
String provider = "ldap://" + server + ":389";
Hashtable env = new Hashtable();
/* Specify host and port to use for directory service */
env.put(Context.PROVIDER_URL, provider);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
/* specify authentication information */
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, password);
DirContext ctx = new InitialDirContext(env);
if (ctx != null)
{
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration results = ctx.search(book, "(cn=*)", constraints);
while (results.hasMoreElements())
{
SearchResult si = (SearchResult)results.next();
Attributes attrs = si.getAttributes();
if (attrs != null)
{
// we have some attributes for this object
NamingEnumeration ae = attrs.getAll();
System.out.println("The ae is ---> " + ae);
while (ae.hasMoreElements())
{
Attribute attr = (Attribute)ae.next();
String attrId = attr.getID();
if(attrId.equals(ma))
{
// this object has the right attribute
// get all the values of this attribute
Enumeration vals = attr.getAll();
while (vals.hasMoreElements())
{
String emailaddr = (String)vals.nextElement();
temp.addElement(emailaddr);
}
}
}
}
Thanks,
Angela
}
}
}
catch(Exception e){}
//return temp;
}
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic