Java JNDI 删除整个 LDAP 子树
我需要通过Java代码删除整个LDAP子树,就像ldapdelete命令的-r参数一样。我怎样才能做到这一点? 有没有一种简单的方法可以使用 JNDI 删除整个 LDAP 子树?
I need to delete entire LDAP subtree, by Java code, like the -r parameter of ldapdelete command. How can I do that?
Is there a simple way to delete entire LDAP subtree with JNDI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,删除 LDAP 中的整个子树只是在测试中执行的操作...
无论如何,spring-Ldap 测试实用程序中有一个名为 LdaptestUtils 的实用程序类,它可以满足您的需求。我不会在这里复制代码。看看 http://www.jarvana.com/jarvana/view/org/springframework/ldap/spring-ldap/ 1.3.0.RELEASE/spring-ldap-1.3.0.RELEASE-sources.jar!/org/springframework/ldap/test/LdapTestUtils.java?format=ok
相关方法名称为clearSubContexts()(注超载)。
Usually deleting entire subtrees in LDAP is something you do only in tests...
Anyway,there's a utility class in spring-Ldap test utils called LdaptestUtils that does just what you want. I won't copy the code here. Take a look at http://www.jarvana.com/jarvana/view/org/springframework/ldap/spring-ldap/1.3.0.RELEASE/spring-ldap-1.3.0.RELEASE-sources.jar!/org/springframework/ldap/test/LdapTestUtils.java?format=ok
The relevant method name is clearSubContexts() (note the overloading).
如果您的服务器支持,您需要使用 javax.naming.ldap.TreeDelete 控件,否则您别无选择,只能深度优先地手动执行。
You need to use the
javax.naming.ldap.TreeDelete
control, if your server supports it, otherwise you have no choice but to do it by hand, depth-first.