J'essaie d'exécuter le programme suivant :
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();
}
}
}
mais je reçois l'erreur "Connexion refusée". Est-ce que quelqu'un pourrait m'aider si j'ai raté quelque chose ?
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
J'utilise RSA 8.0