Search in sources :

Example 11 with SSLUtil

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

SSLUtil (com.unboundid.util.ssl.SSLUtil)11 TrustAllTrustManager (com.unboundid.util.ssl.TrustAllTrustManager)7 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)5 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)4 BindRequest (com.unboundid.ldap.sdk.BindRequest)3 FailoverServerSet (com.unboundid.ldap.sdk.FailoverServerSet)3 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)3 KeyStoreKeyManager (com.unboundid.util.ssl.KeyStoreKeyManager)3 TrustStoreTrustManager (com.unboundid.util.ssl.TrustStoreTrustManager)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)2 Modification (com.unboundid.ldap.sdk.Modification)2 StartTLSExtendedRequest (com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest)2 SocketFactory (javax.net.SocketFactory)2 Cleanup (lombok.Cleanup)2 SneakyThrows (lombok.SneakyThrows)2 lombok.val (lombok.val)2 BindConnectionInitializer (org.ldaptive.BindConnectionInitializer)2 Credential (org.ldaptive.Credential)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1