0

How can I call a SSL connection on a:

com.unboundid.ldap.sdk.migrate.ldapjdk.LDAPConnection; ?

The following:

SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
LDAPConnection ldp = new LDAPConnection(sslUtil.createSSLSocketFactory(), getHost(), getPort(), getAuthid(), getAuthpw());  

only works with:

import com.unboundid.ldap.sdk.LDAPConnection;

However, I would like to stick to the migrated ldapjdk connection, if at all possible.

Thank you,

ltalhouarne
  • 4,586
  • 2
  • 22
  • 31

1 Answers1

3

When using a com.unboundid.ldap.sdk.migrate.ldapjdk.LDAPConnection, one of the constructors allows you to specify a com.unboundid.ldap.sdk.migrate.ldapjdk.LDAPSocketFactory instance that will be used to create the underlying sockets. Further, you can use the com.unboundid.ldap.sdk.migrate.ldapjdk.JavaToLDAPSocketFactory class as an LDAPSocketFactory that wraps a javax.net.SocketFactory (of which javax.net.ssl.SSLSocketFactory is a subclass).

The code to do this should be something like:

 SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
 SSLSocketFactory sslSocketFactory = sslUtil.createSSLSocketFactory();
 JavaToLDAPSocketFactory ldapSocketFactory = 
      new JavaToLDAPSocketFactory(sslSocketFactory);
 LDAPConnection ldp = new LDAPConnection(ldapSocketFactory);

Note that for code you actually intend to use in real-world applications, you should probably use a better trust manager than one that blindly trusts any certificate presented by the server, since the TrustAllTrustManager doesn't do anything to help prevent man-in-the-middle attacks. But the TrustAllTrustManager is a convenient first step to verify that you can get secure communication working before switching to some strong validation with something like the TrustStoreTrustManager.

Neil

Neil Wilson
  • 1,706
  • 8
  • 4
  • This is exactly what I was looking for. And, yes the TrustAllTrustManager was just for testing purposes. I appreciate your time, thank you! – ltalhouarne Mar 27 '14 at 15:04