views:

314

answers:

2

Hi all. 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?

+1  A: 

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.

Kaltezar
unfortunately ATM I don't have a linux machine w/ ldapsearch installed.The only ldap manager I have is JXplorer which return all the records, not only the right ones.AFAIK it is written in java itself, so I don't know if it's me or java.
Vito De Tullio
A: 

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)

Grégory Joseph