How to query multiple users from LDAP.
I am using DirContext.search(base,filter,scope); in my java program
as of now its working fine with one value filter. filter=("uid=name")
but my requirement is to pass multiple names to the filter at a time like
filter=("uid=name1,name2,name3....") .
LDAP uses a "PREFIX" notation for its filters.
For example:
OR condition
(|(attr1=val1)(attr2=val2)(attr1=val2))
AND condition
(&(attr1=val1)(attr2=val2)(attr1=val2))
In your case, the filter criteria will be this:
filter = "(|(uid=name1)(uid=name2)(uid=name3))"
The above filter means:
Find any user who has
uid=name1
ORuid=name2
ORuid=name3
.
This should list you users whose user IDs are name1, name2 or name3.
More Exmples:
Equality:
(attribute=abc)
, e.g. (&(objectclass=user)(displayName=JohnDoe))Negation:
(!(attribute=abc))
, e.g. (!objectClass=group)Presence:
(attribute=*)
, e.g. (mailNickName=*)Absence:
(!(attribute=*))
, e.g. (!proxyAddresses=*)Greater than:
(attribute>=abc)
, e.g. (storageQuota>=100000)Less than:
(attribute<=abc)
, e.g. (storageQuota<=100000)Proximity:
(attribute~=abc)
, e.g. (displayName~=JohnDoe)*(~= may not be compatible with all directory servers !!)
Wildcards: e.g. (sn=J*) or (mail=*@example.com) or (givenName=*John*)
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With