【发布时间】:2013-08-29 09:54:06
【问题描述】:
我想使用信任库文件通过 SSL 连接到 ldap。 我正在使用以下代码:
private DirContext ctxtDir = null;
Attributes attributes = null;
ldap_server_url = "ldaps://" + getLdapHostName() + ":"
+ getPort() + "/";
ldap_base_dn = getBaseDn();
ldap_user = getLogin();
ldap_password = getPwd();
ldap_trust_store_file = "C:\\truststore.jks";
ldap_trust_store_pwd = getStoreJKSPwd();
// Set the parameters
env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, ldap_context_factory);
env.put(Context.PROVIDER_URL, ldap_server_url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, ldap_user);
env.put(Context.SECURITY_CREDENTIALS, ldap_password);
env.put(Context.SECURITY_PROTOCOL, "SSL");
// Set SSL parameters for Ldaps connection
System.setProperty("javax.net.ssl.trustStore", ldap_trust_store_file);
System.setProperty("javax.net.ssl.trustStorePassword",
ldap_trust_store_pwd);
// Try to establish the connection
try {
// create initial context
ctxtDir = new InitialDirContext(env);
attributes = getLdapattributes(ldap_base_dn);
if (null != attributes) {
isAvailable = true;
}
} catch (Exception e) {
isAvailable = false;
}
问题是我不想使用信任库文件的位置,我想使用输入流(文件内容),有什么办法吗?就像使用 SSLContext 建立 https 连接时一样。
【问题讨论】:
-
我不明白这个问题。 “信任库的位置”与“输入流”无关。请澄清。
-
我希望能够通过提供输入流而不是文件的位置来设置 trustore 参数值:
System.setProperty("javax.net.ssl.trustStore", ldap_trust_store_file); System.setProperty("javax.net.ssl.trustStorePassword", ldap_trust_store_pwd); -
我不知道您需要输入流的任何规定。
java.naming.ldap.factory.socket命名套接字工厂类,如 JNDI 文档中所述。你有什么问题?
标签: ssl connection ldap