Search in sources :

Example 16 with TcpTransport

use of org.apache.directory.server.protocol.shared.transport.TcpTransport in project camunda-bpm-platform by camunda.

the class LdapTestEnvironment method startServer.

/**
 * starts the LdapServer
 *
 * @throws Exception
 */
public void startServer() throws Exception {
    ldapService = new LdapServer();
    Properties properties = loadTestProperties();
    String port = properties.getProperty("ldap.server.port");
    ldapService.setTransports(new TcpTransport(Integer.parseInt(port)));
    ldapService.setDirectoryService(service);
    ldapService.start();
}
Also used : LdapServer(org.apache.directory.server.ldap.LdapServer) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) Properties(java.util.Properties)

Example 17 with TcpTransport

use of org.apache.directory.server.protocol.shared.transport.TcpTransport in project goodies by sonatype.

the class LdapServer method start.

public void start() throws Exception {
    if (running) {
        throw new IllegalStateException("The LdapServer is already running");
    }
    long start = System.currentTimeMillis();
    if (port <= 0) {
        port = portRegistry.reservePort();
    }
    // an example that shows how to create and configure embedded apacheds instance
    // http://svn.apache.org/repos/asf/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java
    directoryService = new DefaultDirectoryService();
    // support multiple embedded ldap servers by assigning each one a distinct cache
    URL configURL = getClass().getClassLoader().getResource("directory-cacheservice.xml");
    Configuration config = ConfigurationFactory.parseConfiguration(configURL);
    config.setName(config.getName() + '_' + System.identityHashCode(this));
    directoryService.setCacheService(new CacheService(new CacheManager(config)));
    directoryService.setInstanceLayout(new InstanceLayout(workingDirectory));
    SchemaManager schemaManager = new DefaultSchemaManager();
    directoryService.setSchemaManager(schemaManager);
    // required by group mapping tests
    schemaManager.enable("nis");
    initPartitions(directoryService);
    ldapServer = new org.apache.directory.server.ldap.LdapServer();
    Transport transport = new TcpTransport(LOCALHOST, port);
    transport.setEnableSSL(ldapsKeystore != null);
    ldapServer.setTransports(transport);
    if (ldapsKeystore != null) {
        ldapServer.setKeystoreFile(ldapsKeystore.getCanonicalPath());
    }
    if (ldapsKeystorePassword != null) {
        ldapServer.setCertificatePassword(ldapsKeystorePassword);
    }
    ldapServer.setDirectoryService(directoryService);
    // allowed authentication mechanisms
    Authenticator[] authenticators;
    switch(authLevel) {
        case SIMPLE:
            authenticators = new Authenticator[] { new SimpleAuthenticator() };
            break;
        case STRONG:
            authenticators = new Authenticator[] { new StrongAuthenticator() };
            ldapServer.setSaslMechanismHandlers(saslHandlers);
            ldapServer.setSaslHost(LOCALHOST);
            ldapServer.setSaslRealms(Arrays.asList(getSaslRealm()));
            ldapServer.setSearchBaseDn(searchBaseDn);
            break;
        case NONE:
        default:
            directoryService.setAllowAnonymousAccess(true);
            authenticators = new Authenticator[] { new AnonymousAuthenticator(), new SimpleAuthenticator() };
            break;
    }
    AuthenticationInterceptor auth = (AuthenticationInterceptor) directoryService.getInterceptor(InterceptorEnum.AUTHENTICATION_INTERCEPTOR.getName());
    auth.setAuthenticators(authenticators);
    directoryService.startup();
    ldapServer.start();
    running = true;
    log.debug("Started LdapServer in {} ms", System.currentTimeMillis() - start);
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Configuration(net.sf.ehcache.config.Configuration) AuthenticationInterceptor(org.apache.directory.server.core.authn.AuthenticationInterceptor) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) AnonymousAuthenticator(org.apache.directory.server.core.authn.AnonymousAuthenticator) URL(java.net.URL) DefaultDirectoryService(org.apache.directory.server.core.DefaultDirectoryService) StrongAuthenticator(org.apache.directory.server.core.authn.StrongAuthenticator) SimpleAuthenticator(org.apache.directory.server.core.authn.SimpleAuthenticator) CacheManager(net.sf.ehcache.CacheManager) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) Transport(org.apache.directory.server.protocol.shared.transport.Transport) AnonymousAuthenticator(org.apache.directory.server.core.authn.AnonymousAuthenticator) Authenticator(org.apache.directory.server.core.authn.Authenticator) SimpleAuthenticator(org.apache.directory.server.core.authn.SimpleAuthenticator) StrongAuthenticator(org.apache.directory.server.core.authn.StrongAuthenticator) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)

