Skip to content

Operational Attributes support should not require read-only attributes #446

Closed
@krzysztofmarzec3

Description

@krzysztofmarzec3

I have an object with operational attribute nsAccountLock that allow to lock account in LDAP.

@Entry
public class User {
   //other attributes definition
    @Attribute(name = "nsAccountLock")
    private boolean nsAccountLock;
...
}

In my business layer i have changed the attribute to different value. Then I call method update(Object entry) from LdapTemplate. Method throw org.springframework.ldap.AttributeInUseException: [LDAP: error code 20 - Attribute Or Value Exists];

From my perspective the problem is with method
_DirContextOperations context = lookupContext(id);_
because the return context don't have fetched operational attributes in originalAttr. Operational attributes will be returned from LDAP if you directly request for them.
This cause that modifyAttributes(context) will try to add once again "nsAccountLock" attribute but it is not possible beacuse such attribue exist and ldap throw exception.

In my opinion the code in update method should look like

DirContextAdapter context = lookup(id, entry.getClass());
context.setUpdateMode(true);
odm.mapToLdapDataEntry(entry, context);
modifyAttributes(context);

and the lookup method should look like:

    private DirContextAdapter lookup(final Name dn, final Class<?> clazz) {
        ObjectDirectoryMapper odm = getObjectDirectoryMapper();
        final String[] attributes = odm.manageClass(clazz);

        return executeReadOnly(new ContextExecutor<DirContextAdapter>() {
            public DirContextAdapter executeWithContext(DirContext ctx) throws NamingException {
                Attributes filteredAttributes = ctx.getAttributes(dn, attributes);
                DirContextAdapter contextAdapter = new DirContextAdapter(filteredAttributes, dn);
                return contextAdapter;
            }
        });
    }

to fetch all attributes mapped in ODM object.

Please fix this bug.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions