org.apache.directory.server.protocol.shared.transport.Transport Java Examples

The following examples show how to use org.apache.directory.server.protocol.shared.transport.Transport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KerberosKDCUtil.java    From quarkus-http with Apache License 2.0 8 votes vote down vote up
private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    directoryService.addLast(new KeyDerivationInterceptor()); // Derives the Kerberos keys for new entries.
    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();
}
 
Example #2
Source File: LdapTestSuite.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void startSlaveLdapServer() throws Exception {
    slaveWorkingDir = createWorkingDir(slaveWorkingDir, "slave");
    DirectoryServiceFactory dsf = new InMemoryDirectoryServiceFactory();
    dsf.init(SLAVE_DIRECTORY_NAME);
    slaveDirectoryService = dsf.getDirectoryService();
    slaveDirectoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = slaveDirectoryService.getSchemaManager();

    createPartition(dsf, schemaManager, "simple", "dc=simple,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);
    createPartition(dsf, schemaManager, "group-to-principal", "dc=group-to-principal,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);
    createPartition(dsf, schemaManager, "principal-to-group", "dc=principal-to-group,dc=wildfly,dc=org", slaveDirectoryService, slaveWorkingDir);

    CoreSession adminSession = slaveDirectoryService.getAdminSession();
    processLdif(schemaManager, adminSession, "memberOf-schema.ldif");
    processLdif(schemaManager, adminSession, "simple-partition-slave.ldif");
    processLdif(schemaManager, adminSession, "group-to-principal-slave.ldif");
    processLdif(schemaManager, adminSession, "principal-to-group-slave.ldif");

    slaveLdapServer = new LdapServer();
    slaveLdapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport( "0.0.0.0", SLAVE_LDAP_PORT, 3, 5 );
    slaveLdapServer.addTransports(ldap);
    slaveLdapServer.setDirectoryService(slaveDirectoryService);
    slaveLdapServer.start();
}
 
Example #3
Source File: LdapTestSuite.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void startMasterLdapServer() throws Exception {
    masterWorkingDir = createWorkingDir(masterWorkingDir, "master");
    DirectoryServiceFactory dsf = new InMemoryDirectoryServiceFactory();
    dsf.init(MASTER_DIRECTORY_NAME);
    masterDirectoryService = dsf.getDirectoryService();
    masterDirectoryService.getChangeLog().setEnabled(false);
    SchemaManager schemaManager = masterDirectoryService.getSchemaManager();

    createPartition(dsf, schemaManager, "simple", "dc=simple,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);
    createPartition(dsf, schemaManager, "group-to-principal", "dc=group-to-principal,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);
    createPartition(dsf, schemaManager, "principal-to-group", "dc=principal-to-group,dc=wildfly,dc=org", masterDirectoryService, masterWorkingDir);

    CoreSession adminSession = masterDirectoryService.getAdminSession();
    processLdif(schemaManager, adminSession, "memberOf-schema.ldif");
    processLdif(schemaManager, adminSession, "simple-partition.ldif");
    processLdif(schemaManager, adminSession, "group-to-principal.ldif");
    processLdif(schemaManager, adminSession, "principal-to-group.ldif");

    masterLdapServer = new LdapServer();
    masterLdapServer.setServiceName("DefaultLDAP");
    Transport ldap = new TcpTransport( "0.0.0.0", MASTER_LDAP_PORT, 3, 5 );
    masterLdapServer.addTransports(ldap);
    masterLdapServer.setDirectoryService(masterDirectoryService);
    masterLdapServer.start();
}
 
Example #4
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * @return The underlying TCP transport port, or -1 if no transport has been 
 * initialized
 */
public int getPort()
{
    if ( transports == null )
    {
        return -1;
    }

    for ( Transport transport : transports )
    {
        if ( transport instanceof UdpTransport )
        {
            continue;
        }

        if ( !transport.isSSLEnabled() )
        {
            return transport.getPort();
        }
    }

    return -1;
}
 
Example #5
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * @return The underlying SSL enabled TCP transport port, or -1 if no transport has been 
 * initialized
 */
public int getPortSSL()
{
    if ( transports == null )
    {
        return -1;
    }

    for ( Transport transport : transports )
    {
        if ( transport instanceof UdpTransport )
        {
            continue;
        }

        if ( transport.isSSLEnabled() )
        {
            return transport.getPort();
        }
    }

    return -1;
}
 
Example #6
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * @see Object#toString()
 */
public String toString()
{
    StringBuilder sb = new StringBuilder();

    sb.append( "LdapServer[" ).append( getServiceName() ).append( "], listening on :" ).append( '\n' );

    if ( getTransports() != null )
    {
        for ( Transport transport : getTransports() )
        {
            sb.append( "    " ).append( transport ).append( '\n' );
        }
    }

    return sb.toString();
}
 
Example #7
Source File: LdapService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Adds a TCP server to the directory service.
 *
 * Note: The TCP server is not started until start() is called on this Builder.
 *
 * @param serviceName - The name of this server.
 * @param hostName - The host name to listen on.
 * @param port - The port to listen on.
 * @return This Builder for subsequent changes.
 */
public Builder addTcpServer(final String serviceName, final String hostName, final int port, final String keyStore, final String keyStorePassword) throws URISyntaxException {
    assertNotStarted();
    if (directoryService == null) {
        throw new IllegalStateException("The Directory service has not been created.");
    }

    LdapServer server = new LdapServer();
    server.setServiceName(serviceName);
    Transport ldaps = new TcpTransport( hostName, port, 3, 5 );
    ldaps.enableSSL(true);
    server.addTransports(ldaps);
    server.setKeystoreFile(new File(getClass().getResource(keyStore).getFile()).getAbsolutePath());
    server.setCertificatePassword(keyStorePassword);
    server.setDirectoryService(directoryService);
    servers.add(server);

    return this;
}
 
Example #8
Source File: ApacheKDCServer.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void configureTransportHandlers(KdcConfiguration configuration) {

        int port = getServerPort(configuration);
        if (configuration.getKdcCommunicationProtocol() ==
                KdcConfiguration.ProtocolType.UDP_PROTOCOL) {

            logger.info("Starting KDC on UDP mode at port - " + port + " at host - " +
                    configuration.getKdcHostAddress());

            UdpTransport defaultTransport = new UdpTransport(port);
            this.kdcServer.addTransports(defaultTransport);

        } else {

            logger.info("Starting KDC on a TCP port " + port + " at host " +
                    configuration.getKdcHostAddress());
            Transport tcp =
                    new TcpTransport(configuration.getKdcHostAddress(), port,
                            configuration.getNumberOfThreads(),
                            configuration.getBackLogCount());
            this.kdcServer.addTransports(tcp);

        }
    }
 
Example #9
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * @return The underlying TCP transport port, or -1 if no transport has been 
 * initialized
 */
public int getPort()
{
    if ( transports == null )
    {
        return -1;
    }

    for ( Transport transport : transports )
    {
        if ( transport instanceof UdpTransport )
        {
            continue;
        }

        if ( !transport.isSSLEnabled() )
        {
            return transport.getPort();
        }
    }

    return -1;
}
 
Example #10
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * @return The underlying SSL enabled TCP transport port, or -1 if no transport has been 
 * initialized
 */
public int getPortSSL()
{
    if ( transports == null )
    {
        return -1;
    }

    for ( Transport transport : transports )
    {
        if ( transport instanceof UdpTransport )
        {
            continue;
        }

        if ( transport.isSSLEnabled() )
        {
            return transport.getPort();
        }
    }

    return -1;
}
 
Example #11
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * @see Object#toString()
 */
public String toString()
{
    StringBuilder sb = new StringBuilder();

    sb.append( "LdapServer[" ).append( getServiceName() ).append( "], listening on :" ).append( '\n' );

    if ( getTransports() != null )
    {
        for ( Transport transport : getTransports() )
        {
            sb.append( "    " ).append( transport ).append( '\n' );
        }
    }

    return sb.toString();
}
 
Example #12
Source File: ApacheDirectoryServer.java    From light-oauth2 with Apache License 2.0 5 votes vote down vote up
private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    directoryService.addLast(new KeyDerivationInterceptor()); // Derives the Kerberos keys for new entries.
    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());
    Map<String, String> mappings = Collections.singletonMap("hostname", "localhost");
    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", LDAPS_PORT, 3, 5 );
    ldap.enableSSL(true);
    ldapServer.addTransports(ldap);
    ldapServer.setKeystoreFile(ApacheDirectoryServer.class.getResource("/config/server.keystore").getFile());
    ldapServer.setCertificatePassword("password");
    ldapServer.loadKeyStore();
    ldapServer.setDirectoryService(directoryService);
    ldapServer.start();
}
 
Example #13
Source File: KDCServerAnnotationProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 ) );
    }
}
 
