且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LDAP中的LDAP搜索:DN包含,

更新时间:2022-10-23 14:10:52

依赖于库,例如使用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....