0

我正在为我的代码编写单元测试,出于测试目的,我正在使用 unboundsId 的内存 LDAP 服务器。我创建并连接到内存服务器,之后我想执行同步请求,但服务器说“InMemory LDAP 服务器不支持 contentSyncRequestControl”。我查看了服务器 API 文档,有很多控件。我尝试打印受支持的控件的 OID,并且 contentSyncRequestControl 的 OID 不存在。所以我的问题是如何启用或添加控件到 inMemory LDAP 服务器?查看以下代码以获取参考。

public class InMemoryLDAPServer {
    private Logger logger = LoggerFactory.getLogger(InMemoryLDAPServer.class);

    private InMemoryDirectoryServer mServer;
    final String DEFAULT_INMEMORY_HOST = "localhost";
    final int DEFAULT_INMEMORY_PORT = 5389;
    final String LDAP_LISTENER_NAME = "LDAP_TEST_SERVER";
    final String INMEMORY_BASE = "dc=Contoso,dc=net";
    final String INMEMORY_DOMAIN = "Contoso.net";
    final String INMEMORY_USER = "uid=TestAdmin";
    final String INMEMORY_PASS = "password";


    public void start(int port) {
        try {

            InMemoryDirectoryServerConfig config =
                 new InMemoryDirectoryServerConfig(INMEMORY_BASE);
            config.setGenerateOperationalAttributes(true);
            config.addAdditionalBindCredentials(INMEMORY_USER, INMEMORY_PASS);
            config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig(LDAP_LISTENER_NAME, port));


            mServer = new InMemoryDirectoryServer(config);
            URI ldifFixture= InMemoryLDAPServer.class.getResource("/Contoso_rootdse_open.ldif").toURI();
            mServer.importFromLDIF(true, new LDIFReader(new File(ldifFixture)));


            mServer.startListening(LDAP_LISTENER_NAME); 
            // I tried here to check which controlls are supported
//The OID (1.3.6.1.4.1.4203.1.9.1.1) for the sync request control.
            LDAPConnection con = mServer.getConnection();
            RootDSE rootDSE = con.getRootDSE();
            String[] oids = rootDSE.getSupportedControlOIDs();

            for(int i=0; i<oids.length; i++){
                System.out.println(oids[i]);

            }
            con.close();

        } catch(Exception exception) {
            logger.error("Failed to start in memory ldap server", exception);
        }


    }

    public void start() {
        start(DEFAULT_INMEMORY_PORT);
    }

    public void stop() {
        try {
        mServer.shutDown(LDAP_LISTENER_NAME, true);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

结果

这是默认支持的控件 OID。

1.2.840.113556.1.4.1413
1.2.840.113556.1.4.319
1.2.840.113556.1.4.473
1.2.840.113556.1.4.805
1.3.6.1.1.12
1.3.6.1.1.13.1
1.3.6.1.1.13.2
1.3.6.1.1.21.2
1.3.6.1.1.22
1.3.6.1.4.1.7628.5.101.1
2.16.840.1.113730.3.4.12
2.16.840.1.113730.3.4.16
2.16.840.1.113730.3.4.18
2.16.840.1.113730.3.4.2
2.16.840.1.113730.3.4.9

参考 API 文档:https ://docs.ldap.com/ldap-sdk/docs/javadoc/index.html

请帮我正确配置。

4

1 回答 1

1

确实没有什么好的方法可以做到这一点。您可以添加对自定义扩展操作和 SASL 机制的支持,因为在这些情况下,自定义代码将执行所有处理。但是控件实际上改变了服务器处理操作的方式,所以它必须集成到服务器执行的核心处理中。

但是,如果您要使用的控件足够简单,可以通过不更改操作的核心处理而仅更改请求或响应来支持它,那么您应该能够通过创建自定义 InMemoryOperationInterceptor 来实现这一点(尽管它不会出现在根 DSE 的支持控件集中,除非您还截获了检索根 DSE 的请求并在其中注入了额外的 OID)。

您对哪些控件感兴趣?它们是标准的还是专有的?内存目录服务器旨在成为一个通用的、符合标准的服务器,它并不适合包含专有元素。但是如果有一个目前不支持但可能有用的标准控件,那么我们可以考虑为其添加直接支持。

于 2015-02-03T18:58:18.717 回答