Example #14
Source File: TestLdap.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void prepare() {
	loadLdapConf("om_ldap.cfg", PROPS);
	Transport t = serverExtension.getLdapServer().getTransports()[0];
	PROPS.put(CONFIGKEY_LDAP_HOST, t.getAddress());
	PROPS.put(CONFIGKEY_LDAP_PORT, String.valueOf(t.getPort()));
	PROPS.put(CONFIGKEY_LDAP_ADMIN_DN, ADMIN_SYSTEM_DN);
	PROPS.put(CONFIGKEY_LDAP_ADMIN_PASSWD, new String(ADMIN_PASSWORD_BYTES));
	PROPS.put(CONFIGKEY_LDAP_SEARCH_BASE, "dc=test,dc=openmeetings,dc=apache,dc=org");
	PROPS.put(CONFIGKEY_LDAP_SEARCH_SCOPE, SearchScope.SUBTREE.name());
	PROPS.put(CONFIGKEY_LDAP_KEY_PICTURE, "photo");
	PROPS.put(CONFIGKEY_LDAP_PICTURE_URI, "profile.png"); // this one is for Jenkins
}
 
Example #15
Source File: ApacheDirectoryServer.java    From light-oauth2 with Apache License 2.0 5 votes vote down vote up
private static void startLdapServer() throws Exception {
    createWorkingDir();
    DirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
    dsf.init(DIRECTORY_NAME);
    directoryService = dsf.getDirectoryService();
    directoryService.addLast(new KeyDerivationInterceptor()); // Derives the Kerberos keys for new entries.
    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());
    Map<String, String> mappings = Collections.singletonMap("hostname", "localhost");
    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", LDAPS_PORT, 3, 5 );
    ldap.enableSSL(true);
    ldapServer.addTransports(ldap);
    ldapServer.setKeystoreFile(ApacheDirectoryServer.class.getResource("/config/server.keystore").getFile());
    ldapServer.setCertificatePassword("password");
    ldapServer.loadKeyStore();
    ldapServer.setDirectoryService(directoryService);
    ldapServer.start();
}
 
