简体   繁体   English

ldap使用Java搜索过滤器

[英]ldap search filter with java

I'm having problems with ldap search filters. ldap搜索过滤器出现问题。 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 foo_l.c_bar@foobar.com
  • foobar@foo_l.c_bar foob​​ar@foo_l.c_bar

and the search query is "lc" I want only foo_l.c_bar@foobar.com 并且搜索查询是“ lc”,我只需要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. 我无法给您完整的答案,但是,如果您使用过滤器"(email=*lc*@*)"从命令行尝试ldapsearch ,则应该得到正确的记录...所以我认为问题出在Java方法而不在过滤器中。

Hope it could help you. 希望它能对您有所帮助。

I assume you forgot to paste the code that formatted your query and its {0} parameter ? 我假设您忘记粘贴格式化查询及其代码的{0}参数的代码了吗? edit: wow, forget me, I didn't even know about the method that takes the filterArgs array. 编辑:哇,算了,我什至不知道采用filterArgs数组的方法。

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) 附带说明一下,inetOrgPerson中电子邮件地址的标准属性是“ mail”而不是“ email”(但是您的情况可能会有所不同)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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