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);
}
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);
}
}
Aggregations