使用LDAP来统一管理用户信息

This commit is contained in:
zhaiyongchao
2018-01-27 14:55:30 +08:00
parent effa9b6693
commit f356489f3b
9 changed files with 176 additions and 0 deletions
@@ -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);
}
}
@@ -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;
}
@@ -0,0 +1,10 @@
package com.didispace;
import org.springframework.data.repository.CrudRepository;
import javax.naming.Name;
public interface PersonRepository extends CrudRepository<Person, Name> {
}
@@ -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
@@ -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);
});
}
}
@@ -0,0 +1,3 @@
spring.ldap.embedded.ldif=ldap-server.ldif
spring.ldap.embedded.base-dn=dc=didispace,dc=com
@@ -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=