Example #16
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
private void startNetwork( Transport transport, IoFilterChainBuilder chainBuilder ) throws Exception
{
    if ( transport.getBackLog() < 0 )
    {
        // Set the backlog to the default value when it's below 0
        transport.setBackLog( 50 );
    }

    chainBuilders.add( chainBuilder );

    try
    {
        SocketAcceptor acceptor = getSocketAcceptor( transport );

        // Now, configure the acceptor
        // Disable the disconnection of the clients on unbind
        acceptor.setCloseOnDeactivation( false );

        // No Nagle's algorithm
        acceptor.getSessionConfig().setTcpNoDelay( true );

        // Inject the chain
        acceptor.setFilterChainBuilder( chainBuilder );

        // Inject the protocol handler
        acceptor.setHandler( getHandler() );

        ( ( AbstractSocketSessionConfig ) acceptor.getSessionConfig() ).setReadBufferSize( 64 * 1024 );
        ( ( AbstractSocketSessionConfig ) acceptor.getSessionConfig() ).setSendBufferSize( 64 * 1024 );

        // Bind to the configured address
        acceptor.bind();

        // We are done !
        started = true;

        if ( LOG.isInfoEnabled() )
        {
            LOG.info( "Successful bind of an LDAP Service (" + transport.getPort() + ") is completed." );
        }
    }
    catch ( IOException e )
    {
        String msg = I18n.err( I18n.ERR_171, transport.getPort() );
        LdapConfigurationException lce = new LdapConfigurationException( msg );
        lce.setCause( e );
        LOG.error( msg, e );
        throw lce;
    }
}
 
Example #17
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
private void startNetwork( Transport transport, IoFilterChainBuilder chainBuilder ) throws Exception
{
    if ( transport.getBackLog() < 0 )
    {
        // Set the backlog to the default value when it's below 0
        transport.setBackLog( 50 );
    }

    chainBuilders.add( chainBuilder );

    try
    {
        SocketAcceptor acceptor = getSocketAcceptor( transport );

        // Now, configure the acceptor
        // Disable the disconnection of the clients on unbind
        acceptor.setCloseOnDeactivation( false );

        // No Nagle's algorithm
        acceptor.getSessionConfig().setTcpNoDelay( true );

        // Inject the chain
        acceptor.setFilterChainBuilder( chainBuilder );

        // Inject the protocol handler
        acceptor.setHandler( getHandler() );

        ( ( AbstractSocketSessionConfig ) acceptor.getSessionConfig() ).setReadBufferSize( 64 * 1024 );
        ( ( AbstractSocketSessionConfig ) acceptor.getSessionConfig() ).setSendBufferSize( 64 * 1024 );

        // Bind to the configured address
        acceptor.bind();

        // We are done !
        started = true;

        if ( LOG.isInfoEnabled() )
        {
            LOG.info( "Successful bind of an LDAP Service (" + transport.getPort() + ") is completed." );
        }
    }
    catch ( IOException e )
    {
        String msg = I18n.err( I18n.ERR_171, transport.getPort() );
        LdapConfigurationException lce = new LdapConfigurationException( msg );
        lce.setCause( e );
        LOG.error( msg, e );
        throw lce;
    }
}
 
