Précédent   Forum du club des développeurs et IT Pro > Java > Général Java
Général Java Java SE, Java ME, APIs, Persistance, JDBC, Spring, XML. Avant de poster -> FAQ Java, Sources Java
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 16/11/2012, 15h07   #1
diabli73
Membre régulier
 
Homme
Responsable Applicatif / Développeur
Inscription : mai 2007
Messages : 479
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Responsable Applicatif / Développeur

Informations forums :
Inscription : mai 2007
Messages : 479
Points : 73
Points : 73
Par défaut Recherche dans l'active directory, descendre de plusieurs niveaux

Bonjour je fais une classe qui recherche des utilisateurs et des groupes dans l'AD, mais je n'arrive à descendre que d'un groupe dans les OU,
comment faire pour descendre plus bas.

Je m'explique, j'arrive à chercher dans :
Code :
"OU=Groups,DC=home,DC=maboite,DC=fr"
mais pas dans :

Code :
"OU=grouplvl1,OU=Groups,DC=home,DC=maboite,DC=fr"
Mon code est :

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
this.name=n;
		this.pwd=p;
 
 
		try {
		    Hashtable env = new Hashtable();
		    env.put(Context.INITIAL_CONTEXT_FACTORY,
		             "com.sun.jndi.ldap.LdapCtxFactory");
		    env.put(Context.PROVIDER_URL,
		             "ldap://maboite.fr"); //replace with your server URL/IP
		             //only DIGEST-MD5 works with our Windows Active Directory
		    env.put(Context.SECURITY_AUTHENTICATION,
		             "DIGEST-MD5"); //No other SALS worked with me
		    env.put(Context.SECURITY_PRINCIPAL,
		            name); // specify the username ONLY to let Microsoft Happy
		    env.put(Context.SECURITY_CREDENTIALS, pwd);   //the password
 
		    DirContext ctx = new InitialDirContext(env);
 
		   // ctx.getNameInNamespace();
 
		  //  System.out.println("Name : "+ctx.U);
 
 
 
		    //Create the search controls 		
			SearchControls searchCtls = new SearchControls();
 
			//Specify the attributes to return
			//String returnedAtts[]={"sn","givenName","mail"};
			String returnedAtts[]={"sn","givenName","mail"};
			searchCtls.setReturningAttributes(returnedAtts);
 
			//Specify the search scope
			searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
 
			//specify the LDAP search filter
			String searchFilter = "(&(objectClass=*)(mail=*))";
 
			//Specify the Base for the search
 
			String searchBase = "OU=grouplvl1,OU=Groups,DC=home,DC=maboite,DC=fr";
 
 
			//initialize counter to total the results
			int totalResults = 0;
 
 
			// Search for objects using the filter
			NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
 
			//Loop through the search results
			while (answer.hasMoreElements()) {
		    		SearchResult sr = (SearchResult)answer.next();
 
				totalResults++;
 
				System.out.println(">>>" + sr.getName());
 
				// Print out some of the attributes, catch the exception if the attributes have no values
				Attributes attrs = sr.getAttributes();
 
				if (attrs != null) {
					try {
					System.out.println("   surname: " + attrs.get("sn").get());
					System.out.println("   firstname: " + attrs.get("givenName").get());
					System.out.println("   mail: " + attrs.get("mail").get());
 
					} 
					catch (NullPointerException e)	{
					System.out.println("Errors listing attributes: " + e);
					}
				}
 
			}
 
 			System.out.println("Total results: " + totalResults);
 
 
 
		    ctx.close();
 
		  } catch(NamingException ne) {
		    System.out.println("Error authenticating user:");
		    System.out.println(ne.getMessage());
 
		    return connect;
		}
 
		  //if no exception, the user is already authenticated.
		  connect=1;
 
		  return connect;
 
	}
diabli73 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/11/2012, 17h17   #2
diabli73
Membre régulier
 
Homme
Responsable Applicatif / Développeur
Inscription : mai 2007
Messages : 479
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Responsable Applicatif / Développeur

Informations forums :
Inscription : mai 2007
Messages : 479
Points : 73
Points : 73
ou sinon peut etre savez vous comment faire un member of sur un user?

MErci
diabli73 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 14h59.


 
 
 
 
Partenaires

Hébergement Web