Search code examples
javaspringspring-bootldapldap-query

[LDAP: error code 32 - 0000208D: NameErr: DSID-03100241, problem 2001 (NO_OBJECT), data 0, best match of:


I am trying to add a user to an Active directory group using Spring Boot with the following code.

public boolean addMemberToGroup(String groupName, Person p) {
    boolean status = false;
    Name groupDn = buildGroupDn(groupName);
    Name personDn = buildPersonDn(p);

    try {
        DirContextOperations ctx = ldapTemplate.lookupContext(groupDn);
        ctx.addAttributeValue(UNIQUE_MEMBER, personDn);
        ldapTemplate.modifyAttributes(ctx);
               
    } catch (Exception e) {
        logException
    }
    return status;
}

private Name buildGroupDn(String groupName) {
    return LdapNameBuilder.newInstance(baseLdapPath)
            .add("OU", "ghtc")
            .add("OU", "IT")
            .add("OU", "Groups")           
                    
            .add("CN", groupName)
            .build();
}

baseLdapPath = DC=emea,DC=testdir,DC=net and this is added in the application.properties file.

But when ldapTemplate.lookupContext(groupDn); executes, following exception occurs:

nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100241, problem 2001 (NO_OBJECT), data 0, best match of: 'DC=emea,DC=testdir,DC=net' remaining name 'CN=GroupAMC,OU=Groups,OU=IT,OU=ghtc,DC=emea,DC=testdir,DC=net'*

I have verified that the distinguished name of the group is CN=GroupAMC,OU=Groups,OU=IT,OU=ghtc,DC=emea,DC=testdir,DC=net

What am I missing here?


Solution

  • I was able to resolve the error using the below link Ldap error code 32 while adding user to ldap

    The issue was with the baseDn while building groupName. Removing the baseLdapPath fixed the issue

    private Name buildGroupDn(String groupName) {
            return LdapNameBuilder.newInstance()
                    .add("OU", "ghtc")
                    .add("OU", "IT")
                    .add("OU", "Groups")           
                    
                    .add("CN", groupName)
                    .build();
        }