Spring Ldap - 多个基本名称

标签 spring spring-ldap

我正在尝试使用 spring LDAP/ODM 从 LDAP 接收一些属性。有没有办法在中配置多个基本名称

 <ldap:context-source
          url="${ldap.url}"
          base="${ldap.base}" // here ..is there a prop that will take an array of base names
          username="${userdn}"
          password="${password}" />

<ldap:ldap-template id="ldapTemplate" />  

或在

@Entry(objectClasses = { "person"} base={..CAN I GIVE MULTIPLE BASENames here..})
public class LdapUser {

    @Id
    private Name dn;

    //..
}

我正在开发的应用程序在一个 OU 下定义了用户,并在 AD 的另一个 OU 中定义了内部测试人员。所以我想看看是否可以使用相同的 LDAP 条目类来查找每个人。

最佳答案

ContextSource 基点旨在指定 ContextSource所有操作的基点,通常设置为域 Controller DN。

您可以在不指定 @Entry 上的基础(或使用树中较高的基础 DN)的情况下使用 ODM,但在这种情况下,您通常会使用 @DnAttribute 注释,以便框架自动为您构建 DN(主要在将条目保留回 LDAP 时需要)。

如果我们假设您的用户具有以下结构:

dc=example,dc=com,ou=USERS

dc=example,dc=com,ou=测试者

现在,如果您在 ContextSource 上指定基本 dc=example,dc=com,您可以让 ODM 自动处理此问题,如下简要描述:

@Entry(objectclasses={"person"})
public class Person {
  @Id
  private Name dn;

  @DnAttribute(name="ou", index=0)
  @Transient // Indicates that this is not an attribute on the entry
  private String userType;

  @Attribute(name="cn")
  private String name;

  // More attributes here
}

上面将处理 LDAP 条目与 Person 类之间的自动映射。现在,如果您想找到所有人,请执行以下操作:

List<Person> allPersons = ldapTemplate.findAll(Person.class);

如果您想找到所有测试人员,您会这样做:

List<Person> testers = ldapTemplate.find(
                            query().base("ou=TESTERS"), 
                            Person.class);

关于Spring Ldap - 多个基本名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25633364/

相关文章:

java - @Async和任务:annotation-driven don't work

grails - 在 Grails 服务中注入(inject) LdapTemplate 以返回用户详细信息会导致空指针异常

java - 我无法使用 ip addr 连接 ldap 服务器

java - 从 JSP 获取日期到 Controller (在 Spring Mvc 中)

java - @ControllerAdvice 异常处理程序方法未被调用

java - Spring+Hibernate调试 "Injection of autowired dependencies failed"错误

java - 在 Servlet 中构建 HTML 添加额外的引号

java - Spring Security Active Directory LDAP 身份验证没有全名

java - AD 将whenCreated 属性转换为Date

spring - 如何在Spring LDAP中添加LDAP缓存?