Java LDAP – 将组添加到用户问题 – 错误代码53 – WILL_NOT_PERFORM

我正在尝试将用户添加到Active Directory中。
记住:

  • 使用SSL
  • 证书好
  • 密码工作正常

使用组关联,可以正确创建用户。

当我尝试将用户关联到组时,我收到以下错误:
javax.naming.OperationNotSupportedException:[LDAP:错误代码53 – 0000209A:SvcErr:DSID-031A1021,问题5003(WILL_NOT_PERFORM),数据0

我使用了DN和NAME组属性,但都没有用。 我的代码是:

ctx = getContext(); ctx.createSubcontext(entryDN,entry); // it works fine Attribute memberOf1 = new BasicAttribute("memberOf","NAME_OF_THE_GROUP"); Attributes atts = new BasicAttributes(); atts.put(memberOf1); ctx.modifyAttributes(entryDN, LdapContext.ADD_ATTRIBUTE, atts); // ## it doesn't work 

我尝试了LdapContext.ADD_ATTRIBUTE和LdapContext.REPLACE_ATTRIBUTE。 此外,我尝试添加具有其他属性的组,但所有情况都给了我相同的错误。

有谁知道发生了什么事?

干杯!

memberOf是一个构造的属性。 您必须将用户添加到组的成员属性,而不是将该组添加到用户的memberOf属性。

解决方案代码是:

 BasicAttribute member = new BasicAttribute("member",entryDN); Attributes atts = new BasicAttributes(); atts.put(member); ctx.modifyAttributes("GROUP_DN", LdapContext.ADD_ATTRIBUTE, atts); 

谢谢Hall72215。

尝试使用它,它适合我

 ModificationItem[] mods = new ModificationItem[1]; String userDn="cn=user name,CN=Users,DC=domain,DC=com" String groupDn="cn=Group Name,CN=Groups,DC=domain,DC=com" Attribute mod =new BasicAttribute("member",userDn); mods[0] =new ModificationItem(DirContext.ADD_ATTRIBUTE, mod); ldapContext.modifyAttributes(groupDn, mods);