Error connecting to LDAP?

I am trying to run the 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 get a Connection Connection error. Can someone help me if I missed 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

+4
source share
2 answers

On 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 would say that you are using the wrong host name, the wrong port number, or have not yet started the LDAP installation on this server.

Try looking in the LDAP server logs, maybe you can learn a little more from there.

+1
source

โ€œConnection failedโ€ has the same meaning as everywhere else. Nothing was heard on the IP port you were trying to connect to. Either the service did not start, or you have the wrong IP address or port.

0
source

Source: https://habr.com/ru/post/1379014/


All Articles