简体   繁体   中英

LDAP: Get list of users in a specific group

I'm trying to get all users of a specific user group. I'm doing this in java, I can connect to ldap and get results from different queries. However I've searched to find solution but as far as I can tell the LDAP of my workplace is structured differently than what seems normal.

dn of users:

ou=Users,O=MYCOMPANY.COM

dn of the user group:

cn=Admin,ou=Profiles,ou=MYAPP,ou=Applirights,O=MYCOMPANY.COM

For the user group, cn is the privilege level / group name (Admin) and the name of the application is in an organisational unit. With this structure, how would I query for all users in this specific group?

I tried:

NamingEnumeration<?> namingEnum = ctx.search("ou=Users,O=MYCOMPANY.COM", "(cn=Admin,ou=Profiles,ou=MYAPP,ou=Applirights,O=MYCOMPANY.COM)", searchControls);

However what attributes would need to be in search controls? I use uid which is the users login name.

I also tried whats outlined here :

(&(objectCategory=user)(memberOf=cn=Admin,ou=MYAPP,ou=Applirights,O=MYCOMPANY.COM))

Nothing works and with that, I mean I get 0 results but no error. How can I achieve this with the given organisation of ldap?

Groups have something called memberOf : So try this:

search -s sub -b "DC=whatever,DC=mydomain,DC=com" "(&(objectCategory=user)(memberOf=CN=GROUP,DC=whatever,DC=mydomain,DC=com))"

you fill in whatever mydomain and GROUP above ^

What attributes would need to be in search controls?

The attributes listed in searchControls are the ones you want returned . The one containing the group members. Depending on what objectClass the group object is, it might be:

  • uniqueMember for groupOfUniqueNames
  • roleOccupant for organizationalRole

and so forth.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM