2014-06-09 50 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

连接是否是连接池的一部分不应该对推荐的处理产生任何影响。只要引荐正确组成,那么它应该是什么类型的目录服务器发送给客户端无关紧要。 –