1

我正在使用 UnboundID LDAP Java SDK 将 Groovy/Grails 应用程序连接到 Active Directory。以下是我正在使用的连接选项:

  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,这意味着服务器发送了一个推荐。将 referHopLimit 更改为更高的数字并没有帮助,因此很明显图书馆没有遵循推荐。

到目前为止,我似乎只在使用 LDAPConnection.getEntry 方法加载由 DN 指定的特定条目时遇到此问题。执行搜索时我还没有收到它。所以我想知道 getEntry 方法是否不应该遵循推荐,如果是这种情况,手动遵循推荐或更改其行为的最佳方法是什么?

4

1 回答 1

2

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);
  }
}
于 2014-06-09T20:52:51.937 回答