IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Authentification LDAP avec Java


Sujet :

Java

  1. #1
    Membre habitué

    Homme Profil pro
    Ingénieur Informaticien
    Inscrit en
    Juillet 2010
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Ingénieur Informaticien
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juillet 2010
    Messages : 22
    Points : 178
    Points
    178
    Par défaut Authentification LDAP avec Java
    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");
        }}

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    383
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 383
    Points : 468
    Points
    468
    Par défaut
    Bonjour,

    Le message d'erreur "Proxy can't contact remote server" semble indiquer que le serveur LDAP n'est pas accessible depuis l'endroit où le programme s'exécute.
    Quelle valeur tu as mis pour ldapUrl ?

Discussions similaires

  1. Ldap avec java et userPassword
    Par kenjiamo dans le forum Général Java
    Réponses: 2
    Dernier message: 28/03/2009, 21h24
  2. [LDAP] Authentification LDAP avec Active Directory
    Par sco_didier dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 20/01/2009, 16h36
  3. connexion a ldap avec java
    Par himachalene dans le forum API standards et tierces
    Réponses: 4
    Dernier message: 05/12/2006, 19h15
  4. Réponses: 3
    Dernier message: 14/03/2006, 11h38
  5. [LDAP] recherche dans differents container LDAP avec Java
    Par touinth dans le forum Autres SGBD
    Réponses: 2
    Dernier message: 01/07/2004, 16h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo