spring ldap 2.0.1 replacing deprecated OdmManager

帅比萌擦擦* 提交于 2019-12-04 04:43:44

问题


It seems in Spring LDAP 2.x, that the OdmManager facility is deprecated, as most odm-like things can be done by ldapTemplate, which is true. But the OdmManager has the ability to inject a ConverterManager which can be told about your custom type conversions. What is the equivalent method for using ldapTemplate for odm-like (ConverterManager) operations ?

If there is not an equivalent system in ldapTemplate, should it :

  1. implicitly detect custom classes with single string constructors and String toString() class methods, iff they exist as properties to be mapped to/from ldap attributes.

  2. implicitly allow the use of bean editors, to map from text to the specific type

  3. explicitly have some facility like a Converter manager, in which you can configure this.

As an example, consider the simple class (which i would like to be the type of a bean property, which will be mapped to a ldap timestamp)

public class LdapTimestamp {

static private Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Australia/Brisbane"));
static private DateFormat toStringFormat;
static {
    toStringFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    toStringFormat.setCalendar(cal);
}
static private DateFormat nativeLdapFormat = new SimpleDateFormat("yyyyMMddHHmmssZ"); 

private Date dateTime; // GMT time

public LdapTimestamp(String ldapDateTimeString) throws ParseException {
    this.dateTime = nativeLdapFormat.parse(ldapDateTimeString);
}

public LdapTimestamp() {
    super();
}

public Date getDateTime() {
    return dateTime;
}

public void setDateTime(Date dateTimeObject) {
    this.dateTime = dateTimeObject;
}

public void setDateTime(String ldapDateTimeString) throws ParseException {
    this.dateTime = nativeLdapFormat.parse(ldapDateTimeString);
}

public String toStringShort() {
    return toStringFormat.format(dateTime);
}

public String toString() {
    return nativeLdapFormat.format(dateTime);
}

}

The intent is that the bean natively store a Date object, which can be used for date range comparisons and the like, while returning the ldap date string outwards of the bean as toString() and inward to the bean, as constructor with a single String argument.

This seems to be what is suggested with ConverterManager, but this is new code, so i'd rather not use the deprecated OdmManager interface if i can avoid it. ConverterManager is not deprecated, but i can't see an obvious way of linking it to ldapTemplate to use.

Any thoughts would be welcome.


回答1:


LdapTemplate has a setObjectDirectoryMapper method, which enables you to inject a configured ObjectDirectoryMapper (which corresponds to the OdmManager in previous versions). DefaultObjectDirectoryMapper can be configured with a ConverterManager, so I think you should be all set.



来源:https://stackoverflow.com/questions/24666222/spring-ldap-2-0-1-replacing-deprecated-odmmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!