use of org.forgerock.opendj.ldap.LDAPOptions in project admin-console-beta by connexta.
the class LdapTestingUtils method getLdapConnection.
/**
* Attempts to connect to the given ldap address given the hostname, port, and encryptionMethod
*
* Possible message types: CANNOT_CONFIGURE, CANNOT_CONNECT
* @return
*/
public LdapConnectionAttempt getLdapConnection(LdapConnectionField connection) {
LDAPOptions ldapOptions = new LDAPOptions();
try {
if (connection.encryptionMethod().equals(LDAPS)) {
ldapOptions.setSSLContext(SSLContext.getDefault());
} else if (connection.encryptionMethod().equals(START_TLS)) {
ldapOptions.setUseStartTLS(true);
}
ldapOptions.addEnabledCipherSuite(System.getProperty("https.cipherSuites").split(","));
ldapOptions.addEnabledProtocol(System.getProperty("https.protocols").split(","));
//sets the classloader so it can find the grizzly protocol handler class
ldapOptions.setProviderClassLoader(LdapTestingUtils.class.getClassLoader());
} catch (Exception e) {
LOGGER.debug("Error prepping LDAP connection", e);
return new LdapConnectionAttempt(CANNOT_CONFIGURE);
}
Connection ldapConnection;
try {
ldapConnection = new LDAPConnectionFactory(connection.hostname(), connection.port(), ldapOptions).getConnection();
} catch (Exception e) {
LOGGER.debug("Error opening LDAP connection to [{}:{}]", connection.hostname(), connection.port());
return new LdapConnectionAttempt(CANNOT_CONNECT);
}
return new LdapConnectionAttempt(ldapConnection);
}
Aggregations