2

如何通过 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 条目的原因...

4

0 回答 0