4

I have the following directory structure and am using ODM with Spring LDAP (v 2.3.1.RELEASE).

The below is the directory structure am dealing with.

dc=example,dc=com
dc=studentBase,dc=example,dc=com

I declared the base for the ldap context source in the config.xml as follows:

<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"/>

To explain the context of the problem, here are the details: I have two organizational units under studentBase as follows:

ou=groups,dc=studentBase,dc=example,dc=com
ou=people,dc=studentBase,dc=example,dc=com

Each entry inside the ou=people is as follows:

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>

I created a bean annotated with @Entry as follows:

@Entry(objectClasses = {"inetOrgPerson", "organizationalPerson", "person", "top" }, base = "ou=people")
public class Student {
    @Id
    private Name dn; 
    ...
    ...
    ...
}

Now when I try create the student entry inside the LDAP like below

Student objStudent = new Student();
String dn = "uid=testUserName";
Name dnName = new LdapName(dn);
objStudent.setDn(dnName);
ldapTemplate.create(objStudent);

it is not getting created under the ou=people but instead getting created in the base dn which is (dc=studentBase,dc=example,dc=com) as mentioned in the config.xml.

Per Entry javadocs, it says for the base attribute as follows : The base DN of this entry. If specified, this will be prepended to all calculated distinguished names for entries of the annotated class.

Doesn't it mean it should prepend ou=people for the @Id field of the Student??

However, in the above code, if I explicitly set the ou=person for the dn attribute, it is getting created under ou=person, no matter if I have the base attribute in @Entry or not.

String dn = "uid=testUserName,ou=person";
Name dnName = new LdapName(dn);

Am I not using the "base" attribute of @Entry annotation in the right perspective?

Or can someone explain what am getting wrong here?

Or is this used along with @DnAttribute?

Thanks.

Uresh K
  • 1,136
  • 11
  • 16
  • I bet you need to check setDn() to see if it overwrites base. – wannadream May 04 '17 at 21:15
  • I have this for the setDn in the Student class: public void setDn(Name dn) { this.dn = dn; } – Uresh K May 04 '17 at 21:17
  • Checked the source code but did not find a clue. In its source, getDn() does not have special treatment for 'base' though. – wannadream May 04 '17 at 23:48
  • Check getCalculatedId(Object entry) in https://github.com/spring-projects/spring-ldap/blob/4d593dcf85deffb7d20166f41a0743be5ed4750b/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java – wannadream May 05 '17 at 00:06

1 Answers1

0

I have seen the same issue. However, I suggest this answer : https://stackoverflow.com/a/25658026/6157415

The "@Entry base=" parameter is used by LdapRepository not by LdapTemplate.

Uresh K
  • 1,136
  • 11
  • 16
Mike D3ViD Tyson
  • 1,701
  • 1
  • 21
  • 31