2013-02-18 62 views
2

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

回答

4

外部LDAP服务器和嵌入式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"); 
+0

谢谢@zagyi :)它似乎工作! – SolutionMill 2013-02-19 17:45:53

+0

不客气! :)如果解决方案有效,我是否可以请你接受并且可能upvote我的答案?我只是问这个,因为我看到你是一个新用户。 :) – zagyi 2013-02-19 18:26:00