diff --git a/Chapter3-2-10/pom.xml b/Chapter3-2-10/pom.xml new file mode 100644 index 0000000..a5527fc --- /dev/null +++ b/Chapter3-2-10/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.didispace + Chapter3-2-10 + 1.0.0 + jar + + Chapter3-2-10 + Spring Boot project + + + org.springframework.boot + spring-boot-starter-parent + 1.5.9.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-data-ldap + + + + com.unboundid + unboundid-ldapsdk + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.projectlombok + lombok + 1.16.16 + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/Chapter3-2-10/src/main/java/com/didispace/Application.java b/Chapter3-2-10/src/main/java/com/didispace/Application.java new file mode 100644 index 0000000..2a14b75 --- /dev/null +++ b/Chapter3-2-10/src/main/java/com/didispace/Application.java @@ -0,0 +1,13 @@ +package com.didispace; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/Chapter3-2-10/src/main/java/com/didispace/Person.java b/Chapter3-2-10/src/main/java/com/didispace/Person.java new file mode 100644 index 0000000..fbbb8d3 --- /dev/null +++ b/Chapter3-2-10/src/main/java/com/didispace/Person.java @@ -0,0 +1,22 @@ +package com.didispace; + +import lombok.Data; +import org.springframework.ldap.odm.annotations.*; + +import javax.naming.Name; + +@Entry(base = "ou=people,dc=didispace,dc=com", objectClasses = "inetOrgPerson") +@Data +public class Person { + + @Id + private Name id; + @DnAttribute(value = "uid", index = 3) + private String uid; + @Attribute(name = "cn") + private String commonName; + @Attribute(name = "sn") + private String suerName; + private String userPassword; + +} diff --git a/Chapter3-2-10/src/main/java/com/didispace/PersonRepository.java b/Chapter3-2-10/src/main/java/com/didispace/PersonRepository.java new file mode 100644 index 0000000..a02bd2b --- /dev/null +++ b/Chapter3-2-10/src/main/java/com/didispace/PersonRepository.java @@ -0,0 +1,10 @@ +package com.didispace; + +import org.springframework.data.repository.CrudRepository; + +import javax.naming.Name; + +public interface PersonRepository extends CrudRepository { + + +} \ No newline at end of file diff --git a/Chapter3-2-10/src/main/resources/application.properties b/Chapter3-2-10/src/main/resources/application.properties new file mode 100644 index 0000000..4b3fab0 --- /dev/null +++ b/Chapter3-2-10/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#spring.ldap.urls=ldap://localhost:1235 +#spring.ldap.base=dc=didispace,dc=com +#spring.ldap.username=didispace +#spring.ldap.password=123456 \ No newline at end of file diff --git a/Chapter3-2-10/src/test/java/com/didispace/ApplicationTests.java b/Chapter3-2-10/src/test/java/com/didispace/ApplicationTests.java new file mode 100644 index 0000000..dc18877 --- /dev/null +++ b/Chapter3-2-10/src/test/java/com/didispace/ApplicationTests.java @@ -0,0 +1,39 @@ +package com.didispace; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ApplicationTests { + + @Autowired + private PersonRepository personRepository; + + @Test + public void findAll() throws Exception { + + personRepository.findAll().forEach(p -> { + System.out.println(p); + }); + + } + + @Test + public void save() throws Exception { + Person person = new Person(); + person.setUid("uid:1"); + person.setSuerName("AAA"); + person.setCommonName("aaa"); + person.setUserPassword("123456"); + personRepository.save(person); + + personRepository.findAll().forEach(p -> { + System.out.println(p); + }); + } + +} diff --git a/Chapter3-2-10/src/test/resources/application.properties b/Chapter3-2-10/src/test/resources/application.properties new file mode 100644 index 0000000..08bbb56 --- /dev/null +++ b/Chapter3-2-10/src/test/resources/application.properties @@ -0,0 +1,3 @@ +spring.ldap.embedded.ldif=ldap-server.ldif +spring.ldap.embedded.base-dn=dc=didispace,dc=com + diff --git a/Chapter3-2-10/src/test/resources/ldap-server.ldif b/Chapter3-2-10/src/test/resources/ldap-server.ldif new file mode 100644 index 0000000..4eac061 --- /dev/null +++ b/Chapter3-2-10/src/test/resources/ldap-server.ldif @@ -0,0 +1,18 @@ +dn: dc=didispace,dc=com +objectClass: top +objectClass: domain + +dn: ou=people,dc=didispace,dc=com +objectclass: top +objectclass: organizationalUnit +ou: people + +dn: uid=ben,ou=people,dc=didispace,dc=com +objectclass: top +objectclass: person +objectclass: organizationalPerson +objectclass: inetOrgPerson +cn: didi +sn: zhaiyongchao +uid: didi +userPassword: {SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ= diff --git a/README.md b/README.md index cd98d57..0acc6f5 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ - chapter3-2-7:[整合MyBatis](http://blog.didispace.com/springbootmybatis/) - chapter3-2-8:[MyBatis注解配置详解](http://blog.didispace.com/mybatisinfo/) - chapter3-2-9:[使用Flyway来管理数据库版本](http://blog.didispace.com/spring-boot-flyway-db-version/) +- chapter3-2-10:[使用LDAP来统一管理用户信息](http://blog.didispace.com/spring-boot-ldap-user/) #### 事务管理