Search in sources :

Example 1 with LDAPConnectionOptions

use of com.unboundid.ldap.sdk.LDAPConnectionOptions in project keywhiz by square.

the class LdapConnectionFactory method getLDAPConnection.

public LDAPConnection getLDAPConnection(String userDN, String password) throws LDAPException, GeneralSecurityException {
    TrustStoreTrustManager trust = new TrustStoreTrustManager(trustStorePath, trustStorePassword.toCharArray(), trustStoreType, false);
    LDAPConnectionOptions options = new LDAPConnectionOptions();
    options.setSSLSocketVerifier(new HostNameSSLSocketVerifier(false));
    SSLUtil sslUtil = new SSLUtil(trust);
    SocketFactory factory = new EndpointIdentificationSocketFactory(sslUtil.createSSLSocketFactory("TLSv1.2"));
    LDAPConnection ldapConnection = new LDAPConnection(factory, options);
    // Connect, retrieve the DN of the user (if any)
    ldapConnection.connect(server, port);
    ldapConnection.bind(userDN, password);
    return ldapConnection;
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) SSLUtil(com.unboundid.util.ssl.SSLUtil) HostNameSSLSocketVerifier(com.unboundid.util.ssl.HostNameSSLSocketVerifier) TrustStoreTrustManager(com.unboundid.util.ssl.TrustStoreTrustManager) SocketFactory(javax.net.SocketFactory) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection)

Example 2 with LDAPConnectionOptions

use of com.unboundid.ldap.sdk.LDAPConnectionOptions in project oxCore by GluuFederation.

the class LDAPConnectionProvider method init.

/**
	 * This method is used to create LDAPConnectionPool
	 *
	 * @throws NumberFormatException
	 * @throws LDAPException
	 * @throws GeneralSecurityException
	 * @throws EncryptionException
	 * @throws EncryptionException
	 */
public void init(Properties props) throws NumberFormatException, LDAPException, GeneralSecurityException {
    String serverProp = props.getProperty("servers");
    this.servers = serverProp.split(",");
    this.addresses = new String[this.servers.length];
    this.ports = new int[this.servers.length];
    for (int i = 0; i < this.servers.length; i++) {
        String str = this.servers[i];
        this.addresses[i] = str.substring(0, str.indexOf(":")).trim();
        this.ports[i] = Integer.parseInt(str.substring(str.indexOf(":") + 1, str.length()));
    }
    BindRequest bindRequest = null;
    if (StringHelper.isEmpty(props.getProperty("bindDN"))) {
        this.bindDn = null;
        this.bindPassword = null;
        bindRequest = new SimpleBindRequest();
    } else {
        this.bindDn = props.getProperty("bindDN");
        this.bindPassword = props.getProperty("bindPassword");
        bindRequest = new SimpleBindRequest(this.bindDn, this.bindPassword);
    }
    LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
    connectionOptions.setConnectTimeoutMillis(100 * 1000);
    connectionOptions.setAutoReconnect(true);
    this.useSSL = Boolean.valueOf(props.getProperty("useSSL")).booleanValue();
    SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
    FailoverServerSet failoverSet;
    if (this.useSSL) {
        failoverSet = new FailoverServerSet(this.addresses, this.ports, sslUtil.createSSLSocketFactory(SSL_PROTOCOLS[0]), connectionOptions);
    } else {
        failoverSet = new FailoverServerSet(this.addresses, this.ports, connectionOptions);
    }
    int maxConnections = Integer.parseInt(props.getProperty("maxconnections"));
    this.connectionPool = createConnectionPoolWithWaitImpl(props, failoverSet, bindRequest, connectionOptions, maxConnections, sslUtil);
    if (this.connectionPool != null) {
        this.connectionPool.setCreateIfNecessary(true);
        String connectionMaxWaitTime = props.getProperty("connection-max-wait-time");
        if (StringHelper.isNotEmpty(connectionMaxWaitTime)) {
            this.connectionPool.setMaxWaitTimeMillis(Long.parseLong(connectionMaxWaitTime));
        }
    }
    this.binaryAttributes = new ArrayList<String>();
    if (props.containsKey("binaryAttributes")) {
        String[] binaryAttrs = StringHelper.split(props.get("binaryAttributes").toString().toLowerCase(), ",");
        this.binaryAttributes.addAll(Arrays.asList(binaryAttrs));
    }
    log.debug("Using next binary attributes: " + this.binaryAttributes);
    this.supportedLDAPVersion = determineSupportedLdapVersion();
    this.subschemaSubentry = determineSubschemaSubentry();
    this.supportsSubtreeDeleteRequestControl = supportsSubtreeDeleteRequestControl();
    this.creationResultCode = ResultCode.SUCCESS;
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) SSLUtil(com.unboundid.util.ssl.SSLUtil) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) BindRequest(com.unboundid.ldap.sdk.BindRequest) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) FailoverServerSet(com.unboundid.ldap.sdk.FailoverServerSet) TrustAllTrustManager(com.unboundid.util.ssl.TrustAllTrustManager)

Example 3 with LDAPConnectionOptions

use of com.unboundid.ldap.sdk.LDAPConnectionOptions in project zm-mailbox by Zimbra.

the class LdapConnUtil method getConnectionOptions.

static LDAPConnectionOptions getConnectionOptions(LdapServerConfig ldapConfig) {
    LDAPConnectionOptions connOpts = new LDAPConnectionOptions();
    // TODO: expose in LC?
    connOpts.setUseSynchronousMode(true);
    // TODO: expose in LC?
    connOpts.setFollowReferrals(true);
    connOpts.setConnectTimeoutMillis(ldapConfig.getConnectTimeoutMillis());
    connOpts.setResponseTimeoutMillis(ldapConfig.getReadTimeoutMillis());
    connOpts.setAbandonOnTimeout(ldapConfig.isAbandonOnTimeout());
    return connOpts;
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions)

Aggregations

LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)3 SSLUtil (com.unboundid.util.ssl.SSLUtil)2 BindRequest (com.unboundid.ldap.sdk.BindRequest)1 FailoverServerSet (com.unboundid.ldap.sdk.FailoverServerSet)1 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)1 HostNameSSLSocketVerifier (com.unboundid.util.ssl.HostNameSSLSocketVerifier)1 TrustAllTrustManager (com.unboundid.util.ssl.TrustAllTrustManager)1 TrustStoreTrustManager (com.unboundid.util.ssl.TrustStoreTrustManager)1 SocketFactory (javax.net.SocketFactory)1