使用spring ldapTemplate,如何删除/取消绑定LDAP条目?

时间:2013-03-27 19:43:37

标签: java spring ldap spring-ldap

如何通过Spring LdapTemplate取消绑定LDAP条目?

我有一个LDAP条目uid = johnsmith @ example.com,objectClass = posixAccount。不确定是否重要,但johnsmith@example.com也是group1的成员。

com  
  |
  +--example (dc=example,objectClass=organization)
       |
       +--groups (ou=groups,objectClass=organizationUnit)
       |    |
       |    +--group1 (cn=group1,objectClass=groupOfNames)
       |    +--group2 (cn=group2,objectClass=groupOfNames)
       |
       +--people (ou=people,objectClass=organizationUnit)
            |
            +--johnsmith@example.com (uid=johnsmith@example.com,objectClass=posixAccount)
            +--janesmith@example.com (uid=janesmith@example.com,objectClass=posixAccount)

到目前为止我尝试了什么:

Name dn = new DistinguishedName();
dn.add("ou", "people");
dn.add("uid", "johnsmith@example.com");

ldapTemplate.unbind(dn);

但是,即使没有抛出异常,也不会删除LDAP条目。

我也试过递归解绑:

Name dn = new DistinguishedName();
dn.add("ou", "people");
dn.add("uid", "johnsmith@example.com");

ldapTemplate.unbind(dn, true);

但是我收到以下错误:

Exception occurred in target VM: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'uid=johnsmith@example.com,ou=people'  org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'uid=johnsmith@example.com,ou=people'
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:174)
at org.springframework.ldap.core.LdapTemplate.deleteRecursively(LdapTemplate.java:1122)
at org.springframework.ldap.core.LdapTemplate$25.executeWithContext(LdapTemplate.java:1083)
at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:807)
at org.springframework.ldap.core.LdapTemplate.executeReadWrite(LdapTemplate.java:802)
at org.springframework.ldap.core.LdapTemplate.doUnbindRecursively(LdapTemplate.java:1081)
at org.springframework.ldap.core.LdapTemplate.unbind(LdapTemplate.java:1044)
(etc....)

修改: 我发现了问题。 uid中有一个拼写错误,这就是unbind没有删除LDAP条目的原因......

0 个答案:

没有答案