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