LDAP over SSL

Discussion in 'Java' started by John Smith, Jul 22, 2003.

  1. John Smith

    John Smith Guest

    I'm trying to make a ldap connection using SSL well I'm not sure why I am
    getting the following message. If anyone could help me out.

    ==============
    command prompt
    ==============
    Starting to execute
    Binding...
    javax.naming.CommunicationException: pitt-auth-07.srv.cssd.pitt.edu:636.
    Root exception is java.net
    ..SocketException: Default SSL context init failed: null
    at javax.net.ssl.DefaultSSLSocketFactory.createSocket(DashoA6275)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
    )
    at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    ..java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.sun.jndi.ldap.Connection.createSocket(Connection.java:311)
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:181)
    at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:119)
    at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1668)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2556)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:275)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:173)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:191)
    at
    com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
    at
    com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
    at javax.naming.InitialContext.init(InitialContext.java:219)
    at javax.naming.InitialContext.<init>(InitialContext.java:195)
    at
    javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:80)
    at LDAPConn.bindAs(LDAPConn.java:45)
    at LDAPConn.main(LDAPConn.java:66)
    Fininished....!

    ==========
    code snip
    ==========
    public void bindAs ( String principal, String credentials, String baseDN) {
    env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");

    env.put(Context.SECURITY_AUTHENTICATION, "simple");

    env.put(Context.REFERRAL, "ignore");
    env.put(Context.SECURITY_PROTOCOL, "ssl");
    //THE LOCATION OF THE CACERTS MUST BE SPECIFIED
    java.security.Security.addProvider(new
    com.sun.net.ssl.internal.ssl.Provider());
    System.setProperty("javax.net.ssl.keyStore",
    "c:\\j2sdk1.4.0_01\\jre\\lib\\security\\cacerts");
    System.setProperty("javax.net.ssl.trustStore",
    "c:\\j2sdk1.4.0_01\\jre\\lib\\security\\cacerts");
    System.setProperty("javax.net.ssl.trustStoreType", "jks");
    env.put(Context.PROVIDER_URL, baseDN );
    env.put(Context.SECURITY_PRINCIPAL, principal);
    env.put(Context.SECURITY_CREDENTIALS, credentials);
    DirContext ctx = null;
    try {
    ctx = new InitialDirContext(env);
    System.out.println("bind Successful...");
    ctx.close();
    } catch(AuthenticationException aex) {
    System.out.println("Invalid userid or password... Please try again");
    } catch (Exception ex) {
    ex.printStackTrace();
    }

    } // bindAs


    public static void main(String[] args) {
    String principal = "user name";
    String credentials = "password";
    String baseDN = "ldap://ldaphost:636";
    System.out.println("Starting to execute");
    LDAPConn testUser = new LDAPConn();
    System.out.println("Binding...");
    testUser.bindAs( principal, credentials, baseDN );
    System.out.println( "Fininished....!");
    } // main
    John Smith, Jul 22, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,557
    iksrazal
    Apr 25, 2004
  2. Replies:
    1
    Views:
    514
    Raymond DeCampo
    Feb 21, 2006
  3. Robert
    Replies:
    2
    Views:
    1,944
    Robert
    Jun 10, 2004
  4. rcmn
    Replies:
    1
    Views:
    326
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Nov 6, 2006
  5. Amos
    Replies:
    0
    Views:
    83
Loading...

Share This Page