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

时间:2020-09-08 08:52:41

标签: java spring spring-boot ldap

我正在尝试连接到ldap服务器以使用springboot来获取用户数据。我的春季启动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

当我尝试使用rest控制器获取数据时,出现了代码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连接引起的。如果有人可以解释并给我解决方案,那就太好了

1 个答案:

答案 0 :(得分:0)

这是由于我在application.properties中配置LDAP的方式存在问题

实际配置应为:

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

并且基数应该在模型类中设置为

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

应将对象类更改为对象类ypu希望搜索并执行其他常用编码。