views:

407

answers:

1

I am having trouble connecting to an LDAP server in my JSP application. I am running the application on GlassFish v2. The following code works well in a console application but fails when used in the 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);

The exception that is thrown is:

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

I suspect that I am missing a certificate or bit of configuration but cannot find any good info.

+1  A: 

I was missing the following lines to set properties which are needed by 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");
ProgrammingPope