該ContextSource
基地旨在指定所有基地ContextSource
上的操作,並且通常設置爲域控制器DN。
您可以在沒有在@Entry
上指定基地(或在樹中使用較高基準DN)的情況下使用ODM,但在這種情況下,您通常會使用@DnAttribute
批註以使框架自動爲您生成DN (主要在將條目保留回LDAP時需要)。
如果我們假設你的用戶的結構如下:
dc=example,dc=com,ou=USERS
dc=example,dc=com,ou=TESTERS
現在,如果你在好的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
}
上面將處理自動映射來自Person類的LDAP條目。現在,如果你想找到所有的人,這樣做:
List<Person> allPersons = ldapTemplate.findAll(Person.class);
如果你想找到所有的測試,你會做:
List<Person> testers = ldapTemplate.find(
query().base("ou=TESTERS"),
Person.class);
下面的一塊接到我的文章編輯了以上。我也想知道是否有一種方法來配置 –
Zak
2014-09-02 22:27:26