Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connection refused error with LDAP?

I am trying to run following program:

package jndi;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;


public class LDAPRead {

    public static void main(String[] args) {

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=jaydeetechnology");
        try{
            System.out.println("creating initial directory context");
            DirContext ctx = (DirContext) new InitialContext(env);
            System.out.println("search for john hunt");
            Attributes attrs = ctx.getAttributes("cn=John Hunt , ou=JayDeeTechnology");
            System.out.println("find the surname and print it");
            System.out.println("sn: "+attrs.get("sn").get());
            ctx.close();
        }catch(NamingException e){
            e.printStackTrace();
        }
    }

}

but I am getting 'Connection refused' error. Could any one please help me if I am missing something?

creating initial directory context
javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:222)
    at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:130)
    at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1592)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2664)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:305)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:187)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:205)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:148)
    at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:78)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:235)
    at javax.naming.InitialContext.initializeDefaultInitCtx(InitialContext.java:318)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:348)
    at javax.naming.InitialContext.internalInit(InitialContext.java:286)
    at javax.naming.InitialContext.<init>(InitialContext.java:211)
    at jndi.LDAPRead.main(LDAPRead.java:31)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:383)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:245)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:232)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
    at java.net.Socket.connect(Socket.java:539)
    at java.net.Socket.connect(Socket.java:488)
    at java.net.Socket.<init>(Socket.java:385)
    at java.net.Socket.<init>(Socket.java:199)
    at com.sun.jndi.ldap.Connection.createSocket(Connection.java:364)
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:199)
    ... 14 more

I am using RSA 8.0

like image 806
Mike Avatar asked Oct 31 '11 19:10

Mike


1 Answers

From the Adobe LDAP Troubleshooting pages:

Error: javax.naming.CommunicationException: [server]:[port] [Root exception is java.net.ConnectException: Connection refused: connect]

Cause: The port name you have specified for the LDAP/AD server is incorrect.

I'd say your using the wrong hostname, the wrong port number, or haven't started you LDAP installation on that server yet.

Try looking in the LDAP server's logs, perhaps you can learn a bit more from there.

like image 124
Edwin Buck Avatar answered Sep 30 '22 09:09

Edwin Buck