2013-02-18 22 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