LDAP多个或语法

我希望这对任何LDAP专家来说都是一个简单的问题。

我正在使用java,SearchDirContext和一个字符串构建器来组合一个看起来像的查询: (|(givenName=smith*)(sn=smith*)(middleName=smith*)(mail=smith*)(telephoneNumber=smith*)(buildingName=smith*)(department=smith*)(major=smith*)(minor=smith*)) 。 这个想法是允许用户使用单个字符串进行搜索并获得与任何这些属性匹配的结果。

查询成功完成但结果不准确。 例如,如果我搜索自己(我知道我的记录存在)……

  • 按姓氏我没有结果
  • 通过名字(应该有数百个结果)我得到一个小子集(9),不包括我的条目。

我想首先消除我的查询问题的任何可能性,如果你想要更多的信息/代码执行代码的snippits告诉我,我可以提供它。

另外请记住,我是一个正确做事的强烈倡导者,我愿意修改我的代码的任何部分,以提高效率。

——————-(编辑)所以语法正确….(编辑)—————- —-

这是我的查询的一些代码,也许这可以确定我的结果是否被截止。

  try { context = ldapPooler.getContext(); // Returns a custom SearchDirContext object wrapping a javax.naming.DirContext. SearchControls controls = new SearchControls(); controls.setCountLimit(maxResultCount); Integer resultCount = 0; // They try block is from an example found at // http://www.java2s.com/Code/Java/JNDI-LDAP/howtoperformasearchandlimitthenumberofresultsreturned.htm // The goal was to limit the results. try { logger.debug("Finished w/the search string: " + ldapSearchString); @SuppressWarnings("unchecked") NamingEnumeration result = context.search("ou=People", ldapSearchString, controls); // SearchDirContext.search simply calls DirContext.search with the passed attributes. while (result.hasMore()) { searchResults.add(result.next()); resultCount++; } logger.debug("Found results: " + resultCount); } catch (LimitExceededException lee) { logger.debug("Caught LimitExceededException w/resultCount: " + resultCount); if (resultCount == maxResultCount) { logger.debug("Found " + resultCount + " results."); } else { logger.debug("In the else....not throwing an exception. Found " + resultCount + " results."); } } finally { context.close(); } } catch (NamingException ne) { logger.error("Caught a NamingException while gettingContactCardsBySearchString(" + searchString + ")"); throw new LdapLookupFailedException(ne); } catch (Exception e) { logger.error("Caught Exception while gettingContactCardsBySearchString(" + searchString + ")"); throw new LdapLookupFailedException(e); } 

根据RFC 4515,您的filter语法是正确的。我建议您不要将测试值放在搜索字符串中。 使用{0},{1}表示法并将值作为参数提供给search()。 当您获得的数据少于预期时,您可能会遇到分页搜索结果。 我会使用独立的LDAP客户端(如JXplorer)测试您的filter。

原来这是一个权限问题。 创建的帐户无权访问我正在搜索的属性。 我很想知道对经过身份validation的用户无法访问的属性的查询的预期结果是什么,如果那里的任何人想要发布那将是伟大的。 否则我想我通过整个交易了解了一些关于LDAP的内容,感谢您花时间尝试并提供帮助!