Hello Spring Developers,
Especially Spring-ldap developers may be interested in this post: I've
implemented an "Object Directory Mapping" tool (not the one that comes
up when you do a google search) based on ContextMapper &
ContextAssembler that uses annotations on a Directory Entity. For example:
@NamingAttribute("uid")
@NamingSuffix({"ou=people"})
@ObjectClasses({"top", "person", "organizationalPerson", "inetorgperson"})
public class TestPerson
{
/*********************************** Directory mapped fields
************************************/
@DirAttribute("uid")
private String identifier;
@DirAttribute("sn")
private String lastName;
@DirAttribute("givenName")
private String givenName;
@DirAttribute("cn")
private String fullName;
@DirAttribute("mail")
private String emailAddress;
@DirAttribute("userpassword")
private byte[] password;
@DirAttribute("active")
private Boolean isActive;
@DirAttribute("registrationDate")
private Date registrationDate;
@DirAttribute("rating")
private Long rating;
/************************************************************************************************/
The interface for the DAO implementation is as follows:
public interface LdapDao
{
void create(Object dirObject);
void update(Object dirObject);
void delete(Object dirObject);
Object findByNamingAttribute(String namingValue, Class returnType);
public Object findByDn(Name dn, Class returnType);
void createOrUpdate(Object dirObject);
List findAll(Class ofType);
List filterByBeanProperty(String value, String beanPropertyName,
Class returnType);
}
Type translation is based on Spring's own BeanPropertyEditors with
custom editors registered for GeneralizedTime and DistinguishedName.
There is also support for for loading referenced entries. Ie a Role
Object containing a Person[] members field will populated / updated.
public class TestRole
{
/*********************************** Directory mapped fields
************************************/
@DirAttribute("cn")
private String roleName;
@DirAttribute
private String description;
@DirAttribute("roleOccupant")
private TestPerson[] members;
/******************************
}
The whole thing ways in at just 18 small class files, a few hundred
lines of code and it's very fast. I'm not sure if this is useful to more
people than just myself, but if you'd like to know more, let me know.
Best Regards,
Jasper
|