【问题标题】:UnboundID LDAP SDK not following ReferralsUnboundID LDAP SDK 不遵循推荐
【发布时间】:2014-06-10 04:52:51
【问题描述】:

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

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

【问题讨论】:

    标签: java grails ldap referrals unboundid-ldap-sdk


    【解决方案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);
      }
    }
    

    【讨论】:

    • 谢谢。明天我会试试你的例子并报告。但是,我感觉这样一个乏味的示例会起作用,即使连接到我们的 Active Directory 实例时的类似代码无法遵循引用。我还想问一下,你认为使用连接池会改变什么吗(我正在使用连接池连接到 Active Directory)?
    • 连接是否是连接池的一部分不应该对引荐的处理产生任何影响。并且只要正确形成了引用,那么将哪种类型的目录服务器发送给客户端就无关紧要了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多