Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Malformed 'member' attribute value

I m creating an application that has to connect to an active directory.

I m actually facing a problem when dealing with updating a group member.

The group name is : GG-Collaboration-AgenceXXX

Here's my GroupRepository class code that throws the exception :

 public void addMemberToGroup(String groupName, User user) {
        Name groupDn = this.buildGroupDn(groupName);
        Name userDn = this.buildPersonDn(user.getFirstName() + " " + user.getLastName(), user.getCompany(), user.getCountry().toString());
        DirContextOperations ctx = this.ldapTemplate.lookupContext(groupDn);
        ctx.addAttributeValue("member", userDn);
        System.out.println(userDn);
        this.ldapTemplate.modifyAttributes(ctx);
    }

 private Name buildGroupDn(String groupName) {
        return LdapNameBuilder.newInstance("CN=" + groupName).build();
    }

    private Name buildPersonDn(String fullname, String company, String country) {
        return LdapNameBuilder.newInstance("DC=test,DC=lan").add("OU", "Utilisateurs").add("CN", fullname).build();
    }

Here's my fullstack error :

Malformed 'member' attribute value; nested exception is javax.naming.directory.InvalidAttributeValueException: Malformed 'member' attribute value; remaining name 'CN=GG-Collaboration-AgenceXXX'
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:132)
Caused by: javax.naming.directory.InvalidAttributeValueException: Malformed 'member' attribute value
    at com.sun.jndi.ldap.LdapClient.encodeAttribute(LdapClient.java:984)
like image 303
Thomas thomas Avatar asked Mar 14 '23 08:03

Thomas thomas


1 Answers

The "member" attribute only allows strings as value and not LDAPName objects. So convert your userDn to a string before putting it into the attribute.

like image 198
Jim Holden Avatar answered Mar 23 '23 01:03

Jim Holden