2013-01-08 34 views
2

我有一段代碼在綁定操作後在活動目錄服務器上執行搜索。我使用LDAP協議綁定和我的代碼如下所示:使用匿名進行活動目錄搜索bind

env.put(Context.INITIAL_CONTEXT_FACTORY, 
      "com.sun.jndi.ldap.LdapCtxFactory"); 

    env.put(Context.SECURITY_AUTHENTICATION, "none"); 
    env.put("com.sun.jndi.ldap.read.timeout", "9000"); 
    env.put("com.sun.jndi.ldap.connect.timeout", "9000"); 

      env.put(Context.PROVIDER_URL, "ldap://" + "nec.jp"); 
      DirContext ctx = new InitialDirContext(env); 
      NamingEnumeration<SearchResult> answer = ctx.search(
         searchBase, searchFilter, searchCtls); 
     if (answer.hasMore()) 
      { 
        env.put(Context.SECURITY_PRINCIPAL, principalNameres); 
        env.put(Context.SECURITY_CREDENTIALS, userPasswd); 
        env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
        final DirContext ctxForSerachedResult = new InitialDirContext(
          env); 
        ctxForSerachedResult.close(); 

      } 

我在這裏的問題是與匿名登錄的用戶進行搜索AD服務器的配置。

作爲每理解爲遠,匿名可以通過執行以下所示的步驟啓用:

一個。通過更改DsHeuristics屬性值啓用匿名LDAP操作。

b。提供讀取目錄的權限。

簡稱鏈接:

我曾試圖使用Ldp.exe綁定匿名登錄成功,如圖下圖所示的圖像批准Active Directory中設置:

但是搜索操作仍然不能按需要工作。

請建議我在哪裏出錯。

回答

1

你顯然只顯示你的部分片段,而你卻沒有分享什麼是不工作的。

你在期待什麼。

我們確實有一個sample for JNDI即使它不是一個匿名綁定可能會有所幫助。

+0

當執行搜索的輸出來作爲---- ***搜索... ldap_search_s(LD, 「DC = nec,DC = jp」,2,「(samAccountName = dctestuser1)」,attrList,0,&msg) 獲取0個條目: ----------- Active Directory服務器用戶名稱爲「dctestuser1」。 – user1931914

1

對不起張貼的答案下旬..代碼如下所示修改制定了:)

 DirContext ctx = new InitialDirContext(env); 

      final NamingEnumeration<SearchResult> answer = ctx.search(
        searchBase, searchFilter, searchCtls); 
      if (answer.hasMore()) { 
       /* 
       * Retrieving providerUrl and principal from the answer 
       * returned after search 
       */ 
       if (bindAlgoValue.equals(BINDANONYMOUS)) { 
        env.put(Context.SECURITY_AUTHENTICATION, BINDSIMPLE); 
       } 
       final SearchResult res = answer.next(); 
       final String principalName = res.getNameInNamespace(); 
       final String providerUrl = res.getName(); 
       if (!res.isRelative()) { 
        env.put(Context.PROVIDER_URL, providerUrl); 
       } 
       env.put(Context.SECURITY_PRINCIPAL, principalName); 
       env.put(Context.SECURITY_CREDENTIALS, userPasswd); 
       ctx = new InitialDirContext(env); 
       ctx.close(); 
       return true; 
       // Code Fix End for BUG ID #1304 
      }