gpt4 book ai didi

java - UnboundID LDAP SDK 不遵循推荐

转载 作者:行者123 更新时间:2023-11-30 03:52:16 27 4
gpt4 key购买 nike

我正在使用 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 的 LDAPSearchException,这意味着服务器发送了引用。将 RefererHopLimit 更改为更高的数字并没有帮助,因此显然该库没有遵循引用。

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

最佳答案

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);
}
}

关于java - UnboundID LDAP SDK 不遵循推荐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24127334/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com