0
我想使用信任库文件通过SSL连接到ldap。 我使用下面的代码:SSL Ldap连接(ldaps)
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;
}
的问题是,我不希望使用的信任文件的位置,我想使用的InputStream(文件内容),有没有什么办法去做?比如在使用SSLContext来取消https连接时。
我不明白的问题。 “信任库的位置”与“输入流”无关。请澄清。 – EJP
我希望能够通过给予输入流而不是文件的位置来设置trustore参数值,如下所示: 'System.setProperty(“javax.net.ssl.trustStore”,ldap_trust_store_file); System.setProperty(“javax.net.ssl.trustStorePassword”, ldap_trust_store_pwd);' – callafa
我不知道任何规定的输入流如你所需。 java.naming.ldap.factory.socket命名为套接字工厂类,如JNDI文档中所述。你有什么问题? – EJP