java - 运行嵌入在我的应用程序中的 Apache DS

标签 java apache ldap apacheds

我正在尝试在我的应用程序中运行嵌入式 ApacheDS。看完http://directory.apache.org/apacheds/1.5/41-embedding-apacheds-into-an-application.html我构建这个:

public void startDirectoryService() throws Exception {
    service = new DefaultDirectoryService();
    service.getChangeLog().setEnabled( false );

    Partition apachePartition = addPartition("apache", "dc=apache,dc=org");
    addIndex(apachePartition, "objectClass", "ou", "uid");

    service.startup();

    // Inject the apache root entry if it does not already exist
    try
    {
        service.getAdminSession().lookup( apachePartition.getSuffixDn() );
    }
    catch ( LdapNameNotFoundException lnnfe )
    {
        LdapDN dnApache = new LdapDN( "dc=Apache,dc=Org" );
        ServerEntry entryApache = service.newEntry( dnApache );
        entryApache.add( "objectClass", "top", "domain", "extensibleObject" );
        entryApache.add( "dc", "Apache" );
        service.getAdminSession().add( entryApache );
    }
}

但是运行后无法连接到服务器。默认端口是什么?还是我遗漏了什么?

解决方法如下:

    service = new DefaultDirectoryService();
    service.getChangeLog().setEnabled( false );

    Partition apachePartition = addPartition("apache", "dc=apache,dc=org");

    LdapServer ldapService = new LdapServer();
    ldapService.setTransports(new TcpTransport(389));
    ldapService.setDirectoryService(service);

    service.startup();
    ldapService.start();

最佳答案

这是我们如何使用它的简化版本:

File workingDirectory = ...;

Partition partition = new JdbmPartition();
partition.setId(...);
partition.setSuffix(...);

DirectoryService directoryService = new DefaultDirectoryService();
directoryService.setWorkingDirectory(workingDirectory);
directoryService.addPartition(partition);

LdapService ldapService = new LdapService();
ldapService.setSocketAcceptor(new SocketAcceptor(null));
ldapService.setIpPort(...);
ldapService.setDirectoryService(directoryService);

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

关于java - 运行嵌入在我的应用程序中的 Apache DS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1560230/

相关文章:

node.js - 在权限管理方面,Active Directory 是否仍能与 Node.js 模块相媲美?

apache - mod_mono 问题 : Could not resolve the name 'ConfigurationManager'

java - 调试 java jar 文件

java - 计算网格上两个正方形之间的距离 - Java

java - 将串行通信数据添加到实时 Java 图中

php - 有没有类似Wamp Server的东西?

java - 请求的资源在 Tomcat 8.0.2 中不可用

active-directory - Sitecore Active Directory 间接成员资格

mysql - 如何在 Liferay 6.2 上将 LDAP 设置为永久

java - 在 Eclipse 中更新代号一