我正在为我的代码编写单元测试,出于测试目的,我正在使用 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
请帮我正确配置。