0

请参阅下面的代码。它在 Windows 和 Mac 上运行良好,但在 Linux 上却不行。它不调用 MySSLSocketFactory 类,因此证书不受信任。有什么建议么???

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
        }
    }
}
4

0 回答 0