- pom.xml引入所需要的jar:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-ldap</artifactId> </dependency>
-
在yml配置文件加入相关配置:
ldap:
urls: ldap://xxx.xx.xx.xx:389
base: DC=xxx,DC=xxx,DC=xxx
username: xxx
password: xxx -
创建LdapConfiguration:
private static final String INITIAL_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory"; privatestatic final String SECURITY_AUTHENTICATION = "simple"; privatestatic final String REFERRAL = "follow"; @Value("${spring.ldap.urls}") private String urls; @Value("${spring.ldap.base}") private String base; @Value("${spring.ldap.username}") private String username; @Value("${spring.ldap.pa