SpringBoot整合LDAP的流程分析
更新時間:2021年05月08日 14:13:38 作者:秋風(fēng)颯颯吹
這篇文章主要介紹了SpringBoot整合LDAP的流程分析,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
配置
application.yml
spring:
ldap:
urls: ldap://192.168.1.53:389
username: cn=Manager,${spring.ldap.base}
password: hadoop
base: dc=haohaozhu,dc=com
實體類和Dao
/**
* @author wen.jie
* @date 2021/5/8 12:31
*/
@Data@ToString
@Entry(base = "ou=people,dc=haohaozhu,dc=com", objectClasses = "inetOrgPerson")
public class Person {
@Id
private Name id;
@DnAttribute(value = "uid")
private String uid;
@Attribute(name = "cn")
private String cn;
@Attribute(name = "sn")
private String sn;
@Attribute(name="mail")
private String mail;
@Attribute(name = "homedirectory")
private String homedirectory;
@Attribute(name = "gidnumber")
private String gidnumber;
@Attribute(name = "uidnumber")
private String uidnumber;
}
public interface PersonRepository extends LdapRepository<Person> {
}
測試
@SpringBootTest
class BootLdapApplicationTests {
@Autowired
private PersonRepository personRepository;
@Autowired
private LdapTemplate template;
@Test
public void findAll() {
personRepository.findAll().forEach(System.out::println);
}
@Test
public void findAll2() {
Person person = template.findOne(LdapQueryBuilder.query().where("uid").is("ldapuser2"), Person.class);
System.out.println(person);
}
@Test
public void authenticationTest() {
String uid = "ldapuser2";
Person authenticate = template.authenticate(
LdapQueryBuilder.query().where("uid").is(uid),
"hadoop",
(dirContext, ldapEntryIdentification) ->
template.findOne(LdapQueryBuilder.query().where("uid").is(uid), Person.class));
System.out.println(authenticate);
}
}
findAll:

findAll2:

authenticationTest:

到此這篇關(guān)于SpringBoot整合LDAP的流程分析的文章就介紹到這了,更多相關(guān)SpringBoot整合LDAP內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Spring?Security認證器實現(xiàn)過程詳解
一些權(quán)限框架一般都包含認證器和決策器,前者處理登陸驗證,后者處理訪問資源的控制,這篇文章主要介紹了Spring?Security認證器實現(xiàn)過程,需要的朋友可以參考下2022-06-06
SpringBoot實現(xiàn)Thymeleaf驗證碼生成
本文使用SpringBoot實現(xiàn)Thymeleaf驗證碼生成,使用后臺返回驗證碼圖片,驗證碼存到session中后端實現(xiàn)校驗,前端只展示驗證碼圖片。感興趣的可以了解下2021-05-05
java讀取圖片并轉(zhuǎn)化為二進制字符串的實現(xiàn)方法
這篇文章主要介紹了java讀取圖片并轉(zhuǎn)化為二進制字符串的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09

