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

API standards et tierces Java Discussion :

[JNDI]connexion entre jndi et l'annuaire ldap


Sujet :

API standards et tierces Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Septembre 2005
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 7
    Points : 6
    Points
    6
    Par défaut [JNDI]connexion entre jndi et l'annuaire ldap
    Bonjour
    Pouvez- vous m'aider à faire la connexion entre jndi et l'annuaire ldap (j'aimerais récupérer des données de l'annuaire avec jndi).
    je travaille avec WebSphere.
    merci d'avance



    [Modéré par Didier] : ajout de tag dans le titre - Les règles du forum Java

  2. #2
    Membre à l'essai
    Inscrit en
    Mai 2004
    Messages
    10
    Détails du profil
    Informations forums :
    Inscription : Mai 2004
    Messages : 10
    Points : 11
    Points
    11
    Par défaut
    LDAP utilise JNDI

    avec l'exemple ci dessous tu pourras te connecter = Bind sur un annuaire LDAP c'est lorsque tu obtiens ton InitialDirContext

    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
     import javax.naming.*;
    import javax.naming.directory.*;
     
    import java.util.Hashtable;
     
    /**
     * Demonstrates how to create an initial context to an LDAP server
     * using simple authentication.
     *
     * usage: java Simple
     */
    class Simple {
        public static void main(String[] args) {
     
        // Set up environment for creating initial context
        Hashtable env = new Hashtable(11);
        env.put(Context.INITIAL_CONTEXT_FACTORY, 
            "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
     
        // Authenticate as S. User and password "mysecret"
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
        env.put(Context.SECURITY_CREDENTIALS, "mysecret");
     
        try {
            // Create initial context
            DirContext ctx = new InitialDirContext(env);
     
            System.out.println(ctx.lookup("ou=NewHires"));
     
            // do something useful with ctx
     
            // Close the context when we're done
            ctx.close();
        } catch (NamingException e) {
            e.printStackTrace();
        }
        }
    }

  3. #3
    Futur Membre du Club
    Inscrit en
    Septembre 2005
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 7
    Points : 6
    Points
    6
    Par défaut
    Merci fotoweb. J'aimerais avoir une précision;mon but est de récuperer tous les employes du ldap;es ce que ce code convient:
    i
    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
    mport javax.naming.*; 
    import javax.naming.directory.*; 
     
    import java.util.Hashtable; 
     
    /** 
    * Demonstrates how to create an initial context to an LDAP server 
    * using simple authentication. 
    * 
    * usage: java Simple 
    */ 
     
    class Simple { 
    public static void main(String[] args) { 
     
    // Set up environment for creating initial context 
    Hashtable env = new Hashtable(11); 
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); 
     
    // Authenticate as S. User and password "mysecret" 
    env.put(Context.SECURITY_AUTHENTICATION, "simple"); 
    env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=Employe, o=JNDITutorial"); 
    env.put(Context.SECURITY_CREDENTIALS, "mysecret"); 
     
    try { 
    // Create initial context 
    DirContext ctx = new InitialDirContext(env); 
     
    System.out.println(ctx.lookup("ou=Employe")); 
     
    // do something useful with ctx 
     
    String[] attrIDs = {"matricule","nom","prenom","titre","fonction","login","password","email","connecte"};
     
    // Get the attributes requested
     
    Attributes answer = ctx.getAttributes("cn= S. User, ou=Employe",attrIDs);
    For (NamingEnumeration ae = answer.getAll(); ae.hasMore();){
        Attribute attr = (Attribute)ae.next();
        System.out.println("attribute:" + attr.getID());
        /* print each value */
        For (NamingEnumeration e = attr.getAll(); e.hasMore();){
            System.out.println("value:" + e.next());
            }
     
        }
     
    // Close the context when we're done 
    ctx.close(); 
    } catch (NamingException e) { 
    e.printStackTrace(); 
    } 
    } 
    }

    Encore une fois merci.

  4. #4
    Membre à l'essai
    Inscrit en
    Mai 2004
    Messages
    10
    Détails du profil
    Informations forums :
    Inscription : Mai 2004
    Messages : 10
    Points : 11
    Points
    11
    Par défaut
    oui; et ca marche ?

    Mais bon comme il ne s'agit pas d'une transaction si jamais il y a bc d'infos à récuperer tu peux peut être les récupérer par groupe de 100, je ne suis pas sur que tu puisse récupérer 10000 users d'un coup ... ca n'est pas une base oracle en terme de perf un ldap

  5. #5
    Futur Membre du Club
    Inscrit en
    Septembre 2005
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Septembre 2005
    Messages : 7
    Points : 6
    Points
    6
    Par défaut
    Merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [JNDI] Afficher les groupes d'un annuaire LDAP
    Par caro_caro dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 08/09/2009, 23h14
  2. Insérer une entrée dans un annuaire LDAP via JNDI
    Par caro_caro dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 31/07/2009, 17h48
  3. connexion SSH appuye sur un annuaire LDAP
    Par Toeic dans le forum Réseau
    Réponses: 3
    Dernier message: 31/07/2007, 12h01
  4. [LDAP] Connexion via PHP à un annuaire LDAP sous un serveur Novell
    Par podz dans le forum Bibliothèques et frameworks
    Réponses: 10
    Dernier message: 15/06/2006, 14h34
  5. [JDBC]connexion entre db2 et l'annuaire ldap
    Par Man Crado dans le forum JDBC
    Réponses: 4
    Dernier message: 10/10/2005, 11h34

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