use of org.forgerock.opendj.ldap.SSLContextBuilder in project OpenAM by OpenRock.
the class ServiceBase method getLDAPConnection.
/**
* Returns a LDAP connection to the directory host.
*
* @param dsHostName name of the sever where DS is installed
* @param dsPort port at which the directory server is listening
* @param dsProtocol protocol used by directory server
* @param dsManager admin user name for directory server
* @param dsAdminPwd admin password used by admin user name
* @return LDAP connection
*/
protected static Connection getLDAPConnection(String dsHostName, int dsPort, String dsProtocol, String dsManager, String dsAdminPwd) {
try {
// All connections will use authentication
Options options = Options.defaultOptions().set(CONNECT_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS)).set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray()));
if (dsProtocol.equalsIgnoreCase("ldaps")) {
options = options.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
}
ConnectionFactory factory = new LDAPConnectionFactory(dsHostName, dsPort, options);
return factory.getConnection();
} catch (Exception ignored) {
return null;
}
}
Aggregations