| Author |
how to get ldap list of users belongs to a group using java
|
suhasini dharmisetty
Greenhorn
Joined: Oct 07, 2008
Posts: 19
|
|
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
Joined: Oct 07, 2008
Posts: 19
|
|
|
Please let me know if anybody knows. I need urgent. Please help me.
|
 |
Arshad Noor
Ranch Hand
Joined: Oct 06, 2011
Posts: 34
|
|
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.
|
 |
 |
|
|
subject: how to get ldap list of users belongs to a group using java
|
|
|