当组 DN 名称上有斜线时,无法使用 ldap api 将用户添加到组

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

尽管此代码适用于在区分名称中没有斜杠的组和用户,但当组的 DN 名称中存在斜杠时,我似乎遇到了问题。

        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
                                         }}

我收到以下错误:

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'

有人对此有任何线索吗?

我设法找到了解决办法。看来斜线确实有问题

我没有在 modifyAttributes 中为组 DN 名称插入字符串,而是插入了名称对象。

之后成功了:

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


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