Spring 引导 ldap 身份验证错误 [LDAP:错误代码 49 - 无效凭据]

Spring boot ldap Authentication Error [LDAP: error code 49 - Invalid Credentials]

我正在尝试连接到 ldap 服务器以使用 springboot 获取用户数据。我的 spring 启动 application.properties 为

spring.ldap.base=dc=example,dc=com
spring.ldap.password=Secret
spring.ldap.username=uid=admin,ou=user
spring.ldap.urls=ldap://myServerIP:389/
spring.data.ldap.repositories.enabled=true

当我尝试使用其余控制器获取数据时,出现代码 49 错误

ERROR 3535 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.ldap.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]] with root cause

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

由于我是 ldap 数据获取的新手,我不确定这是由 ldap 还是 springboot 连接引起的。如果有人能解释并给我解决方案就太好了

这是因为我在 application.properties

中配置 LDAP 的方式存在问题

实际配置应该是:

spring.ldap.password=secret
spring.ldap.username=cn=admin,dc=example,dc=com
spring.ldap.urls=ldap://myserverIP:389/

并且base应该在模型class中设置为

@Entry( base = "dc=example,dc=com",objectClasses = {"inetOrgPerson"})
public class ldapUserModel {
//attributes, getters and setters
}

object class 应该更改为 object class 你更喜欢搜索并执行其他常用编码。