简体   繁体   中英

UnboundID, LDAP jdk migration

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,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM