This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

LDAP and NamingEnumeration

Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
I have connected to LDAP and have abit of trouble getting certain data out.
for example: In the LDAP browsing tool..a groupA has certain attributes and their values for example:
cn groupA
sAMAccountName aaa
member CN=Cilliers\, Maggie, OU=Users ...
member CN=James\, Kai, OU=Users ...
member CN=Henin\, Sven, OU=Users ...
How do I get all the members in groupA? Please give me example code to do this.
A bit of my code:
DirContext ctx = new InitialDirContext(env);
// Ask for all attributes of the object
Attributes attrs = ctx.getAttributes("CN=groupA,OU=GroupsA,OU=Groups,OU=Core,DC=xx,DC=com");
//getting the attributes value
System.out.println("member: " + attrs.get("member").get());
I have tried to use NaminEnumeration..but was not very successful.
NamingEnumeration xx = attrs.get("member").getAll();
System.out.println(xx.??); //It has no method to get a value
Need urgent help
thanx in advance
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It actually looks as though you are querying MS ActiveDirectory, so I don't know if this will help, but you may be able to adapt some of it. Where I am using the attributes "cn" and "mail" you would substitute "member". And of course, you would replace some/all of the code where I am building the StringBuffer "sb".
Not sure what your base should be... perhaps "OU=Core,DC=xx,DC=com".
Hope this helps!
tejal bilan
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Philip
Thank you for your response.
I have tried your suggested code, but got myself abit stuck with this line:
String base = "DC=sasol,DC=com";
String filter = "CN=SAPPortal-Sec-Prod-Admin,OU=SAPPortal

NamingEnumeration results =, filter, ctls);
I can not continue with the while loop because results is null.
The search method takes a (name, string, searchControl)
I know that the base value is right, and my string value points to the group that has the attributes "member" which I want.
Please can you help further.
I have played around with it for some time and was very unsuccessful. The error I get :

javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name 'DC=sasol,DC=com'
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source)
at source)
at Source)
at Source)
at com.sasol.iview.LDAPLookup.main(

source code:
public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://");
env.put(Context.SECURITY_CREDENTIALS, "password");
String base = "DC=sasol,DC=com";
String filter = "CN=SAPPortal-Sec-Prod-Admin,OU=SAPPortal Groups,OU=Groups,OU=Core,DC=sasol,DC=com";
try {
DirContext dctx = new InitialDirContext(env);
//String[] attrIDs = {"member"};
String[] attrIDs = {"member"};
SearchControls ctls = new SearchControls();
NamingEnumeration results =, filter, ctls);
//Attributes attrs1 = dctx.getAttributes("CN=SAPPortal-Sec-Prod-Admin,OU=SAPPortal Groups,OU=Groups,OU=Core,DC=sasol,DC=com");
//System.out.println("val:" + attrs1.get("cn").get());
StringBuffer sb = new StringBuffer();
while (results.hasMore()) {
SearchResult res = (SearchResult);
Attributes attrs = res.getAttributes();
if (results.hasMore())
sb.append(attrs.get("member").toString().substring(4) + ",");

} catch (NamingException e) {
} //end main
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic