SpringBoot整合LDAP的流程分析
更新時(shí)間:2021年05月08日 14:13:38 作者:秋風(fēng)颯颯吹
這篇文章主要介紹了SpringBoot整合LDAP的流程分析,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
依賴
<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
實(shí)體類和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> {
}
測(cè)試
@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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
- SpringLDAP連接LDAPS證書報(bào)錯(cuò)問(wèn)題及解決
- springboot操作ldap全過(guò)程
- springboot配置ldaps連接方式
- SpringBoot整合Ldap的實(shí)現(xiàn)示例
- Spring Security LDAP實(shí)現(xiàn)身份驗(yàn)證的項(xiàng)目實(shí)踐
- 淺談Spring Security LDAP簡(jiǎn)介
- Vue+Jwt+SpringBoot+Ldap完成登錄認(rèn)證的示例代碼
- Spring Boot中使用LDAP來(lái)統(tǒng)一管理用戶信息的示例
- Spring Boot 連接LDAP的方法
- Spring LDAP目錄服務(wù)的使用示例
相關(guān)文章
Spring?Security認(rèn)證器實(shí)現(xiàn)過(guò)程詳解
一些權(quán)限框架一般都包含認(rèn)證器和決策器,前者處理登陸驗(yàn)證,后者處理訪問(wèn)資源的控制,這篇文章主要介紹了Spring?Security認(rèn)證器實(shí)現(xiàn)過(guò)程,需要的朋友可以參考下2022-06-06
SpringBoot實(shí)現(xiàn)Thymeleaf驗(yàn)證碼生成
本文使用SpringBoot實(shí)現(xiàn)Thymeleaf驗(yàn)證碼生成,使用后臺(tái)返回驗(yàn)證碼圖片,驗(yàn)證碼存到session中后端實(shí)現(xiàn)校驗(yàn),前端只展示驗(yàn)證碼圖片。感興趣的可以了解下2021-05-05
java讀取圖片并轉(zhuǎn)化為二進(jìn)制字符串的實(shí)現(xiàn)方法
這篇文章主要介紹了java讀取圖片并轉(zhuǎn)化為二進(jìn)制字符串的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-09-09

