Bonjour,

J'aimerais afficher tous les groupes auxquels l'uid connecté appartient et voilà mon code :
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
 
public void printGroups (String uid, String dn)
  throws ch.esnig.ldap.ClientLDAPException {
    try {
      // Créer le contrôle de recherche
      SearchControls searchCtls = new SearchControls();
      // Spécifier le search scope
      searchCtls.setSearchScope (SearchControls.SUBTREE_SCOPE);
      // Spécifier le filtre de recherche LDAP
        String searchFilter = "(&(objectClass=top))";
      // Spécifier la base de la recherche
      String searchBase = "ou=person";
      // Spécifier les attributs à retourner
      String returnedAttrs[]={"memberOf"};
      searchCtls.setReturningAttributes(returnedAttrs);
      // Rechercher les objets utilisant le filtre
      NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
      // Parcourir les résultats de la recherche
      while (answer.hasMoreElements()) {
        SearchResult sr = (SearchResult)answer.next();
        System.out.println(">>>>>" + sr.getName());
        // Afficher les groupes
        Attributes attrs = sr.getAttributes();
        if (attrs != null) {
          try {
             NamingEnumeration ae = attrs.getAll();
             while (ae.hasMore()) {
               Attribute attr = (Attribute)ae.next();
	       System.out.println("Attribute: " + attr.getID());
	       NamingEnumeration e = attr.getAll();
               while (e.hasMore()) {
               System.out.println(" " +  e.next());
	      }
            }
          }
	  catch (NamingException e) {
            throw new ch.esnig.ldap.ClientLDAPException("Error : Listage des groupes! (printGroups)", e );
	 }
       }
       else {
         System.out.println ("L'utilisateur n'appartient a aucun groupe !");
       }
     }
    }
    catch (javax.naming.NamingException ex) {
      throw new ch.esnig.ldap.ClientLDAPException("Error : Recherche du directory! (printGroups)", ex );
    }
  }
Il ne fonctionne pas....
J'obtiens l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
ch.esnig.ldap.ClientLDAPException: Exception rencontree : Error : Recherche du d
irectory! (printGroups): [LDAP: error code 32 - No Such Object]
        at ch.esnig.ldap.ClientLDAP.printGroups(ClientLDAP.java:134)
        at ch.esnig.ldap.ClientLDAPUI.main(ClientLDAPUI.java:84)
Caused by: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Ob
ject]; remaining name 'ou=person'
Le problème est que je ne sais pas trop quoi mettre dans searchBase et searchFilter.

Est-ce que quelqu'un pourrait m'aider SVP ?

Merci d'avance