Search in sources :

Example 1 with TrustStoreTrustManager

use of com.unboundid.util.ssl.TrustStoreTrustManager 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)

Aggregations

LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)1 HostNameSSLSocketVerifier (com.unboundid.util.ssl.HostNameSSLSocketVerifier)1 SSLUtil (com.unboundid.util.ssl.SSLUtil)1 TrustStoreTrustManager (com.unboundid.util.ssl.TrustStoreTrustManager)1 SocketFactory (javax.net.SocketFactory)1