简体   繁体   中英

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

  • foo_l.c_bar@foobar.com
  • foobar@foo_l.c_bar

and the search query is "lc" I want only foo_l.c_bar@foobar.com

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?

I cannot give you a full answer, but if you try a ldapsearch from command line with the filter "(email=*lc*@*)" , 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM