org.apache.directory.ldap.client.api.LdapConnectionConfig Java Examples

The following examples show how to use org.apache.directory.ldap.client.api.LdapConnectionConfig. 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: ApiLdapClientApiOsgiTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Override
protected void useBundleClasses() throws Exception
{
    new LdapNetworkConnection().close();
    new SaslGssApiRequest();
    new Krb5LoginConfiguration();
    new AddFuture( new LdapNetworkConnection(), 2 );
    new LdapConnectionTemplate( new LdapConnectionPool( new DefaultPoolableLdapConnectionFactory(
        new LdapConnectionConfig() ) ) );
    FilterBuilder.and( FilterBuilder.not( FilterBuilder.contains( "cn", "a", "b" ) ) ).toString();

    // Test for DIRAPI-239
    PooledObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(
        new LdapConnectionConfig() );
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    LdapConnectionPool ldapConnectionPool = new LdapConnectionPool( factory, config );
    ldapConnectionPool.getLdapApiService();
    ldapConnectionPool.getTestOnBorrow();
    ldapConnectionPool.close();
}
 
Example #2
Source File: LDAPConnectionService.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of LdapNetworkConnection, configured as required
 * to use the given encryption method to communicate with the LDAP server
 * at the given hostname and port. The returned LdapNetworkConnection is
 * configured for use but is not yet connected nor bound to the LDAP
 * server. It will not be bound until a bind operation is explicitly
 * requested, and will not be connected until it is used in an LDAP
 * operation (such as a bind).
 *
 * @param host
 *     The hostname or IP address of the LDAP server.
 *
 * @param port
 *     The TCP port that the LDAP server is listening on.
 *
 * @param encryptionMethod
 *     The encryption method that should be used to communicate with the
 *     LDAP server.
 *
 * @return
 *     A new instance of LdapNetworkConnection which uses the given
 *     encryption method to communicate with the LDAP server at the given
 *     hostname and port.
 *
 * @throws GuacamoleException
 *     If the requested encryption method is actually not implemented (a
 *     bug).
 */
private LdapNetworkConnection createLDAPConnection(String host, int port,
        EncryptionMethod encryptionMethod) throws GuacamoleException {

    LdapConnectionConfig config = new LdapConnectionConfig();
    config.setLdapHost(host);
    config.setLdapPort(port);

    // Map encryption method to proper connection and socket factory
    switch (encryptionMethod) {

        // Unencrypted LDAP connection
        case NONE:
            logger.debug("Connection to LDAP server without encryption.");
            break;

        // LDAP over SSL (LDAPS)
        case SSL:
            logger.debug("Connecting to LDAP server using SSL/TLS.");
            config.setUseSsl(true);
            break;

        // LDAP + STARTTLS
        case STARTTLS:
            logger.debug("Connecting to LDAP server using STARTTLS.");
            config.setUseTls(true);
            break;

        // The encryption method, though known, is not actually
        // implemented. If encountered, this would be a bug.
        default:
            throw new GuacamoleUnsupportedException("Unimplemented encryption method: " + encryptionMethod);

    }

    return new LdapNetworkConnection(config);

}
 
Example #3
Source File: LDAPApi.java    From mamute with Apache License 2.0 5 votes vote down vote up
private LdapConnection connection(String username, String password) throws LdapException {
	// Manually build the configuration since the convenience constructor in 
	// the LdapNetworkConnection doesn't let us specify a TLS setting			
	LdapConnectionConfig config = new LdapConnectionConfig();
	config.setLdapHost(host);
	config.setLdapPort(port);
	config.setUseTls(useTls);
	config.setUseSsl(useSsl);
       LdapNetworkConnection conn = new LdapNetworkConnection(config);
	
	conn.bind(username, password);
	return conn;
}
 
Example #4
Source File: SingularityLDAPDatastore.java    From Singularity with Apache License 2.0 5 votes vote down vote up
private static LdapConnectionPool createConnectionPool(LDAPConfiguration configuration)
  throws IOException {
  final LdapConnectionConfig config = new LdapConnectionConfig();
  config.setLdapHost(configuration.getHostname());
  config.setLdapPort(configuration.getPort());
  config.setName(configuration.getBindDn());
  config.setCredentials(configuration.getBindPassword());

  final DefaultPoolableLdapConnectionFactory factory = new DefaultPoolableLdapConnectionFactory(
    config
  );

  final LdapConnectionPool pool = new LdapConnectionPool(factory);
  pool.setTestOnBorrow(configuration.isPoolTestOnBorrow());
  pool.setTestOnReturn(configuration.isPoolTestOnReturn());
  pool.setTestWhileIdle(configuration.isPoolTestWhileIdle());

  pool.setMaxActive(configuration.getPoolMaxActive());
  pool.setMaxIdle(configuration.getPoolMaxIdle());
  pool.setMinIdle(configuration.getPoolMinIdle());
  pool.setMaxWait(configuration.getPoolMaxWait());

  switch (configuration.getPoolWhenExhaustedAction()) {
    case BLOCK:
      pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_BLOCK);
      break;
    case FAIL:
      pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_FAIL);
      break;
    case GROW:
      pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_GROW);
      break;
    default:
      pool.setWhenExhaustedAction(LdapConnectionPool.DEFAULT_WHEN_EXHAUSTED_ACTION);
  }

  return pool;
}
 
Example #5
Source File: LDAPConnectionService.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of LdapNetworkConnection, configured as required
 * to use the given encryption method to communicate with the LDAP server
 * at the given hostname and port. The returned LdapNetworkConnection is
 * configured for use but is not yet connected nor bound to the LDAP
 * server. It will not be bound until a bind operation is explicitly
 * requested, and will not be connected until it is used in an LDAP
 * operation (such as a bind).
 *
 * @param host
 *     The hostname or IP address of the LDAP server.
 *
 * @param port
 *     The TCP port that the LDAP server is listening on.
 *
 * @param encryptionMethod
 *     The encryption method that should be used to communicate with the
 *     LDAP server.
 *
 * @return
 *     A new instance of LdapNetworkConnection which uses the given
 *     encryption method to communicate with the LDAP server at the given
 *     hostname and port.
 *
 * @throws GuacamoleException
 *     If the requested encryption method is actually not implemented (a
 *     bug).
 */
private LdapNetworkConnection createLDAPConnection(String host, int port,
        EncryptionMethod encryptionMethod) throws GuacamoleException {

    LdapConnectionConfig config = new LdapConnectionConfig();
    config.setLdapHost(host);
    config.setLdapPort(port);

    // Map encryption method to proper connection and socket factory
    switch (encryptionMethod) {

        // Unencrypted LDAP connection
        case NONE:
            logger.debug("Connection to LDAP server without encryption.");
            break;

        // LDAP over SSL (LDAPS)
        case SSL:
            logger.debug("Connecting to LDAP server using SSL/TLS.");
            config.setUseSsl(true);
            break;

        // LDAP + STARTTLS
        case STARTTLS:
            logger.debug("Connecting to LDAP server using STARTTLS.");
            config.setUseTls(true);
            break;

        // The encryption method, though known, is not actually
        // implemented. If encountered, this would be a bug.
        default:
            throw new GuacamoleUnsupportedException("Unimplemented encryption method: " + encryptionMethod);

    }

    return new LdapNetworkConnection(config);

}