Bonjour à tous
Je débute sur LDAP en java, j'ai ecrit une classe pour l'authentification. Tout va bien. Mais lorsque je veux faire un bind, j'ai une erreur:
J'apprécierais vraiment votre aide.

voici l'erreur:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
run:
Jan 17, 2013 10:09:33 AM interfaces.LdapAuthentication authenticate
SEVERE: null
javax.naming.ServiceUnavailableException: [LDAP: error code 52 - Proxy can't contact remote server]; remaining name 'cn=Etudiant,dc=mydomain,dc=com'
	at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3097)
	at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2978)
	at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2785)
	at com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:410)
	at com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:367)
	at com.sun.jndi.toolkit.ctx.ComponentContext.p_bind(ComponentContext.java:614)
	at com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(PartialCompositeContext.java:201)
	at com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(PartialCompositeContext.java:191)
	at javax.naming.InitialContext.bind(InitialContext.java:419)
	at interfaces.LdapAuthentication.authenticate(LdapAuthentication.java:64)
	at interfaces.LdapAuthentication.main(LdapAuthentication.java:81)
BUILD SUCCESSFUL (total time: 5 seconds)

Mon code est le suivant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaces;
 
import beans.Etudiant;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import ldapauthenticate.LdapAuthenticate;
//import javax.naming.directory.SchemaViolationException;
 
/**
 *
 * @author Wanki
 */
public class LdapAuthentication implements IAuthenticate {
 
    private static final String INITIAL_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
    private String base;
    private String dn;
    private String ldapUrl;
    private String securityType;
    private Hashtable<String, String> environnement;
 
    /**
     *
     * @param base qui est la base utilisée par l'annuaire
     * @param ldapUrl qui est l'url pour localiser l'annuaire
     * @param securityType qui est le mode de sécurité utilisé par ldap (simple,
     * SSL, SASL) pour la transaction des informations vers l'annuaire
     */
    public LdapAuthentication(String base, String ldapUrl, String securityType) {
        this.base = base;
        this.ldapUrl = ldapUrl;
        this.securityType = securityType;
        this.environnement = new Hashtable();
    }
 
    /**
     *
     * @param name cn de l'utilisateur
     * @param password mot de passe de l'utilisateur
     */
    @Override
    public boolean authenticate(String name, String password) {
        boolean isDone = false;
        this.dn = "cn=" + name + "," + this.base;
        this.environnement.put(Context.INITIAL_CONTEXT_FACTORY, this.INITIAL_CONTEXT_FACTORY);
        this.environnement.put(Context.PROVIDER_URL, this.ldapUrl);
        this.environnement.put(Context.SECURITY_AUTHENTICATION, this.securityType);
        this.environnement.put(Context.SECURITY_PRINCIPAL, this.dn);
        this.environnement.put(Context.SECURITY_CREDENTIALS, password);
        try {
            DirContext authContext = new InitialDirContext(this.environnement);
            isDone = true;
            Etudiant etudiant = new Etudiant("jacque", "secret", 22, "GM");
            authContext.bind("cn=Etudiant,dc=mydomain,dc=com", etudiant);
            authContext.close();
        } catch (AuthenticationException ae) {
            Logger.getLogger(LdapAuthenticate.class.getName()).log(Level.SEVERE, null, ae);
        } catch (NamingException ex) {
            Logger.getLogger(LdapAuthenticate.class.getName()).log(Level.SEVERE, null, ex);
        }
        return isDone;
    }
 
    public static void main(String[] args) {
        // TODO code application logic here
        LdapAuthentication ldapAuthentication = new LdapAuthentication("dc=mydomain,dc=com", "ldap://ordinateur-pc:389", "simple");
        ldapAuthentication.authenticate("Manager", "password");
    }}