简体   繁体   中英

Unable to add user to group with ldap api when there is a slash on group DN Name

Although this code functions well with groups and users that do not have a slash in their Distringuished name, it appears that i have a problem when a slash exists in the DN name of the group.

        String groupDNName =
            "CN=test/group,OU=TestOU,OU=Test,DC=TestDC,DC=test,DC=test";
        Set<String> usersToAddDN = new HashSet();

        usersToAddDN.add("CN=testUser,OU=TestOU,OU=TestO,DC=TestDC,DC=test,DC=test");


        //Add Users
        if (usersToAddDN != null && !usersToAddDN.isEmpty()) {

            for (String userDistinguishedName :
                 usersToAddDN) { //Add to  group


                    ModificationItem[] mods = new ModificationItem[1];
                    mods[0] =
                            new ModificationItem(DirContext.ADD_ATTRIBUTE,
                                                 new BasicAttribute("member",
                                                                    userDistinguishedName));


                    ctx.modifyAttributes(groupDNName,
                                         mods); //Add user to group
                                         }}

I get the following error:

javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-031007DB, problem 5012 (DIR_ERROR), data 0 ]; remaining name 'CN=test/group,OU=TestOU,OU=Test,DC=TestDC,DC=test,DC=test'

Does anyone have any clues on this?

I managed to find a work out for this. It seems that there was indeed a problem with the slash.

Instead of inserting a String for the group DN name in the modifyAttributes, I inserted a Name object.

It worked after that:

 Name name = new CompositeName().add(groupDNName);


                ctx.modifyAttributes(name,
                                     mods); //Add user to group 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM