Vito De Tullio
Vito De Tullio

Reputation: 2121

ldap search filter with java

I'm having problems with ldap search filters. I want to search through all the children of a root node. I want the users where the username of the email contains the query string. for example, if I have

and the search query is "l.c" I want only [email protected]

the following code, surprisingly, returns either the first and the second.

String query = "...";
DirContext dc = ...;
NamingEnumeration<SearchResult> ne = dc.search(root,
    "(email=*{0}*@*)",
    new Object[] { query }, null);

what's wrong in the "*...*@*" query filter?

Upvotes: 2

Views: 2911

Answers (2)

Gr&#233;gory Joseph
Gr&#233;gory Joseph

Reputation: 1657

I assume you forgot to paste the code that formatted your query and its {0} parameter ? edit: wow, forget me, I didn't even know about the method that takes the filterArgs array.

As a side note, the standard attribute for e-mail address in inetOrgPerson is "mail" not "email" (but it might be different on your case of course)

Upvotes: 0

Kaltezar
Kaltezar

Reputation: 721

I cannot give you a full answer, but if you try a ldapsearch from command line with the filter "(email=*l.c*@*)", you should get the right records ... so I would say the problem is in the Java method and not in the filter.

Hope it could help you.

Upvotes: 1

Related Questions