毕宿五ne 2022-08-24 15:44 采纳率: 0%
浏览 15

SpringBoot整合LDAP遇到无效验证问题, 求解答

问题遇到的现象和发生背景

我正在尝试使用SpringBoot 整合 LDAP进行测试, 但却没有成功,抛出了 [LDAP: error code 49 - Invalid Credentials]的异常
这里的用户名 密码 我都是使用默认的,(cn=Manager, secret)

问题相关代码,请勿粘贴截图

applicatin.yml
spring:
ldap:
urls: ldap://localhost:389
base: dc=maxcrc,dc=com
username: cn=Manager
password: secret

LdapConfiguration.java

package com.example.ldap.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class LdapConfiguration {

    private LdapTemplate ldapTemplate;

    @Value("${spring.ldap.urls}")
    private String url;

    @Value("${spring.ldap.base}")
    private String base;

    @Value("${spring.ldap.username}")
    private String username;

    @Value("${spring.ldap.password}")
    private String password;

    @Bean
    public LdapContextSource contextSource() {
        LdapContextSource contextSource = new LdapContextSource();
        Map<String, Object> config = new HashMap<>();
        contextSource.setUrl(url);
        contextSource.setBase(base);
        contextSource.setUserDn(username);
        contextSource.setPassword(password);
        //  解决乱码
        config.put("java.naming.ldap.attributes.binary", "objectGUID");

        contextSource.setPooled(true);
        contextSource.setBaseEnvironmentProperties(config);
        return contextSource;
    }

    @Bean
    public LdapTemplate ldapTemplate() {
        if (null == ldapTemplate) {
            ldapTemplate = new LdapTemplate(contextSource());
        }
        return ldapTemplate;
    }

}

运行结果及报错内容
Caused by: javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
    at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3261)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3207)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2993)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2907)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:347)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxFromUrl(LdapCtxFactory.java:225)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:189)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:243)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
    at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:695)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
    at javax.naming.InitialContext.init(InitialContext.java:244)
    at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:154)
    at org.springframework.ldap.core.support.LdapContextSource.getDirContextInstance(LdapContextSource.java:42)
    at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:351)
    ... 73 more

我的解答思路和尝试过的方法

我尝试百度 Google, 但都没有有效解决问题
看到您在一篇文章的评论中说解决了这个问题
您能帮助我解答疑惑吗?

我想要达到的结果

使用Springboot 整合 LDAP 实现CURD效果

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-08-24 16:46
    关注
    看下这篇博客,也许你就懂了,链接:Springboot LDAP开发
    评论

报告相同问题?

问题事件

  • 创建了问题 8月24日

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败