Example #18
Source File: LDAPEmbeddedServer.java    From keycloak with Apache License 2.0 4 votes vote down vote up
protected LdapServer createLdapServer() {
    LdapServer ldapServer = new LdapServer();

    ldapServer.setServiceName("DefaultLdapServer");
    ldapServer.setSearchBaseDn(this.baseDN);
    // Tolerate plaintext LDAP connections from clients by default
    ldapServer.setConfidentialityRequired(this.setConfidentialityRequired);

    // Read the transports
    Transport ldap = new TcpTransport(this.bindHost, this.bindPort, 3, 50);
    ldapServer.addTransports( ldap );
    if (enableSSL || enableStartTLS) {
        ldapServer.setKeystoreFile(keystoreFile);
        ldapServer.setCertificatePassword(certPassword);
        if (enableSSL) {
            Transport ldaps = new TcpTransport(this.bindHost, this.bindLdapsPort, 3, 50);
            ldaps.setEnableSSL(true);
            ldapServer.addTransports( ldaps );
            if (ldaps.isSSLEnabled()) {
                log.info("Enabled SSL support on the LDAP server.");
            }
        }
        if (enableStartTLS) {
            try {
                ldapServer.addExtendedOperationHandler(new StartTlsHandler());
            } catch (Exception e) {
                throw new IllegalStateException("Cannot add the StartTLS extension handler: ", e);
            }
            for (ExtendedOperationHandler eoh : ldapServer.getExtendedOperationHandlers()) {
                if (eoh.getOid().equals(StartTlsHandler.EXTENSION_OID)) {
                    log.info("Enabled StartTLS support on the LDAP server.");
                    break;
                }
            }
        }
    }

    // Require the LDAP server to accept only encrypted connections if confidentiality requested
    if (setConfidentialityRequired) {
        ldapServer.setConfidentialityRequired(true);
        if (ldapServer.isConfidentialityRequired()) {
            log.info("Configured the LDAP server to accepts only requests with a secured connection.");
        }
    }

    // Associate the DS to this LdapServer
    ldapServer.setDirectoryService( directoryService );

    // Support for extended password modify as described in https://tools.ietf.org/html/rfc3062
    try {
        ldapServer.addExtendedOperationHandler(new PwdModifyHandler());
    } catch (LdapException le) {
        throw new IllegalStateException("It wasn't possible to add PwdModifyHandler");
    }

    if (enableAccessControl) {
        if (enableAnonymousAccess) {
            throw new IllegalStateException("Illegal to enable both the access control subsystem and the anonymous access at the same time! See: http://directory.apache.org/apacheds/gen-docs/latest/apidocs/src-html/org/apache/directory/server/core/DefaultDirectoryService.html#line.399 for details.");
        } else {
            directoryService.setAccessControlEnabled(true);
            if (directoryService.isAccessControlEnabled()) {
                log.info("Enabled basic access control checks on the LDAP server.");
            }
        }
    } else {
        if (enableAnonymousAccess) {
            directoryService.setAllowAnonymousAccess(true);
            // Since per ApacheDS JavaDoc: http://directory.apache.org/apacheds/gen-docs/latest/apidocs/src-html/org/apache/directory/server/core/DefaultDirectoryService.html#line.399
            // "if the access control subsystem is enabled then access to some entries may not
            // be allowed even when full anonymous access is enabled", disable the access control
            // subsystem together with enabling anonymous access to prevent this
            directoryService.setAccessControlEnabled(false);
            if (directoryService.isAllowAnonymousAccess() && !directoryService.isAccessControlEnabled()) {
                log.info("Enabled anonymous access on the LDAP server.");
            }
        }
    }

    return ldapServer;
}
 
Example #19
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 2 votes vote down vote up
/**
 * Returns <tt>true</tt> if LDAPS is enabled.
 *
 * @return True if LDAPS is enabled.
 */
public boolean isEnableLdaps( Transport transport )
{
    return transport.isSSLEnabled();
}
 
Example #20
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 2 votes vote down vote up
/**
 * Returns <tt>true</tt> if LDAPS is enabled.
 *
 * @return True if LDAPS is enabled.
 */
public boolean isEnableLdaps( Transport transport )
{
    return transport.isSSLEnabled();
}