【问题标题】:Spring LDAP Error Changing Distinguished NameSpring LDAP 错误更改可分辨名称
【发布时间】:2017-01-27 14:39:43
【问题描述】:

我找不到正确的方法来使用 Spring LDAP 在组织单位之间移动 Active Directory 中的人员。

我正在使用 Spring LDAP 2.0.4.RELEASE。我尝试了四种不同的方法来在我要移动的人员对象上设置distinguishedName,但每种方法都会出现 LDAP 错误。

1)distinguishedName 设置为String,包括dc 部分。

final Name currentDn = LdapNameBuilder.newInstance("CN=Some Person,OU=Old,OU=Domain Users").build();
final String newDn = "CN=Some Person,OU=New,OU=Domain Users,dc=my,dc=domain";

final Attribute attributeChange = new BasicAttribute("distinguishedName", newDn);
final ModificationItem modificationItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attributeChange);
ldapTemplate.modifyAttributes(currentDn, new ModificationItem[]{modificationItem});

这给了我以下错误:

javax.naming.directory.InvalidAttributeValueException:[LDAP:错误代码 19 - 000020B1:AtrErr:DSID-030F052C,#1: 0: 000020B1: DSID-030F052C, 问题 1005 (CONSTRAINT_ATT_TYPE), 数据 0, Att 31 (distinguishedName) ];剩余名称 'CN=Some Person,OU=Old,OU=Domain Users'

2)distinguishedName 设置为String没有 dc 部分。

final Name currentDn = LdapNameBuilder.newInstance("CN=Some Person,OU=Old,OU=Domain Users").build();
//the line below is the only line changed from (1)
final String newDn = "CN=Some Person,OU=New,OU=Domain Users"; 

final Attribute attributeChange = new BasicAttribute("distinguishedName", newDn);
final ModificationItem modificationItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attributeChange);
ldapTemplate.modifyAttributes(currentDn, new ModificationItem[]{modificationItem});

这给了我一个不同的错误:

org.springframework.ldap.UncategorizedLdapException:LDAP处理期间发生未分类异常;嵌套异常是 javax.naming.NamingException:[LDAP:错误代码 80 - 00002089:UpdErr:DSID-031B0D38,问题 5012 (DIR_ERROR),数据 5 ];剩余名称 'CN=Some Person,OU=Old,OU=Domain Users'

3)distinguishedName 设置为LdapName,包括dc 部分。

final Name currentDn = LdapNameBuilder.newInstance("CN=Some Person,OU=Old,OU=Domain Users").build();
final Name newDn = LdapNameBuilder.newInstance("CN=Some Person,OU=New,OU=Domain Users,dc=my,dc=domain").build();

final Attribute attributeChange = new BasicAttribute("distinguishedName", newDn);
final ModificationItem modificationItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attributeChange);
ldapTemplate.modifyAttributes(currentDn, new ModificationItem[]{modificationItem});

这给了我与 (1) 相同的错误。

4)distinguishedName 设置为LdapName没有dc 部分。

final Name currentDn = LdapNameBuilder.newInstance("CN=Some Person,OU=Old,OU=Domain Users").build();
final Name newDn = LdapNameBuilder.newInstance("CN=Some Person,OU=New,OU=Domain Users").build();

final Attribute attributeChange = new BasicAttribute("distinguishedName", newDn);
final ModificationItem modificationItem = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attributeChange);
ldapTemplate.modifyAttributes(currentDn, new ModificationItem[]{modificationItem});

这也给了我与 (1) 相同的错误。

我错过了什么?这不是使用 Spring LDAP 更改 Active Directory 人员对象上的distinguishedName 的正确方法吗?错误消息一点帮助都没有。

【问题讨论】:

    标签: java active-directory ldap spring-ldap


    【解决方案1】:

    显然,您不能通过修改操作更改distinguishedName 属性。使用 Spring LDAP 执行此操作的正确方法是使用 LdapTemplate.rename 方法。您可以将oldDnnewDn 作为String 对象或Name 对象传入。

    final Name oldDn = LdapNameBuilder.newInstance("CN=Some Person,OU=Old,OU=Domain Users").build();
    final Name newDn = LdapNameBuilder.newInstance("CN=Some Person,OU=New,OU=Domain Users").build();
    
    ldapTemplate.rename(oldDn, newDn);
    

    【讨论】:

    • 这是因为 DN 不是属性。相关的 LDAP 操作/请求是 MODRDN 而不是普通的 MODIFY
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 2014-10-27
    • 2011-01-03
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    相关资源
    最近更新 更多