Hello,

Je cherche à me connecter à active directory et récupérer des informations sur un attribut qui est définit pour un user

j ai trouvé le code 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
 
import javax.naming.Context;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.DirContext;
import java.util.Hashtable;
 
public DirContext ActiveDirectory(String serverName, String username, String password) {
     DirContext dirContext = null;                      //  returned to the calling program
     Hashtable environment = new Hashtable();           //  holds parameters that will be passed to the AD server
 
     //  Set up the Active Directory environment.		
     environment.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
     environment.put(Context.PROVIDER_URL, "ldap://" + serverName);
     environment.put(Context.SECURITY_AUTHENTICATION, "simple");
     environment.put(Context.SECURITY_PRINCIPAL, username);
     environment.put(Context.SECURITY_CREDENTIALS, password1);
     environment.put(Context.REFERRAL, "follow");
 
     try {
          dirContext = new InitialDirContext(environment);         //  Retrieve a "connection" to the Active Directory server.
     } catch (Exception ex) {
          System.err.println(ex);
     }
 
     return dirContext;
je cherche maintenant à récupérer un attribut nommé localité qui fait partie de la définition d'un user

comment faire ?

D'avance merci