我正在尝试使用 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/