第一步:执行命令导入服务器上的证书
keytool -import -trustcacerts -alias umapad-ssl -file f:/ssl-ldap.cer -keystore "e:/ssl-ldap-mapad.jks"
第二步:在代码中设置信任证书库及证书库口令
System.setProperty("javax.net.ssl.trustStore", "e:/ssl-ldap-umapad.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");第三步:获取LDAPcontext
env.put(Context.PROVIDER_URL, "ldaps://10.21.16.189:636");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "zhangsan@abc.com"); env.put(Context.SECURITY_CREDENTIALS, "123qwe!@#QWE"); env.put(Context.SECURITY_PROTOCOL, "ssl"); LdapContext context = new InitialLdapContext(env,null);