我在JSP应用程序中连接到LDAP服务器时遇到问题。我正在GlassFish v2上运行该应用程序。以下代码在控制台应用程序中运行良好,但在jsp中使用时失败:
java.security.Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("javax.net.ssl.trustStore",
"C:\\Users\\Projects\\npope-PostiniSSO\\PostiniSSO\\ssltest.keystore");
LDAPJSSESecureSocketFactory ssf = new LDAPJSSESecureSocketFactory();
LDAPConnection conn = new LDAPConnection(ssf);
conn.connect( ldapHost, sslPort);
引发的异常是:
LDAPException: Unable to connect to server 192.168.254.128:636 (91) Connect Error java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
class com.novell.ldap.LDAPException
我怀疑我缺少证书或配置,但找不到任何好的信息。
答案 0 :(得分:1)
我缺少以下几行来设置GlassFish所需的属性:
System.setProperty("javax.net.ssl.keyStore",
"C:\\Users\\Nathan\\Projects\\npope-PostiniSSO\\PostiniSSO\\ssltest.keystore");
System.setProperty("javax.net.ssl.trustStorePassword",
"password");
System.setProperty("javax.net.ssl.keyStorePassword",
"password");