• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

SpringBoot整合LDAP的流程分析

springboot 搞代码 4年前 (2022-01-05) 19次浏览 已收录 0个评论

这篇文章主要介绍了SpringBoot整合LDAP的流程分析,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

依赖

  org.springframework.bootspring-boot-starter-data-ldap org.projectlomboklomboktrue org.springframework.bootspring-boot-starter-testtest

配置

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") privat<i style="color:transparent">来源gaodai$ma#com搞$代*码网</i>e String homedirectory; @Attribute(name = "gidnumber") private String gidnumber; @Attribute(name = "uidnumber") private String uidnumber; } public interface PersonRepository extends LdapRepository { }

测试

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

以上就是SpringBoot整合LDAP的流程分析的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:SpringBoot整合LDAP的流程分析

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址