Spring Boot LDAP认证错误 [LDAP:错误代码49 – 无效凭据]

huangapple go评论159阅读模式
英文:

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

问题

我正在尝试使用Spring Boot连接到LDAP服务器以获取用户数据。我的Spring Boot应用的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还是Spring Boot连接引起的。如果有人能解释并给出解决方案,将会非常棒。

英文:

I am trying to connect to the ldap server to fetch user data using springboot. My spring boot application.properties as

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

when I try to get the data using the rest controller I am getting an error of code 49 stating

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]

As I am new to ldap data fetching am not sure whether this is caused from the ldap or from the springboot connectivity. If could anyone explain and give me solution would be great

答案1

得分: 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 {
    // 属性、getter 和 setter 方法
}

将对象类更改为您喜欢的对象类,然后进行其他常规编码。

英文:

This was caused because, there was a issue on the way I configured the LDAP in application.properties

Actual configuration should be :

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

And the base should be set in the model class as

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

object class should be changed to the object class ypu prefer to search and do the other usual codings.

huangapple
  • 本文由 发表于 2020年9月8日 16:52:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63790454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定