LDAP整个子树副本

时间:2020-03-06 14:54:57  来源:igfitidea点击:

我实际上是这个论坛的新手,我持续尝试了几天,以找到一种将整个LDAP子树复制到另一棵树的简便方法。由于我找不到任何有用的信息,因此我也考虑在此处提出一个问题。有人知道如何以编程方式执行此操作吗?

对于诸如添加,删除,搜索之类的常规操作,我一直在使用Spring LDAP。

非常感谢 !

解决方案

我实际上并不了解Spring LDAP,但是如果LDAP接口没有为移动/重新命名或者复制整个子树提供任何高级抽象,则必须递归移动/重命名或者复制所有子树节点。 LDAP API不直接提供这样的选项。

以下是伪代码:

function copySubtree(oldDn, newDn)
{
    copyNode(oldDn, newDn); // the new node will be created here
    if (nodeHasChildren(oldDn) { 
        foreach (nodeGetChildren(oldDn) as childDn) {
            childRdn=getRdn(childDn); // we have to get the 'local' part, the so called RDN 
            newChildDn=childRdn + ',' + newDn; // the new DN will be the old RDN concatenated with the new parent's DN
            copySubtree(childDn, newChildDn); // call this function recursively
        }  
    }
}

请注意,密码很难复制。我们可能无法通过LDAP API读取它们。这将取决于我们使用它的LDAP实现。

因此,复制到新位置可能无法获得我们想要或者需要的一切。

将其作为LDIF转储,通过搜索和替换(或者通过脚本)编辑DN,然后导入新的LDIF。

Spring可能不是执行此操作的工具。是否有必要使用Spring操作目录?我认为OpenLDAP的ldapsearch和ldapadd应该可以在任何服务器上使用,并且它们将转储/装入LDIF。