Announcement Announcement Module
Collapse
No announcement yet.
LDAPTemplate: modifyattributes throws invalidattributevalueexception on postalAddress Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LDAPTemplate: modifyattributes throws invalidattributevalueexception on postalAddress

    Hey,

    Using Spring-ldap-core:1.3.0-RELEASE as version..

    In order to CRUD an Ldap entry I'm using LdapTemplate with DirContextAdapter. Everything works except doing an update operation (U ^^ )

    The LDAP entry is a User with a bunch of attributes. The add method looks like this and works fine:

    Code:
    public void add(User user) {
            DistinguishedName dn = (DistinguishedName) createDN(user);
            DirContextAdapter context = new DirContextAdapter(dn);
            mapUserToContext(user,context);
    
    
            context.setAttributeValues("objectClass",new String[]{
                    "top","person","organizationalPerson","inetorgperson","inetuser"
            });
    
    
            getLdapTemplate().bind(dn,context,null);
        }
    Then the update method. This throws:
    javax.naming.directory.InvalidAttributeValueExcept ion: 'postalAddress' has no values.; remaining name .....

    This is weird because it's true that postalAddress is null when I update it, but it's also null when I use the add method. There it doesn't throw an exception.

    Code:
        public void update(User user) {
            DistinguishedName dn = (DistinguishedName) createDN(user);
            DirContextAdapter context = (DirContextAdapter) getLdapTemplate().lookup(dn);
    
            context.setAttributeValues("objectClass",new String[]{
                    "top","person","organizationalPerson","inetorgperson","inetuser"
            });
    
            mapUserToContext(user,context);
            getLdapTemplate().modifyAttributes(dn,context.getModificationItems());
        }

    Thanks in advance

  • #2
    Right.. So it was my own fault.

    I made a typo / copy-paste error, namely:

    setAttribute() to addAttribute. I was hardly noticeable as it was the only one in the bunch. Obviously on the postalAddress attribute. Logically in order to "add" an attribute it's got to have a value or it's pointless.

    At least thanks for reading

    Comment

    Working...
    X