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



尽管此代码适用于名称中没有斜杠的组和用户,但当组的 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.命名异常: [LDAP: 错误代码 1 - 000020D6: SvcErr: DSID-031007DB,问题 5012 (DIR_ERROR(,数据 0 ];剩余 名称 'CN=测试/组,OU=TestOU,OU=测试,DC=TestDC,DC=test,DC=test'

有人对此有任何线索吗?

我设法找到了解决这个问题的方法。看来斜杠确实有问题。

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

之后它起作用了:

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

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

最新更新