java ldap 查询完整dn,LDAP中的LDAP搜索:DN包含,

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....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值