如何使LdapContextSource指向UnboundID InMemoryDirectoryServer?

时间:2013-02-18 21:42:20

标签: spring-ldap unboundid-ldap-sdk

我有一套基于Spring LDAP框架的旧自动化测试用例。它们连接到外部LDAP服务器。我正在考虑用嵌入式服务器替换外部服务器。 UnboundID InMemoryDirectoryServer看起来很有吸引力,特别是如果有一种方法允许基于Spring LDAP的客户端连接基于UnboundID的嵌入式服务器。问题是:怎么做?我是LDAP新手,请帮助。

1 个答案:

答案 0 :(得分:4)

外部和嵌入式LDAP服务器的情况确实没有太大区别。配置LdapContextSource时,您必须将服务器的URL设置为ldap://localhost:33389/(假设您的嵌入式服务器侦听端口33389)。

请注意,默认情况下,UnboundID InMemoryDirectoryServer将在运行时随机选择一个空闲端口,除非您将其配置为侦听修复端口。这可能有助于您入门:

InMemoryDirectoryServerConfig config = 
        new InMemoryDirectoryServerConfig("dc=example, dc=com");

// make sure that the server listens on port 33389
config.setListenerConfigs(
        new InMemoryListenerConfig("myListener", null, 33389, null, null, null));

InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);

ds.startListening();

// import some test data from an ldif file
ds.importFromLDIF(true,"content.ldif");
相关问题