1

我正在尝试以编程方式创建分区。我已经尝试按照 ApacheDS 网站上的示例(https://directory.apache.org/apacheds/basic-ug/1.4.3-adding-partition.html#adding-a-partition-programmatically),但是这个例子绝对是不正确的。

这是我的代码:

LdapConnection connection = new LdapNetworkConnection(host, port);     
connection.bind(admin, password);

connection.loadSchema();
SchemaManager schemaManager = connection.getSchemaManager();
Dn suffixDn = new Dn(schemaManager, "dc=newParition,dc=com");

JdbmPartition newPartition = new JdbmPartition(schemaManager);
newPartition.setId("newParition");
newPartition.setSuffixDn(suffixDn);
newPartition.setCacheSize(1000);
newPartition.setPartitionPath(new URI("file:///var/lib/apacheds-2.0.0-M15/default/partitions/newParition"));

newPartition.addIndex(new JdbmIndex("objectClass", false));
newPartition.addIndex(new JdbmIndex("dc", false));

Entry contextEntry = new DefaultEntry(schemaManager, suffixDn);
contextEntry.put("objectClass", "domain", "top");
contextEntry.put("dc", "newParition");

newPartition.initialize();
newPartition.add(new AddOperationContext(null, contextEntry)); 

当我尝试将 contextEntry 添加到分区时看到以下错误:

org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException: ERR_219 Entry dc=newParition,dc=com contains no entryCsn attribute: Entry …

甚至看起来分区都没有添加到我的服务器中(当我重新启动我的 apacheds 服务器时,我在根 DSE 下看不到任何新的命名上下文)。我想我在这里遗漏了一些步骤,但不确定它们是什么。

4

1 回答 1

-1

来自 Apache DS 开发者邮件列表的建议:

"// 总是使用 CoreSession 的 API 添加一个条目"。查看http://apaste.info/KHX以获得几乎完整的如何添加分区的示例。缺少的类 EmbeddedServer 如下:

 private static final class EmbeddedServer {
    private DirectoryService directoryService;
    private LdapServer ldapService;

    public EmbeddedServer(final String host, final int port) throws Exception {
        init(host, port);
    }

    private void init(final String host, final int port) throws Exception {

        DefaultDirectoryServiceFactory factory = new DefaultDirectoryServiceFactory();
        factory.init("Test");
        this.directoryService = factory.getDirectoryService();
        this.directoryService.getChangeLog().setEnabled(false);
        this.directoryService.setShutdownHookEnabled(true);
        this.directoryService.setInstanceLayout(new InstanceLayout("/tmp/ldapServer"));

        this.ldapService = new LdapServer();
        this.ldapService.setTransports(new TcpTransport(host, port));
        this.ldapService.setDirectoryService(this.directoryService);
    }

    public void start() throws Exception {

        this.directoryService.startup();
        this.ldapService.start();
    }

    public void stop() throws Exception {

        this.ldapService.stop();
        this.directoryService.shutdown();
    }
}
于 2014-09-29T14:31:08.197 回答