Skip to content

Commit f356489

Browse files
committed
使用LDAP来统一管理用户信息
1 parent effa9b6 commit f356489

File tree

9 files changed

+176
-0
lines changed

9 files changed

+176
-0
lines changed

Chapter3-2-10/pom.xml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>Chapter3-2-10</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Chapter3-2-10</name>
12+
<description>Spring Boot project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.9.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-data-ldap</artifactId>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>com.unboundid</groupId>
39+
<artifactId>unboundid-ldapsdk</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-test</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.projectlombok</groupId>
51+
<artifactId>lombok</artifactId>
52+
<version>1.16.16</version>
53+
<scope>provided</scope>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-maven-plugin</artifactId>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.didispace;
2+
3+
import lombok.Data;
4+
import org.springframework.ldap.odm.annotations.*;
5+
6+
import javax.naming.Name;
7+
8+
@Entry(base = "ou=people,dc=didispace,dc=com", objectClasses = "inetOrgPerson")
9+
@Data
10+
public class Person {
11+
12+
@Id
13+
private Name id;
14+
@DnAttribute(value = "uid", index = 3)
15+
private String uid;
16+
@Attribute(name = "cn")
17+
private String commonName;
18+
@Attribute(name = "sn")
19+
private String suerName;
20+
private String userPassword;
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.didispace;
2+
3+
import org.springframework.data.repository.CrudRepository;
4+
5+
import javax.naming.Name;
6+
7+
public interface PersonRepository extends CrudRepository<Person, Name> {
8+
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#spring.ldap.urls=ldap://localhost:1235
2+
#spring.ldap.base=dc=didispace,dc=com
3+
#spring.ldap.username=didispace
4+
#spring.ldap.password=123456
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.didispace;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.test.context.junit4.SpringRunner;
8+
9+
@RunWith(SpringRunner.class)
10+
@SpringBootTest
11+
public class ApplicationTests {
12+
13+
@Autowired
14+
private PersonRepository personRepository;
15+
16+
@Test
17+
public void findAll() throws Exception {
18+
19+
personRepository.findAll().forEach(p -> {
20+
System.out.println(p);
21+
});
22+
23+
}
24+
25+
@Test
26+
public void save() throws Exception {
27+
Person person = new Person();
28+
person.setUid("uid:1");
29+
person.setSuerName("AAA");
30+
person.setCommonName("aaa");
31+
person.setUserPassword("123456");
32+
personRepository.save(person);
33+
34+
personRepository.findAll().forEach(p -> {
35+
System.out.println(p);
36+
});
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring.ldap.embedded.ldif=ldap-server.ldif
2+
spring.ldap.embedded.base-dn=dc=didispace,dc=com
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
dn: dc=didispace,dc=com
2+
objectClass: top
3+
objectClass: domain
4+
5+
dn: ou=people,dc=didispace,dc=com
6+
objectclass: top
7+
objectclass: organizationalUnit
8+
ou: people
9+
10+
dn: uid=ben,ou=people,dc=didispace,dc=com
11+
objectclass: top
12+
objectclass: person
13+
objectclass: organizationalPerson
14+
objectclass: inetOrgPerson
15+
cn: didi
16+
sn: zhaiyongchao
17+
uid: didi
18+
userPassword: {SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- chapter3-2-7:[整合MyBatis](http://blog.didispace.com/springbootmybatis/)
4444
- chapter3-2-8:[MyBatis注解配置详解](http://blog.didispace.com/mybatisinfo/)
4545
- chapter3-2-9:[使用Flyway来管理数据库版本](http://blog.didispace.com/spring-boot-flyway-db-version/)
46+
- chapter3-2-10:[使用LDAP来统一管理用户信息](http://blog.didispace.com/spring-boot-ldap-user/)
4647

4748
#### 事务管理
4849

0 commit comments

Comments
 (0)