如何使用 Spring Boot 连接外部/在线 LDAP 服务器?



我正在尝试在我的 Spring 启动应用程序中集成基于 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 引导应用程序提供工作配置吗?

因为我从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");

这是正确的配置:

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

使用以下应用程序属性。

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}

最新更新