[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Unable to connect to OpenLDAP over SSL



Now I am using Novell JLDAP API instead of Netscape LDAP SDK to connect to
LDAP server over SSL.

Below is my source code:

  public static void main(String[] args) {
    String str_ldapsHost = "ldap.openldap.org";
    int i_ldapsPort = 636;
    String str_baseDN = "cacertificate=New,o=ascertia.com.pk";
//    performLdapSearchUsingNetscape(str_ldapsHost, i_ldapsPort, str_baseDN,
false);
    performLdapSearchUsingNovell(str_ldapsHost, i_ldapsPort, str_baseDN,
true);
  }

  public static void performLdapSearchUsingNovell(String a_strHost, int
a_iPort, String a_strBaseDN, boolean a_bUseSSL){
    try{
      com.novell.ldap.LDAPConnection obj_connection = null;
      if( a_bUseSSL ){
        System.out.println("Adding Security Providers ...");
        java.security.Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());

System.getProperties().put("java.protocol.handler.pkgs","com.sun.net.ssl.int
ernal.www.protocol");

        System.out.println("Connecting to LDAPS server
"+a_strHost+":"+a_iPort);
        com.novell.ldap.LDAPJSSESecureSocketFactory obj_sslSocketFactory =
new com.novell.ldap.LDAPJSSESecureSocketFactory();
        obj_connection = new
com.novell.ldap.LDAPConnection(obj_sslSocketFactory);
      }
      else{
        System.out.println("Connecting to LDAP server
"+a_strHost+":"+a_iPort);
        obj_connection = new com.novell.ldap.LDAPConnection();
      }
      obj_connection.connect( a_strHost, a_iPort );
      System.out.println("Connection to LDAP server
"+a_strHost+":"+a_iPort+" is successful");

      System.out.println("Perfoming LDAP search ...");
      com.novell.ldap.LDAPSearchResults obj_ldapResults =
obj_connection.search(a_strBaseDN, com.novell.ldap.LDAPConnection.SCOPE_SUB,
"objectclass=*", null, false);
     System.out.println("LDAP Results Found : "+obj_ldapResults.getCount());
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

Here is output of the program:

Adding Security Providers ...
Connecting to LDAPS server ldap.openldap.org:636
Connection to LDAP server ldap.openldap.org:636 is successful
Perfoming LDAP search ...
LDAPException: I/O Exception on host ldap.openldap.org, port 636 (91)
Connect Error
java.net.SocketException: Socket closed
 at com.novell.ldap.Connection.writeMessage(Unknown Source)
 at com.novell.ldap.Connection.writeMessage(Unknown Source)
 at com.novell.ldap.Message.sendMessage(Unknown Source)
 at com.novell.ldap.MessageAgent.sendMessage(Unknown Source)
 at com.novell.ldap.LDAPConnection.search(Unknown Source)
 at com.novell.ldap.LDAPConnection.search(Unknown Source)
 at com.novell.ldap.LDAPConnection.search(Unknown Source)
 at
com.ascertia.ldapclient.ASC_LDAPConnector.performLdapSearchUsingNovell(ASC_L
DAPConnector.java:35)
 at
com.ascertia.ldapclient.ASC_LDAPConnector.main(ASC_LDAPConnector.java:12)

I have also tested the same program with my local Netscape Directory Server
v4.2, but got the same results. Any help or ideas would be highly
appreciated.
Thanx.

Regards,
Yasir

----- Original Message -----
From: "Jon Roberts" <man@mentata.com>
To: "Yasir Khan" <yasir.khan@ascertia.com>
Cc: <openldap-software@OpenLDAP.org>
Sent: Tuesday, February 24, 2004 8:22 PM
Subject: Re: Unable to connect to OpenLDAP over SSL


> Yasir Khan wrote:
> > I am using Netscape LDAP Java SDK 4.1. I am trying to connect to online
> > OpenLDAP server running over SSL. LDAP Browser is successfully connected
> > to the OpenLDAP server over SSL. But every time when I run my own code I
> > get the following  error.
>
> To spare Kurt another post, I'll point out that unless this is an issue
> with OpenLDAP failing to provide SSL connections properly (a
> misconfiguration you could demonstrate with ldapsearch), this post is
> *off-topic*. Try posting to the netscape.public.mozilla.directory list
> on news.mozilla.org.
>
> To bring it on topic, you could do the same thing with the (better IMHO)
> Novell JLDAP libraries with the following:
>
> System.out.println("Creating LDAPS Connection");
> LDAPConnection m_ldpCon = new LDAPConnection( new
> LDAPJSSESecureSocketFactory() );
> m_ldpCon.connect("ldap.mydomain.org", 636);
>
> Jon Roberts
> www.mentata.com
>