Q:

Generalise LDAP query for groups

I use the following query to find the groups each user is a member of:
(&(objectClass=group)(|(member=cn=UID,OU=ServiceAccounts,OU=MC,DC=ads,DC=myCompany,DC=com,DC=au)(member=cn=UID,OU=BTLY,OU=Sites,OU=MC,DC=ads,DC=myCompany,DC=com,DC=au)))
This query works and runs using the following Base DN:
OU=MC,DC=ads,DC=myCompany,DC=com,DC=au
I have few problems with the query:

I don't like having to use the OR operator to find Service Account users and BTLY users. 
I don't want to hard-code the BTLY site, there are others, too. 

Ideally, I'd just like to have the query as:
(&(objectClass=group)(|(member=cn=UID,OU=MC,DC=ads,DC=myCompany,DC=com,DC=au))
This way, I don't care whether the user account is a service account nor which site the account belongs to.  Unfortunately, that query doesn't work. 
Can someone please help me generalise the LDAP query?  I'm a bit of a newbie, so I'm most likely missing something completely obvious! 
Thanks! 

Thanks for the reply.  What you've said makes sense, but it doesn't help me, unfortunately.  We're using GlassFish  (a Java app server), and have configured it to point to the local AD server.  Normally, a person can tell GlassFish how to retrieve users, eg
(&(objectCategory=user)(CN=UID))
and GlassFish will pick up all the groups (perhaps by using the memberOf attribute). 
This time round we're using a different AD server which hosts a different directory of users.  GlassFish isn't able to retrieve the groups by itself.  So, there is a field where we can give GlassFish a custom query to find groups.  In this field, I've put the query I've posted which works, but is ugly and verbose. 
What I'd love to be able to do is:
(&(objectClass=group)(member=cn=UID))
but this doesn't work. 
Is there anyway to do this?  
Thanks,
Muel. 

A:

My guess is that using this technique is not possible.  You would need to use wildcard here:
(&(objectCategory=group)(member=CN=UID,*))

and this is not acceptable for DN attributes (like the one stored in 'member' property):
http://msdn.microsoft.com/en-us/library/ms676930(v=vs.85).aspx
My suggestion here would be: use some tool to generate 'ugly' query for you (using syntax mentioned above) and "feed" your tool with end result.  Can't see any option, sorry...

