I am querying Active Directory through LDAP (from Java and PHP) to create a list of all the groups the user is a member of. This list should contain all the least of all groups (optional organizational units) that contain the groups to which the user directly belongs. For example:
User1 is a member of GroupA, GroupB and GroupC.
GroupA is a member of GroupD.
I am looking for a way to create an LDAP query that will immediately return GroupA, GroupB, GroupC and GroupD.
My current implementation is lower, but I am looking for a more efficient way to collect this information.
The current implementation of naivety (in pseudo-code)
user = ldap_search('samaccountname=johndoe', baseDN); allGroups = array(); foreach (user.getAttribute('memberOf') as groupDN) { allGroups.push(groupDN); allGroups = allGroups.merge(getAncestorGroups(groupDN)); } function getAncestorGroups(groupDN) { allGroups = array(); group = ldap_lookup(groupDN); parents = group.getAttribute('memberOf'); foreach (parents as groupDN) { allGroups.push(groupDN); allGroups = allGroups.merge(getAncestorGroups(groupDN)); } return allGroups; }
java php active-directory ldap
Adam franco
source share