我想在java中删除带有DN的LDAP条目。我有以下代码:
private void deleteUserAssociations(String customer) throws Exception {
DirContext ctx = null;
@SuppressWarnings("rawtypes")
NamingEnumeration results = null;
if (customer != null) {
ctx = new InitialDirContext(env);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
results = ctx.search("", "(customer=" + customer+ ")", controls);
while (results.hasMore()) {
SearchResult searchResult = (SearchResult) results.next();
String NameSpaceToDelete = searchResult.getNameInNamespace();
LdapContext ctxTemp = new InitialLdapContext(env, null);
Control[] tdCtls = new Control[]{new TreeDeleteControl()};
ctxTemp.setRequestControls(tdCtls);
ctxTemp.destroySubcontext(NameSpaceToDelete);
ctxTemp.close();
}
}
}
该方法将客户ID删除,搜索LDAP中的条目并尝试使用Tree Delete Control删除该条目。 Tree Delete Control类如下:
class TreeDeleteControl implements Control
{
public byte[] getEncodedValue() {
return new byte[] {};
}
public String getID() {
return "1.2.840.113556.1.4.805";
}
public boolean isCritical() {
return true;
}
}
问题:代码运行时没有任何错误/异常,但它不会删除任何条目。执行代码后,我可以从LDAP浏览器(JXplorer)中看到所有客户。
请帮忙。