List Members of Active Directory Group
Is there an equivalent of (uniquemember = userDN) search I can use with Active Directory or alternatively where can I list the members of an active directory group. I have listed all the attributes of an Exchange distribution list within the active directory but there is no member information. Is what I am attempting possible?
I have worked it out and in case anyone else is looking at this post this was the problem. Exchange Distribution lists don't have the member attribute unless they are also a security group. This is why I couldn't find any member information. The code that is equivalent to using a uniquemember=userDN type search in Active Directory is:
// Set up the environment for creating the initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://mattlyons:389/");
// Authentication
env.put(Context.SECURITY_PRINCIPAL, "cn=administrator,cn=users,dc=matt,dc=local");
env.put(Context.SECURITY_CREDENTIALS, "mypword");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
// List groups that contain the DN as member
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
matchAttrs.put(new BasicAttribute("member", "cn=Mickey Mouse,cn=users,dc=matt,dc=local"));
// Search for objects that have those matching attributes
NamingEnumeration answer = ctx.search("cn=users,dc=matt,dc=local", matchAttrs);
while (answer.hasMore()) {
SearchResult sr = (SearchResult)answer.next();
System.out.println(sr.getName());
}