SpringBoot整合LDAP的流程分析
短信预约 -IT技能 免费直播动态提醒
依赖
<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
@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:
到此这篇关于SpringBoot整合LDAP的流程分析的文章就介绍到这了,更多相关SpringBoot整合LDAP内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341