Search code examples
filterldapldap-query

how to check whether any user exists as part of GROUP-FILTER in ldap


Say, I want to retrieve some users and I have provided both user_filter & group_filter to filter out the specific users that I need. user_filter = (&(cn=ab*)(sn=cd*)) group_filter = (|(cn=gh*)(cn=kl*))

I know how to write individual queries for user & group. How can I combine the above filters to write a single query such that I get the users whose common name starts with 'ab' and surname starts with 'cd' and they either belong to groups which start with 'gh' or 'kl'?


Solution

  • It depends how you have membership defined. If you have membership on the groups, eg. group1 has member attribute for user1, this combined query is not possible. If you have groups defined on the user, eg. user1 has memberOf attribute for group1, then you may do something like

    (&(objectclass=user)(cn=ab*)(sn=cd*)(|(memberof=cn=gh*)(memberof=cn=kl*)))