Search in sources :

Example 21 with Options

use of org.forgerock.util.Options in project ddf by codice.

the class LdapLoginConfig method createLdapConnectionFactory.

protected ConnectionFactory createLdapConnectionFactory(String url, Boolean startTls) {
    boolean useSsl = url.startsWith("ldaps");
    boolean useTls = !url.startsWith("ldaps") && startTls;
    Options lo = Options.defaultOptions();
    try {
        if (useSsl || useTls) {
            LOGGER.trace("Setting up secure LDAP connection.");
            initializeSslContext();
            lo.set(LDAPConnectionFactory.SSL_CONTEXT, sslContext);
        } else {
            LOGGER.trace("Setting up insecure LDAP connection.");
        }
    } catch (GeneralSecurityException e) {
        LOGGER.info("Error encountered while configuring SSL. Secure connection will fail.", e);
    }
    lo.set(LDAPConnectionFactory.HEARTBEAT_TIMEOUT, new Duration(30L, TimeUnit.SECONDS));
    lo.set(LDAPConnectionFactory.HEARTBEAT_INTERVAL, new Duration(60L, TimeUnit.SECONDS));
    lo.set(LDAPConnectionFactory.CONNECT_TIMEOUT, new Duration(30L, TimeUnit.SECONDS));
    lo.set(LDAPConnectionFactory.SSL_USE_STARTTLS, useTls);
    String cipherSuites = System.getProperty(SecurityConstants.HTTPS_CIPHER_SUITES);
    if (cipherSuites != null) {
        lo.set(LDAPConnectionFactory.SSL_ENABLED_CIPHER_SUITES, Arrays.asList(cipherSuites.split(",")));
    }
    String protocols = System.getProperty(HTTPS_PROTOCOLS);
    if (protocols != null) {
        lo.set(LDAPConnectionFactory.SSL_ENABLED_PROTOCOLS, Arrays.asList(protocols.split(",")));
    }
    lo.set(LDAPConnectionFactory.TRANSPORT_PROVIDER_CLASS_LOADER, SslLdapLoginModule.class.getClassLoader());
    LDAPUrl parsedUrl = LDAPUrl.valueOf(url);
    String host = parsedUrl.getHost();
    Integer port = parsedUrl.getPort();
    auditRemoteConnection(host);
    return new LDAPConnectionFactory(host, port, lo);
}
Also used : Options(org.forgerock.util.Options) LDAPUrl(org.forgerock.opendj.ldap.LDAPUrl) GeneralSecurityException(java.security.GeneralSecurityException) Duration(org.forgerock.util.time.Duration) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory)

Example 22 with Options

use of org.forgerock.util.Options in project ddf by codice.

the class ClaimsHandlerManager method createConnectionFactory.

protected ConnectionFactory createConnectionFactory(List<String> urls, Boolean startTls, String loadBalancingAlgorithm) throws LdapException {
    List<ConnectionFactory> connectionFactories = new ArrayList<>();
    for (String singleUrl : urls) {
        connectionFactories.add(createLdapConnectionFactory(new PropertyResolver(singleUrl).toString(), startTls));
    }
    Options options = Options.defaultOptions();
    if (FAILOVER.equalsIgnoreCase(loadBalancingAlgorithm)) {
        return Connections.newFailoverLoadBalancer(connectionFactories, options);
    } else {
        return Connections.newRoundRobinLoadBalancer(connectionFactories, options);
    }
}
Also used : Options(org.forgerock.util.Options) ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) ArrayList(java.util.ArrayList) PropertyResolver(org.codice.ddf.configuration.PropertyResolver)

Aggregations

Options (org.forgerock.util.Options)22 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)16 Duration (org.forgerock.util.time.Duration)14 SSLContextBuilder (org.forgerock.opendj.ldap.SSLContextBuilder)8 ByteString (org.forgerock.opendj.ldap.ByteString)7 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)7 GeneralSecurityException (java.security.GeneralSecurityException)6 LdapException (org.forgerock.opendj.ldap.LdapException)6 IOException (java.io.IOException)4 SimpleBindRequest (org.forgerock.opendj.ldap.requests.SimpleBindRequest)4 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)4 PolicyException (com.sun.identity.policy.PolicyException)3 Connection (org.forgerock.opendj.ldap.Connection)3 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)2 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)2 ShutdownManager (com.sun.identity.common.ShutdownManager)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2