2014-06-09 47 views
0

我正在使用UnboundID LDAP Java SDK將Groovy/Grails應用程序連接到Active Directory。下面是我使用的連接選項:UnboundID LDAP SDK不在推薦

LDAPConnectionOptions options = new LDAPConnectionOptions() 
    options.connectTimeoutMillis = 60000 // 1 minute 
    options.followReferrals = true 
    options.referralHopLimit = 10 
    options.responseTimeoutMillis = 60000 // 1 minute 
    options.useSynchronousMode = true 

不過,我仍然保持與結果碼10,這意味着服務器發送的推薦越來越LDAPSearchExceptions。將referralHopLimit更改爲更高的數字並沒有幫助,因此很顯然,該庫並未遵循引薦。

到目前爲止,我似乎只有在使用LDAPConnection.getEntry方法加載由DN指定的特定條目時纔會出現此問題。執行搜索時我還沒有收到它。所以我想知道如果getEntry方法不應該跟隨引用,並且如果是這種情況,手動跟蹤引用或更改其行爲的最佳方法是什麼?

回答

1

getEntry方法在幕後使用搜索,所以如果搜索起作用,那麼getEntry也應該起作用。我只是跑了一個快速測試,它適用於我。使用最新的LDAP SDK版本(2.3.6)和下面的代碼,我可以在引用後獲得預期的條目。如果我註釋掉「opts.setFollowReferrals(true)」一行,那麼我得到一個推薦異常:

import com.unboundid.ldap.listener.*; 
import com.unboundid.ldap.sdk.*; 



public class ReferralTest 
{ 
    public static void main(final String... args) 
     throws Exception 
    { 
    final InMemoryDirectoryServerConfig cfg = 
     new InMemoryDirectoryServerConfig("dc=example,dc=com"); 
    final InMemoryDirectoryServer ds1 = new InMemoryDirectoryServer(cfg); 
    final InMemoryDirectoryServer ds2 = new InMemoryDirectoryServer(cfg); 

    ds1.startListening(); 
    ds2.startListening(); 

    final LDAPConnectionOptions opts = new LDAPConnectionOptions(); 
    opts.setFollowReferrals(true); 

    final LDAPConnection conn1 = ds1.getConnection(opts); 
    final LDAPConnection conn2 = ds2.getConnection(opts); 

    conn1.add(
     "dn: dc=example,dc=com", 
     "objectClass: top", 
     "objectClass: domain", 
     "dc: example"); 
    conn1.add(
     "dn: ou=Referral Entry,dc=example,dc=com", 
     "objectClass: top", 
     "objectClass: organizationalUnit", 
     "ou: Referral Entry", 
     "description: This is a referral entry"); 

    conn2.add(
     "dn: dc=example,dc=com", 
     "objectClass: top", 
     "objectClass: domain", 
     "dc: example"); 
    conn2.add(
     "dn: ou=Referral Entry,dc=example,dc=com", 
     "objectClass: top", 
     "objectClass: referral", 
     "objectClass: extensibleObject", 
     "ou: Referral Entry", 
     "ref: ldap://127.0.0.1:" + ds1.getListenPort() + 
       "/ou=Referral Entry,dc=example,dc=com"); 

    final Entry e = conn2.getEntry("ou=Referral Entry,dc=example,dc=com"); 
    System.out.println(e.toLDIFString()); 

    conn1.close(); 
    conn2.close(); 

    ds1.shutDown(true); 
    ds2.shutDown(true); 
    } 
} 
+0

謝謝。我明天會試試你的例子並回報。但是,我有一種感覺,這樣一個不育的例子將起作用,即使連接到我們的Active Directory實例時的類似代碼沒有遵循引用。我也想問,你認爲使用連接池會改變什麼(我正在使用連接池連接到Active Directory)? –

+0

連接是否是連接池的一部分不應該對推薦的處理產生任何影響。只要引薦正確組成,那麼它應該是什麼類型的目錄服務器發送給客戶端無關緊要。 –