开发者

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 "l.c" 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=*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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