我有以下目录结构,并且正在使用带有 Spring LDAP (v 2.3.1.RELEASE) 的 ODM。
以下是我正在处理的目录结构。
dc=example,dc=com
dc=studentBase,dc=example,dc=com
我在 config.xml 中声明了 ldap 上下文源的基础,如下所示:
<ldap:context-source
id="ldapContextSource"
url="ldap://ldaphost:389"
username="cn=ldaptestadmin,cn=Administrators,cn=config"
password="abcxyz"
base="dc=studentBase,dc=example,dc=com"/>
<ldap:ldap-template id="ldapTemplate" context-source-
ref="ldapContextSource"/>
为了解释问题的背景,以下是详细信息:
我在 studentBase 下有两个组织单位如下:
ou=groups,dc=studentBase,dc=example,dc=com
ou=people,dc=studentBase,dc=example,dc=com
ou=people
内的每个条目如下:objectclass: inetorgperson (structural)
objectclass: organizationalPerson (structural)
objectclass: person (structural)
objectclass: top (abstract)
cn: Test Name
sn: Test
givenName: TestName
uid: test1234
userPassword: <SSHA hashed password>
我创建了一个用@Entry 注释的 bean,如下所示:
@Entry(objectClasses = {"inetOrgPerson", "organizationalPerson", "person", "top" }, base = "ou=people")
public class Student {
@Id
private Name dn;
...
...
...
}
现在,当我尝试在 LDAP 中创建学生条目时,如下所示
Student objStudent = new Student();
String dn = "uid=testUserName";
Name dnName = new LdapName(dn);
objStudent.setDn(dnName);
ldapTemplate.create(objStudent);
它不是在 下创建的ou=人 而是在 config.xml 中提到的基础 dn 中创建,即 ( dc=studentBase,dc=example,dc=com )。
每 Entry javadocs ,它表示 底座 属性如下:
此条目的基本 DN。如果指定,这将被添加到所有为注释类的条目计算的可分辨名称之前。
这不是意味着它应该为学生的@Id 字段添加 ou=people 吗?
但是,在上面的代码中,如果我为 dn 属性显式设置了 ou=person,它将在 ou=person 下创建,无论我在 @Entry 中是否具有 base 属性。
String dn = "uid=testUserName,ou=person";
Name dnName = new LdapName(dn);
我不是在正确的角度使用@Entry 注释的“base”属性吗?
或者有人可以解释这里出了什么问题?
还是与@DnAttribute 一起使用?
谢谢。
最佳答案
我见过同样的问题。但是,我建议这个答案:
https://stackoverflow.com/a/25658026/6157415
“@Entry base="参数由 使用LdapRepository 不是通过 LdapTemplate。
关于Spring LDAP + @Entry + 基本属性 - 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43792804/