rwinch / spring-security-jira-to-gh

0 stars 0 forks source link

LDAP-271: ODM: nullable attributes are not removed from LDAP if OdmManagerImpl#update(Object) is used #250

Closed rwinch closed 11 years ago

rwinch commented 11 years ago

Migrated from LDAP-271

Hi. I've faced with a problem using ODM.

Preconditions: a. There is an attributetype in ldap schema - e.g. 'someAttribute'. b. The type is mentioned in the MAY list of an objectClass - e.g. 'someClass'. c. There is an ODM entry class mapped to the objectClass.

Steps to reproduce:

  1. Create an entry and fill it in including a value for 'someAttribute'.
  2. Save it - odmManager.create(entry); Result: the entry is in DIT, 'someAttribute' exists and filled.
  3. Update the entry: set null as a new value for 'someAttribute' property.
  4. Save it - odmManager.update(entry);

Actual Result: the entry is in DIT, 'someAttribute' exists and its value the same as in p.2.

Expected Result: the entry is in DIT but without 'someAttribute'.

Note: I've looked through OdmManagerImpl source code and found out that before actual update is executed the method OdmManagerImpl#mapToContext(Object,DirContextOperations) is invoked. The method converts Java representation of an Ldap Entry. During the conversion only non-nullable properties of an entry are considered, null field values are ignored at all: if (!attributeInfo.isList()) { // Single valued - get the value of the field Object fieldValue = field.get(entry); // Ignore null field values if (fieldValue != null) { // Convert the field value to the required type and write it into the JNDI context context.setAttributeValue(attributeInfo.getName().toString(), converterManager.convert(fieldValue, attributeInfo.getSyntax(), targetClass)); } }

Many Thanks, Vadzim

rwinch commented 11 years ago

Mattias Hellborg Arthursson said:

This looks like something we should look into for the 2.0 release.