Refer to the code below. It works fine on Windows and Mac but not on Linux. It does not call the MySSLSocketFactory class and as a result, the cert is not trusted. Any suggestions???
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class LdapBaseDN {
public static void main(String[] args) {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "none");
env.put(Context.PROVIDER_URL, "ldaps://MyServerIP:636");
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.REFERRAL, "follow");
env.put("java.naming.ldap.factory.socket", MySSLSocketFactory.class.getName()); //MySSLSocketFactory does not get called on Linux
try {
DirContext ldapContext = new InitialDirContext(env);
System.out.println("Connected successfully ");
} catch (Exception e) {
e.printStackTrace(); //SSLHandshake fails because Cert is not trusted on Linux
}
}
}