Connecting to LDAP over SSL

See below for enabling SSL in an existing JNDIDirectory connection.

Selecting the SSL certificates

Get Trusted SSL X509 Certificates from the location of your choice

X509Certificate trustedcerts[] =
(X509Certificate[])certlist.toArray(new X509Certificate[]{});

Create an LDAPSConfig object to specify the SSL parameters.

LDAPSConfig sslconfig = new LDAPSConfig(true);

Where true enables LDAP over SSL using the following scheme.

ldaps://

Specify the trusted SSL certificates.

sslconfig.addTrustCerts(trustedcerts);

Setting the SSL configuration

Create the JNDIDirectory object either in the usual manner:

JNDIDirectory dir= new JNDIDirectory(directory,Integer.parseInt(port));

...or with the new constructor;

JNDIDirectory dir = new JNDIDirectory("ldaps://myLDAPSHost.com:636");

Set the SSL configuration.

dir.setLDAPSConfig(sslconfig);