有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    也可以通过LdapTemplate实现。LdapParser将以LdapAttribute的形式解析ldif文件中的记录,然后通过ldapTemplate绑定该记录。束缚

    LdapContextSource contextSource = new LdapContextSource();
    
            contextSource.setUrl("ldap://192.168.99.101:389/");
            contextSource.setUserDn("uid=admin,dc=abc,dc=com");
            contextSource.setPassword(********);
            contextSource.setPooled(false);
            contextSource.afterPropertiesSet();
    
            LdapTemplate template = new LdapTemplate(contextSource);
            LdifParser parser = new LdifParser(new ClassPathResource("schema.ldif"));
            parser.open();
            while (parser.hasMoreRecords()) {
                LdapAttributes record = parser.getRecord();
                LdapName dn = record.getName();
                template.bind(dn, null, record);
            }
    
  2. # 2 楼答案

    您需要使用一个单独的库,该库具有支持LDIF导入的API。一旦这样的库被Apache Directory LDAP API。该库通常与大多数LDAP服务器兼容

    参考documentation,LdifFileLoader类具有导入LDIF的功能,与DefaultDirectoryService类一起(不幸的是,我找不到演示LDIF导入的早期代码)。您可以参考this post,它展示了如何使用上述方法,尽管它处理的是不同类型的问题

    我不确定您正在使用的LDAP服务器,但是,您可以尝试并检查上面的内容