Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query multiple users from LDAP

Tags:

java

unix

ldap

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....")  .
like image 897
Thrinath Reddy Avatar asked Feb 23 '17 12:02

Thrinath Reddy


1 Answers

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 OR uid=name2 OR uid=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!

like image 61
anacron Avatar answered Oct 07 '22 18:10

anacron