【问题标题】:Apache Directory adding partition programmaticallyApache Directory 以编程方式添加分区
【发布时间】:2014-03-09 21:36:13
【问题描述】:

我正在尝试以编程方式创建分区。我已经尝试按照 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 下看不到任何新的命名上下文)。我想我在这里遗漏了一些步骤,但不确定它们是什么。

【问题讨论】:

  • 我遇到同样的错误?您找到任何解决方案了吗..您是否找到使用代码创建分区的任何方法....请发布解决方案

标签: apache ldap apacheds


【解决方案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();
    }
}

【讨论】:

  • 粘贴已过期,导致此答案无法使用。
  • 该死,粘贴不是我提供的。不幸的是,我无法提供替代方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-10
  • 2018-05-25
  • 1970-01-01
  • 1970-01-01
  • 2012-02-29
  • 2021-08-23
  • 2018-04-10
相关资源
最近更新 更多