Search in sources :

Example 1 with InMemoryListenerConfig

use of com.unboundid.ldap.listener.InMemoryListenerConfig in project gocd by gocd.

the class InMemoryLdapServerForTests method startServer.

private InMemoryDirectoryServer startServer(int port, String baseDn, String bindDn, String bindPassword) throws LDAPException, BindException {
    InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", port);
    InMemoryDirectoryServerConfig serverConfig = new InMemoryDirectoryServerConfig(new DN(baseDn));
    /* Ignore schema so that it does not complain that some attributes (like sAMAccountName) are not valid. */
    serverConfig.setSchema(null);
    serverConfig.setListenerConfigs(listenerConfig);
    serverConfig.addAdditionalBindCredentials(bindDn, bindPassword);
    InMemoryDirectoryServer server = new InMemoryDirectoryServer(serverConfig);
    try {
        server.startListening();
    } catch (LDAPException e) {
        throw new RuntimeException(e);
    }
    new LDIFAddChangeRecord(baseDn, new Attribute("objectClass", "domain", "top")).processChange(server);
    return server;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) Attribute(com.unboundid.ldap.sdk.Attribute) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDIFAddChangeRecord(com.unboundid.ldif.LDIFAddChangeRecord) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) InMemoryListenerConfig(com.unboundid.ldap.listener.InMemoryListenerConfig) DN(com.unboundid.ldap.sdk.DN)

Example 2 with InMemoryListenerConfig

use of com.unboundid.ldap.listener.InMemoryListenerConfig in project spring-boot by spring-projects.

the class EmbeddedLdapAutoConfiguration method directoryServer.

@Bean
public InMemoryDirectoryServer directoryServer() throws LDAPException {
    InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.embeddedProperties.getBaseDn());
    if (hasCredentials(this.embeddedProperties.getCredential())) {
        config.addAdditionalBindCredentials(this.embeddedProperties.getCredential().getUsername(), this.embeddedProperties.getCredential().getPassword());
    }
    setSchema(config);
    InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("LDAP", this.embeddedProperties.getPort());
    config.setListenerConfigs(listenerConfig);
    this.server = new InMemoryDirectoryServer(config);
    importLdif();
    this.server.startListening();
    setPortProperty(this.applicationContext, this.server.getListenPort());
    return this.server;
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) InMemoryListenerConfig(com.unboundid.ldap.listener.InMemoryListenerConfig) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)2 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)2 InMemoryListenerConfig (com.unboundid.ldap.listener.InMemoryListenerConfig)2 Attribute (com.unboundid.ldap.sdk.Attribute)1 DN (com.unboundid.ldap.sdk.DN)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1