• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ldap newbie  RSS feed

Steve Sutton
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to ldap and I am having a hard time finding examples of what I need to accomplish. I am performing a search on a user and getting an attribute under that user. I want to get the value of that attribute and pass that along. Here is the code that I have.
DirContext ctx = null;
String hostURL = "ldap://ldaptest.nwa.com:389";
String passWord = "lwcsvc";

// Create a Hashtable object.
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, hostURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple" );
env.put(Context.SECURITY_PRINCIPAL, "cn=lwcsvc,ou=svcacct,dc=tads,dc=nwa,dc=com" );
env.put(Context.SECURITY_CREDENTIALS, passWord );

// Create the initial directory context

System.out.println(" Binding to the context");

ctx = new InitialDirContext(env);
catch (NamingException e)
System.err.println("Problem with Bind:" + e);

System.out.println("Successful Bind");
String baseDN = "CN=Users,DC=tads,DC=xxx,DC=com";
String searchFilter = "(CN=" + empID +")";
String[] attrID= {"memberOf"};

SearchControls ctls = new SearchControls();

NamingEnumeration answer = ctx.search(baseDN, searchFilter, ctls);
while (answer.hasMore())
SearchResult sr = (SearchResult)answer.next();
System.out.println(sr.toString() + "\n");
catch (Exception e)
System.out.println("Could not find Group for empID: " +empID +e);
The result is:
"CN=c02188: null:null:{memberof
=memberOf: CN=monitorRecords,OU=groups,DC=tads,DC=xxx,DC=com}"
What I would really like to do is just retrieve the value of 'monitorRecords' instead of the entire string. How do I use the getAttribute function to do this after the search.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!