Précédent   Forum des professionnels en informatique > Java > Général Java > APIs
APIs Forum sur les API standard et API complémentaires. Avant de poster -> FAQ Java, Les meilleures API Java
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 19/01/2012, 09h59   #1
Membre du Club
 
Avatar de freelibre
 
Inscription : février 2005
Messages : 53
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 53
Points : 48
Points : 48
Par défaut LDAP Active directory récupérer les utilisateurs d'un groupe

Bonjour a tous,
Tout est dans le titre !!

Format LDAP:

OU=STM
___OU=Comptes
_____CN=Utilisateur1
_____CN=Utilisateur2
_____CN=Utilisateur3

Merci d'avance
__________________
Le Partage est notre Force !
freelibre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/01/2012, 15h23   #2
Membre du Club
 
Avatar de freelibre
 
Inscription : février 2005
Messages : 53
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 53
Points : 48
Points : 48
Par défaut Solution

Code :
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
 
import java.util.Hashtable;
 
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
 
public class Test_LDAP {
	public static void main(String[] args) {
 
		String LDAP_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
		String LDAP_SERVER_URL = "LDAP://10.0.0.0:389";
		String LDAP_BASE_DN = "DC=Develo,DC=COM";
		String LDAP_AUTHENTICATION_MODE = "simple";
		String LDAP_USER = "Develo" + "\\" + "Administrateur";
		String LDAP_PASSWORD = "password";
 
		Hashtable<String, String> env = new Hashtable<String, String>();
		env.put(Context.INITIAL_CONTEXT_FACTORY, LDAP_CONTEXT_FACTORY);
		env.put(Context.PROVIDER_URL, LDAP_SERVER_URL + "/" + LDAP_BASE_DN);
		env.put(Context.SECURITY_AUTHENTICATION, LDAP_AUTHENTICATION_MODE);
		env.put(Context.SECURITY_PRINCIPAL, LDAP_USER);
		env.put(Context.SECURITY_CREDENTIALS, LDAP_PASSWORD);
 
		try {
			// LdapContext
			LdapContext ctx = new InitialLdapContext(env, null);
 
		    //Filtre du LDAP
			NamingEnumeration<SearchResult> userAnswer = ctx.search("OU=Comptes,OU=STM", null);
 
			//Parcourir tous les Utilisateurs
			while (userAnswer.hasMoreElements()) {
				SearchResult sr = (SearchResult) userAnswer.next();
				Attributes attrs = sr.getAttributes();
 
				if (attrs != null) {
					try {
						//Récupération des attributs
						for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {
							Attribute attr = (Attribute) ae.next();
							if (attr.getID().equals("sn")) {
								System.out.println(attr.get(0).toString());
							}
							if (attr.getID().equals("displayName")) {
								System.out.println(attr.get(0).toString());
							}
						}
					} catch (NamingException e) {
						System.err.println("Défaut : " + e);
						e.printStackTrace();
					}
				}
			}
			ctx.close();
		}
		catch (NamingException e) {
			System.err.println("Problème de connexion");
			e.printStackTrace();
		}
	}
}
__________________
Le Partage est notre Force !
freelibre est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h28.


 
 
 
 
Partenaires

Hébergement Web