Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get ldap list of users belongs to a group using java

 
suhasini dharmisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

If any body knows how to read list of users belongs to a group in LDAP using java. please let me know.
Currently i am getting one user belongs to a group using below code.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, principalName);
env.put(Context.SECURITY_CREDENTIALS, password);

DirContext ctx = new InitialDirContext(env);

String returnedAtts[] ={ "member" };
String searchFilter = "(&(objectClass=group)(cn=Group1))";


SearchControls searchCtls = new SearchControls();
searchCtls.setReturningAttributes(returnedAtts);

searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);


NamingEnumeration answer = ctx.search(toDC(domainName), searchFilter, searchCtls);

while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult) answer.next();
Attributes attrs = sr.getAttributes();

if (attrs != null) {
NamingEnumeration ne = attrs.getAll();

while (ne.hasMore()) {
Attribute attr = (Attribute) ne.next();
String tempSplitArr[] = attr.get().toString().split(",");
System.out.println(attr.get());
// We just need group, now we get CN=CSR UG1 for example.
String grpTemp = tempSplitArr[0];

String tempArr[] = grpTemp.split("=");
groups.add(tempArr[1]);

}
}
}
ctx.close();
Thanks in advance
 
suhasini dharmisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please let me know if anybody knows. I need urgent. Please help me.
 
Arshad Noor
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the "authenticateUser" method of this source-code (StrongKey CryptoEngine - a library for encrypting files and moving them into clouds); you should be able to find hints to what you need there: http://skce.svn.sourceforge.net/viewvc/skce/skcews/src/java/com/strongauth/skcengine/SKCEImpl.java?revision=6&view=markup

Arshad Noor
StrongAuth, Inc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic