Search in sources :

Example 1 with Transport

use of org.apache.directory.server.protocol.shared.transport.Transport in project undertow by undertow-io.

the class KerberosKDCUtil method startLdapServer.

private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    // Derives the Kerberos keys for new entries.
    directoryService.addLast(new KeyDerivationInterceptor());
    directoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = directoryService.getSchemaManager();
    createPartition(dsf, schemaManager, "users", "ou=users,dc=undertow,dc=io");
    CoreSession adminSession = directoryService.getAdminSession();
    Map<String, String> mappings = Collections.singletonMap("hostname", DefaultServer.getDefaultServerAddress().getHostString());
    processLdif(schemaManager, adminSession, "partition.ldif", mappings);
    processLdif(schemaManager, adminSession, "krbtgt.ldif", mappings);
    processLdif(schemaManager, adminSession, "user.ldif", mappings);
    processLdif(schemaManager, adminSession, "server.ldif", mappings);
    ldapServer = new LdapServer();
    ldapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport("0.0.0.0", LDAP_PORT, 3, 5);
    ldapServer.addTransports(ldap);
    ldapServer.setDirectoryService(directoryService);
    ldapServer.start();
}
Also used : KeyDerivationInterceptor(org.apache.directory.server.core.kerberos.KeyDerivationInterceptor) LdapServer(org.apache.directory.server.ldap.LdapServer) DefaultDirectoryServiceFactory(org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) CoreSession(org.apache.directory.server.core.api.CoreSession) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) Transport(org.apache.directory.server.protocol.shared.transport.Transport) DirectoryServiceFactory(org.apache.directory.server.core.factory.DirectoryServiceFactory) DefaultDirectoryServiceFactory(org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory)

Example 2 with Transport

use of org.apache.directory.server.protocol.shared.transport.Transport in project wildfly by wildfly.

the class NoReplayKdcServer method createTransport.

private static Transport createTransport(CreateTransport transportBuilder, int startPort) {
    String protocol = transportBuilder.protocol();
    int port = transportBuilder.port();
    int nbThreads = transportBuilder.nbThreads();
    int backlog = transportBuilder.backlog();
    String address = transportBuilder.address();
    if (port == -1) {
        port = AvailablePortFinder.getNextAvailable(startPort);
        startPort = port + 1;
    }
    if (protocol.equalsIgnoreCase("TCP")) {
        Transport tcp = new TcpTransport(address, port, nbThreads, backlog);
        return tcp;
    } else if (protocol.equalsIgnoreCase("UDP")) {
        UdpTransport udp = new UdpTransport(address, port);
        return udp;
    } else {
        throw new IllegalArgumentException(I18n.err(I18n.ERR_689, protocol));
    }
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) CreateTransport(org.apache.directory.server.annotations.CreateTransport) UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) Transport(org.apache.directory.server.protocol.shared.transport.Transport)

Example 3 with Transport

use of org.apache.directory.server.protocol.shared.transport.Transport in project wildfly by wildfly.

the class NoReplayKdcServer method createKdcServer.

// Private methods -------------------------------------------------------
/**
 * Creates and starts {@link KdcServer} instance based on given configuration.
 *
 * @param createKdcServer
 * @param directoryService
 * @param startPort
 * @return
 */
private static KdcServer createKdcServer(CreateKdcServer createKdcServer, DirectoryService directoryService, int startPort, String bindAddress) {
    if (createKdcServer == null) {
        return null;
    }
    KerberosConfig kdcConfig = new KerberosConfig();
    kdcConfig.setServicePrincipal(createKdcServer.kdcPrincipal());
    kdcConfig.setPrimaryRealm(createKdcServer.primaryRealm());
    kdcConfig.setMaximumTicketLifetime(createKdcServer.maxTicketLifetime());
    kdcConfig.setMaximumRenewableLifetime(createKdcServer.maxRenewableLifetime());
    kdcConfig.setPaEncTimestampRequired(false);
    KdcServer kdcServer = new NoReplayKdcServer(kdcConfig);
    kdcServer.setSearchBaseDn(createKdcServer.searchBaseDn());
    CreateTransport[] transportBuilders = createKdcServer.transports();
    if (transportBuilders == null) {
        // create only UDP transport if none specified
        UdpTransport defaultTransport = new UdpTransport(bindAddress, AvailablePortFinder.getNextAvailable(startPort));
        kdcServer.addTransports(defaultTransport);
    } else if (transportBuilders.length > 0) {
        for (CreateTransport transportBuilder : transportBuilders) {
            String protocol = transportBuilder.protocol();
            int port = transportBuilder.port();
            int nbThreads = transportBuilder.nbThreads();
            int backlog = transportBuilder.backlog();
            final String address = bindAddress != null ? bindAddress : transportBuilder.address();
            if (port == -1) {
                port = AvailablePortFinder.getNextAvailable(startPort);
                startPort = port + 1;
            }
            if (protocol.equalsIgnoreCase("TCP")) {
                Transport tcp = new TcpTransport(address, port, nbThreads, backlog);
                kdcServer.addTransports(tcp);
            } else if (protocol.equalsIgnoreCase("UDP")) {
                UdpTransport udp = new UdpTransport(address, port);
                kdcServer.addTransports(udp);
            } else {
                throw new IllegalArgumentException(I18n.err(I18n.ERR_689, protocol));
            }
        }
    }
    CreateChngPwdServer[] createChngPwdServers = createKdcServer.chngPwdServer();
    if (createChngPwdServers.length > 0) {
        CreateChngPwdServer createChngPwdServer = createChngPwdServers[0];
        ChangePasswordConfig config = new ChangePasswordConfig(kdcConfig);
        config.setServicePrincipal(createChngPwdServer.srvPrincipal());
        ChangePasswordServer chngPwdServer = new ChangePasswordServer(config);
        for (CreateTransport transportBuilder : createChngPwdServer.transports()) {
            Transport t = createTransport(transportBuilder, startPort);
            startPort = t.getPort() + 1;
            chngPwdServer.addTransports(t);
        }
        chngPwdServer.setDirectoryService(directoryService);
        kdcServer.setChangePwdServer(chngPwdServer);
    }
    kdcServer.setDirectoryService(directoryService);
    // Launch the server
    try {
        kdcServer.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return kdcServer;
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) KerberosConfig(org.apache.directory.server.kerberos.KerberosConfig) CreateTransport(org.apache.directory.server.annotations.CreateTransport) ChangePasswordServer(org.apache.directory.server.kerberos.changepwd.ChangePasswordServer) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) ChangePasswordConfig(org.apache.directory.server.kerberos.ChangePasswordConfig) CreateChngPwdServer(org.apache.directory.server.annotations.CreateChngPwdServer) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) CreateTransport(org.apache.directory.server.annotations.CreateTransport) UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) Transport(org.apache.directory.server.protocol.shared.transport.Transport) KdcServer(org.apache.directory.server.kerberos.kdc.KdcServer) CreateKdcServer(org.apache.directory.server.annotations.CreateKdcServer)

Example 4 with Transport

use of org.apache.directory.server.protocol.shared.transport.Transport 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)

Aggregations

TcpTransport (org.apache.directory.server.protocol.shared.transport.TcpTransport)4 Transport (org.apache.directory.server.protocol.shared.transport.Transport)4 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)3 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)2 CreateTransport (org.apache.directory.server.annotations.CreateTransport)2 IOException (java.io.IOException)1 URL (java.net.URL)1 CacheManager (net.sf.ehcache.CacheManager)1 Configuration (net.sf.ehcache.config.Configuration)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 DefaultSchemaManager (org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)1 CreateChngPwdServer (org.apache.directory.server.annotations.CreateChngPwdServer)1 CreateKdcServer (org.apache.directory.server.annotations.CreateKdcServer)1 DefaultDirectoryService (org.apache.directory.server.core.DefaultDirectoryService)1 CacheService (org.apache.directory.server.core.api.CacheService)1 CoreSession (org.apache.directory.server.core.api.CoreSession)1 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)1 AnonymousAuthenticator (org.apache.directory.server.core.authn.AnonymousAuthenticator)1 AuthenticationInterceptor (org.apache.directory.server.core.authn.AuthenticationInterceptor)1 Authenticator (org.apache.directory.server.core.authn.Authenticator)1