I'm migrating our LDAP client application that manages our OpenLDAP objects. This application is written in Java and currently use spring ldap 1.3. I'm currently (70%) in the process of migrating to spring ldap 2.0.2 and I'm quite happy with this new version.
I've created our objects and used annotations (@Entry ...) and it works.
Now here is my problem :
- My users are in ou=people,dc=mycompany,dc=com
- The user belongs to an unit
- base name for units is ou=units,dc=mycompany,dc=com
- Units are hierarchically embedded : ou=a,ou=b,ou=units or ou=e,ou=b,ou=units
Here is my code:
@Entry(objectClasses={"organizationalUnit", "top"}, base="ou=units")
public class Unit {
@Id
private Name dn;
@Attribute(name="ou")
@DnAttribute(value="ou", index=1)
private String rdn;
}
But this code only works for first level units ! I've found the following question and @marthursson suggests to write its own ObjectDirectoryMapper. Is this the only solution ?
Edit 1 : You mean, like :
@Entry(objectClasses={"organizationalUnit", "top"}, base="ou=units")
public class Unit {
@Id
private Name dn;
@Attribute(name="ou")
@DnAttribute(value="ou", index=1)
private String rdn;
@Attribute(name="ou")
@DnAttribute(value="ou", index=2)
private String lvl2;
@Attribute(name="ou")
@DnAttribute(value="ou", index=3)
private String lvl3;
@Attribute(name="ou")
@DnAttribute(value="ou", index=4)
private String lvl4;
}
I get one IndexOutofBoundException if there is no value to put at index 2. Typically when I'm loading the root unit under ou=units.
Edit 2 : The following function does the job :
public String getRdn() {
LdapName n = LdapNameBuilder.newInstance(dn.getSuffix(dn.size()-1)).build();
return n.getRdn(0).getValue().toString();
}