Example 18 with TcpTransport

use of org.apache.directory.server.protocol.shared.transport.TcpTransport in project spring-security by spring-projects.

the class ApacheDSContainer method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if (this.workingDir == null) {
        String apacheWorkDir = System.getProperty("apacheDSWorkDir");
        if (apacheWorkDir == null) {
            apacheWorkDir = createTempDirectory("apacheds-spring-security-");
        }
        setWorkingDirectory(new File(apacheWorkDir));
    }
    Assert.isTrue(!this.ldapOverSslEnabled || this.keyStoreFile != null, "When LdapOverSsl is enabled, the keyStoreFile property must be set.");
    this.server = new LdapServer();
    this.server.setDirectoryService(this.service);
    // AbstractLdapIntegrationTests assume IPv4, so we specify the same here
    this.transport = new TcpTransport(this.port);
    if (this.ldapOverSslEnabled) {
        this.transport.setEnableSSL(true);
        this.server.setKeystoreFile(this.keyStoreFile.getAbsolutePath());
        this.server.setCertificatePassword(this.certificatePassord);
    }
    this.server.setTransports(this.transport);
    start();
}
Also used : LdapServer(org.apache.directory.server.ldap.LdapServer) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) File(java.io.File)

Example 19 with TcpTransport

use of org.apache.directory.server.protocol.shared.transport.TcpTransport in project vertx-auth by vert-x3.

the class EmbeddedADS method startServer.

/**
 * starts the LdapServer
 *
 * @throws Exception
 */
public void startServer() throws Exception {
    server = new LdapServer();
    int serverPort = 10389;
    server.setTransports(new TcpTransport(serverPort));
    server.setDirectoryService(service);
    server.start();
}
Also used : LdapServer(org.apache.directory.server.ldap.LdapServer) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport)

Aggregations

TcpTransport (org.apache.directory.server.protocol.shared.transport.TcpTransport)19 LdapServer (org.apache.directory.server.ldap.LdapServer)9 File (java.io.File)6 Transport (org.apache.directory.server.protocol.shared.transport.Transport)4 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)3 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)3 HashMap (java.util.HashMap)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 CreateTransport (org.apache.directory.server.annotations.CreateTransport)2 DefaultDirectoryService (org.apache.directory.server.core.DefaultDirectoryService)2 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)2 DefaultDirectoryServiceFactory (org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory)2 MechanismHandler (org.apache.directory.server.ldap.handlers.sasl.MechanismHandler)2 CramMd5MechanismHandler (org.apache.directory.server.ldap.handlers.sasl.cramMD5.CramMd5MechanismHandler)2 DigestMd5MechanismHandler (org.apache.directory.server.ldap.handlers.sasl.digestMD5.DigestMd5MechanismHandler)2 GssapiMechanismHandler (org.apache.directory.server.ldap.handlers.sasl.gssapi.GssapiMechanismHandler)2 PlainMechanismHandler (org.apache.directory.server.ldap.handlers.sasl.plain.PlainMechanismHandler)2 SimpleLdapDirectoryServer (org.apache.knox.gateway.security.ldap.SimpleLdapDirectoryServer)2 JsonPath (io.restassured.path.json.JsonPath)1 FileNotFoundException (java.io.FileNotFoundException)1