Hi,

I am trying to find the way to connect my program to my LDAPS Netscape 
Server, but I cannot find the way to do it...

This is my code...


import netscape.ldap.*;

public class SSLSample {

        String host;
        String user;
        String password;

        public static final int SSL_PORT = 636;
        public static final String FILTER = "&(objectclass=inetOrgPerson)(cn=";
        public static final String BASEDN = "o=mycompany";

        SSLSample(String h, String u, String p){
                host = h;
                user = u;
                password = p;
        }

        void run(){
                LDAPConnection ld = null;
                String dn = null;
                try {
                        ld = new LDAPConnection(new LDAPSSLSocketFactory());
// 
                ld.connect(host, SSL_PORT);
                        ld.getSocketFactory().makeSocket(host, SSL_PORT);
                        String filter = FILTER + user + ")";
                        LDAPSearchResults res = ld.search (BASEDN, LDAPv2.SCOPE_SUB,
                                        filter, null, false);
                        if (res != null && res.hasMoreElements ()){
                                        LDAPEntry entry = res.next();
                                        dn = entry.getDN();
                        }
                        ld.authenticate(dn, password);
                        System.out.println("User authenticated: " + dn);
                } catch(LDAPException e){
                        e.printStackTrace();
                } catch(Exception e2){
                        e2.printStackTrace();
                } finally {
                        try {
                                ld.finalize();
                        } catch (Exception ex) { }
                }


        }

        public static void main(String [] args){

                if (args.length != 3){
                        System.out.println("Usage: SSLSample <server> <user> 
<passwd>");
                        System.exit(-1);
                }
                SSLSample s = new SSLSample(args[0], args[1], args[2]);
                try {
                        s.run();
                } catch (Exception e){
                        e.printStackTrace();
                }
        }
}

And this is my execution result:

c:\>java SSLSample server user passwd
netscape.ldap.LDAPException: Failed to create SSL socket (91); Cannot 
connect to
  the LDAP server
         at 
netscape.ldap.LDAPSSLSocketFactory.makeSocket(LDAPSSLSocketFactory.ja
va:309)
         at SSLSample.run(SSLSample.java:26)
         at SSLSample.main(SSLSample.java:57)


Reply via email to