繁体   English   中英

当组 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:错误代码 1 - 000020D6:SvcErr:DSID-031007DB,问题 5012(DIR_ERROR),数据 0]; 剩余名称 'CN=test/group,OU=TestOU,OU=Test,DC=TestDC,DC=test,DC=test'

有人对此有任何线索吗?

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

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

之后它起作用了:

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


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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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