2017-08-24 165 views
0

我想在我的Spring Boot應用程序中集成基於LDAP的登錄。如何使用Spring Boot連接外部/在線LDAP服務器?

作爲第一步,我試圖使用這個LDAP服務器(http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/)。

但是,我無法成功連接到服務器,並得到此錯誤。

nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials] 

我在配置類中使用這些信息。

authenticationManagerBuilder.ldapAuthentication() 
      .contextSource().url("ldap://ldap.forumsys.com:389/dc=example,dc=com") 
      .managerDn("cn=read-only-admin,dc=example,dc=com").managerPassword("password") 
      .and() 
      .userSearchBase("ou=mathematicians") 
      .groupSearchBase("ou=mathematicians") 
      .userSearchFilter("(cn={0})"); 

這是我的這個項目的application.properties文件。

spring.ldap.urls=ldap.forumsys.com:389 
spring.ldap.base=cn=read-only-admin,dc=example,dc=com 
spring.ldap.password=password 

任何人都可以使用LDAP服務器爲Spring Boot應用程序提供工作配置嗎?

回答

0

因爲我從LDAP服務器得到這個錯誤代碼。

LDAP: error code 49 - Invalid Credentials 

該問題與我發送到LDAP服務器以打開通信通道的信息有關。所以當我將我的請求改爲另一個對象時,它開始工作。

這是我們需要從Spring發送到LDAP服務器的正確請求。

authenticationManagerBuilder 
       .ldapAuthentication() 
       .userDetailsContextMapper(inetOrgPersonContextMapper()) 
       .userSearchFilter("(uid={0})") 
       .userSearchBase("dc=example,dc=com") 
       .groupSearchBase("ou=mathematicians,dc=example,dc=com") 
       .groupSearchFilter("cn={0}") 
       .contextSource() 
       .url("ldap://ldap.forumsys.com") 
       .port(389) 
       .managerDn("cn=read-only-admin,dc=example,dc=com") 
       .managerPassword("password"); 
0

最後。經過一番嘗試,我已經能夠解決這個問題。我會在完成我的工作後發佈一些細節。

0

使用以下應用程序屬性。

ldap.enabled = true 

####### LDAP TEST############## 
ldap.urls= ldap://ldap.forumsys.com:389/ 
ldap.base.dn= dc=example,dc=com 
ldap.username= cn=read-only-admin,dc=example,dc=com 
ldap.password= password 
ldap.user.dn.pattern = uid={0}