SpringBoot整合LDAP的流程分析

网友投稿 410 2022-10-25


SpringBoot整合LDAP的流程分析

依赖

org.springframework.boot

spring-boot-starter-data-ldap

org.projectlombok

lombok

true

org.springframework.boot

spring-boot-starter-test

test

配置

application.yml

spring:

ldap:

urls: ldap://192.168.1.53:389

username: cn=Manager,${spring.ldap.base}

password: hadoop

base: dc=haohaozhu,dc=comhttp://

实体类和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 = http://"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 {

}

测试

@SpringBootTest

class BootLdapJbYPVIHjyVApplicationTests {

@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:


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:C语言实现数组快速排序(含对算法的详细解释)
下一篇:jvm内存模型及分配参数
相关文章

 发表评论

评论列表