LDAP中的LDAP搜索:DN包含, [英] LDAP search in java: DN contains ,

查看:565
本文介绍了LDAP中的LDAP搜索:DN包含,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索DN中包含逗号的条目时,我正遇到问题:

  StringTokenizer st = new StringTokenizer (dn,=); 
属性searchAttributes = new BasicAttributes(st.nextToken(),st.nextToken());
枚举结果= ctx.search(baseDn,searchAttributes);

if(results.hasMoreElements()){
// ...
}

我测试了 dn = first,second 以及 dn = first\,second 虽然搜索正常运行,我从来没有得到任何结果。相同的baseDn和dn在Eclipse / Apache Directory Studio LDAP浏览器中正常工作。

解决方案

依赖于库,例如使用Novell ldap.jar是constuctor

  searchResults = lc.search(searchBase,searchScope,searchFilter,null,false); 
// private String searchFilter =(objectClass = *);

再次依赖或库,因为也许Directory Studio LDAP浏览器有自己的驱动程序,还有一些方法实现了另一个可能没有,例如,ldap.jar能够在ActiveDirectory中浏览



基本上所有库(包括Windows ActiveDirectory的Java驱动程序)都包含大量包含库的示例,驱动程序中实现的大多数导入和方法



编辑:



嗯,但是有两个相关的< ($)

1 /由管理员(环境之间)提供的上下文
2 /与ActiveDirectory(总是)和LDAP(老PC)测试环境LDAP必须强制线程一些小暂停

  private void readData(){
searchResults = new LDAPSearchResults();
try {
Thread.sleep(450);
} catch(InterruptedException ex){
Logger.getLogger(Profylaxia.class.getName())。log(Level.SEVERE,null,ex);
}
try {
searchResults = lc.search(searchBase,searchScope,searchFilter,null,false);
try {
Thread.sleep(500);
} catch(InterruptedException ex){
Logger.getLogger(Profylaxia.class.getName())。log(Level.SEVERE,null,ex);
}
int noResult = searchResults.getCount();
System.out.println(noResult:+ noResult);

//然后我可以开始迭代....


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.

解决方案

depends of libraries, for example by using Novell ldap.jar is constuctor

searchResults = lc.search(searchBase, searchScope, searchFilter, null, false);
//private String searchFilter = "(objectClass=*)"; 

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

private void readData() {
        searchResults = new LDAPSearchResults();
        try {
            Thread.sleep(450);
        } catch (InterruptedException ex) {
            Logger.getLogger(Profylaxia.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            searchResults = lc.search(searchBase, searchScope, searchFilter, null, false);
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(Profylaxia.class.getName()).log(Level.SEVERE, null, ex);
            }
            int noResult = searchResults.getCount();
            System.out.println("  noResult : " + noResult);

// thenafter I can able to start Iterations....

这篇关于LDAP中的LDAP搜索:DN包含,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