java中的LDAP搜索:DN包含,
我目前在搜索 DN 包含逗号的条目时遇到问题:
StringTokenizer st = new StringTokenizer(dn, "=");
Attributes searchAttributes = new BasicAttributes(st.nextToken(), st.nextToken());
Enumeration results = ctx.search(baseDn, searchAttributes);
if (results.hasMoreElements()) {
// ...
}
我测试了 dn=first,second
以及 dn=first\,second
, 虽然搜索运行正确,但我从未得到任何结果。相同的 baseDn 和 dn 在 Eclipse/Apache Directory Studio LDAP 浏览器中可以正常工作。
I'm currently running into issues when searching for entries where the DN contains a comma:
StringTokenizer st = new StringTokenizer(dn, "=");
Attributes searchAttributes = new BasicAttributes(st.nextToken(), st.nextToken());
Enumeration results = ctx.search(baseDn, searchAttributes);
if (results.hasMoreElements()) {
// ...
}
I tested both dn=first,second
as well as dn=first\,second
, and although the search runs correctly, I never get any results back. The same baseDn and dn works correctly in Eclipse/Apache Directory Studio LDAP Browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
依赖于库,例如通过使用 Novell ldap.jar
再次依赖于库,因为 Directory Studio LDAP 浏览器可能有自己的驱动程序,并且某些方法可能没有实现,例如使用 ldap.jar 能够在 ActiveDirectory 中搜索
基本上所有库(包括 Windows ActiveDirectory 的 Java 驱动程序)都包含大量与库一起包装的示例,对于在驱动程序中实现的最重要的方法
编辑:
嗯,但是管理员提供了两个相关的
1/ 上下文访问权限(环境之间)
2/ 使用 ActiveDirectory(始终)和(旧 PC)LDAP 测试环境,我必须强制线程稍微停顿
// 然后我才能开始迭代....
depends of libraries, for example by using Novell ldap.jar is constuctor
again depends or libraries, because maybe Directory Studio LDAP Browser has own driver, and some methods are implemented another maybe not, for example with ldap.jar is able to seach in ActiveDirectory
basically all libraries (including Java driver for Windows ActiveDirectory) contains tons of examples packed with library, for most importand of methods which are implemented into driver
EDIT:
hmmm, but there are two relevant
1/ access for context given by admin (between enviroments)
2/ with ActiveDirectory (always) and with (old PC) test enviroment for LDAP I must force for thread(s) some small pause
// thenafter I can able to start Iterations....
ldap查询的引用规则可以在http://www.rlmueller.net/CharactersEscaped.htm
我正在使用以下代码片段来查询 cn,对于 dn 应该同样有效:
The quoting rules for ldap queries can be found at http://www.rlmueller.net/CharactersEscaped.htm
I'm using the following code snippet to query the cn, should work teh same for the dn: