加依赖
<!-- ldap -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
yml文件配置
spring:
ldap:
urls: ldap://66.3.125.35:389
base: dc=test,dc=com
username: cn=service,dc=test,dc=com
password: hidata!@#
authentication: simple
ldapCtxFactory: com.sun.jndi.ldap.LdapCtxFactory
配置初始化类 LdapConfiguration
package com.ruoyi.web.core.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.NamingException;
import javax.naming.Context;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import java.util.Hashtable;
@Configuration
public class LdapConfiguration {
private DirContext dirContext