Beispiel #1
0
 /// /////////////////////////////////////
 private void AssureDonnees()
 {
     if (m_listeGroups != null)
     {
         return;
     }
     m_listeGroups = new ArrayList();
     try
     {
         DirectoryEntry         entry    = CAdBase.RootEntry;     //, m_strUser, m_strPassword);
         DirectorySearcher      searcher = new DirectorySearcher(entry);
         SearchResultCollection results;
         searcher.Filter = "(objectCategory=group)";
         searcher.PropertiesToLoad.Add(c_champId);
         searcher.PropertiesToLoad.Add(c_champNom);
         searcher.PropertiesToLoad.Add(c_champGroups);
         results = searcher.FindAll();
         Hashtable tableMembersOf = new Hashtable();
         foreach (SearchResult result in results)
         {
             try
             {
                 DirectoryEntry entryTrouvee = result.GetDirectoryEntry();
                 CAdGroup       group        = new CAdGroup(
                     entryTrouvee.Properties[c_champId].Value.ToString(),
                     entryTrouvee.Properties[c_champNom].Value.ToString());
                 tableMembersOf[group] = entryTrouvee.Properties[c_champGroups];
                 m_listeGroups.Add(group);
             }
             catch
             {
             }
         }
         //Récupère les groupes
         foreach (CAdGroup group in m_listeGroups)
         {
             group.GroupesParents.Clear();
             PropertyValueCollection properties = (PropertyValueCollection)tableMembersOf[group];
             if (properties != null)
             {
                 foreach (object obj in properties)
                 {
                     CAdGroup groupParent = GetGroupeFromMemberOfValue(obj.ToString());
                     if (groupParent != null)
                     {
                         group.GroupesParents.Add(groupParent);
                     }
                 }
             }
         }
         m_listeGroups.Sort();
     }
     catch
     {
         m_listeGroups.Clear();
     }
 }
Beispiel #2
0
 /// /////////////////////////////////////
 private void AssureDonnees()
 {
     if (m_listeUsers != null)
     {
         return;
     }
     m_listeUsers = new ArrayList();
     try
     {
         DirectoryEntry         entry    = CAdBase.RootEntry;     //, m_strUser, m_strPassword);
         DirectorySearcher      searcher = new DirectorySearcher(entry);
         SearchResultCollection results;
         searcher.Filter = "(objectCategory=person)";
         searcher.PropertiesToLoad.Add(c_champId);
         searcher.PropertiesToLoad.Add(c_champNom);
         searcher.PropertiesToLoad.Add(c_champGroups);
         results = searcher.FindAll();
         CAdGroupsServeur groupeServeur = new CAdGroupsServeur(IdSession);
         foreach (SearchResult result in results)
         {
             try
             {
                 DirectoryEntry entryTrouvee = result.GetDirectoryEntry();
                 CAdUser        user         = new CAdUser(
                     entryTrouvee.Properties[c_champId].Value.ToString(),
                     entryTrouvee.Properties[c_champNom].Value.ToString());
                 if (entryTrouvee.Properties[c_champGroups] != null)
                 {
                     foreach (object obj in entryTrouvee.Properties[c_champGroups])
                     {
                         CAdGroup group = groupeServeur.GetGroupeFromMemberOfValue(obj.ToString());
                         if (group != null)
                         {
                             user.Groups.Add(group);
                         }
                     }
                 }
                 m_listeUsers.Add(user);
             }
             catch
             {
             }
         }
         m_listeUsers.Sort();
     }
     catch
     {
         m_listeUsers.Clear();
     }
 }
Beispiel #3
0
 /// /////////////////////////////////////
 public CAdGroup GetGroup(string strId)
 {
     AssureDonnees();
     if (m_listeGroups.Count == 0)
     {
         CAdGroup group = new CAdGroup(strId, strId);
         return(group);
     }
     foreach (CAdGroup group in m_listeGroups)
     {
         if (group.Id == strId)
         {
             return(group);
         }
     }
     return(null);
 }
Beispiel #4
0
        /// <summary>
        /// Force l'appartenance des groupes comme définit dans la base AD
        /// </summary>
        /// <returns></returns>
        public CResultAErreur SynchroniseGroupesAD( )
        {
            CResultAErreur result = CResultAErreur.True;

            CAdGroup[] adGroups = CAdGroup.GetGroups(IdSession);
            using (CContexteDonnee contexte = new CContexteDonnee(IdSession, true, false))
            {
                contexte.BeginModeDeconnecte();
                CListeObjetsDonnees liste  = new CListeObjetsDonnees(contexte, typeof(CGroupeActeur));
                CFiltreData         filtre = new CFiltreData(CGroupeActeur.c_champGroupeWindowsCorrespondant + "<>@1", "");
                liste.Filtre = filtre;

                if (result)
                {
                    contexte.CommitModifsDeconnecte();
                }
            }
            return(result);
        }
Beispiel #5
0
        protected bool CreateOrUpdateRelations(CGroupeActeur groupe, CAdGroup adGroupe, Hashtable tableElementsASupprimer, Hashtable tableEmpecheRecursInf)
        {
            if (tableEmpecheRecursInf[adGroupe.Id] != null)
            {
                return(false);
            }
            tableEmpecheRecursInf[adGroupe.Id] = true;
            //Trouve le groupe correspondant au groupe AD
            CGroupeActeur groupeCorrespondant = CGroupeActeur.FromAd(groupe.ContexteDonnee, adGroupe.Id);

            if (groupeCorrespondant == null)
            {
                foreach (CAdGroup adParent in adGroupe.GroupesParents)
                {
                    if (CreateOrUpdateRelations(groupe, adParent, tableElementsASupprimer, tableEmpecheRecursInf))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                //Le groupe correspondant existe. Existe-t-il la relation ?
                CListeObjetsDonnees liste = groupe.RelationsGroupesContenantsDirects;
                liste.Filtre = new CFiltreData(CRelationGroupeActeur_GroupeActeur.c_champIdGroupeContenant + "=@1", groupeCorrespondant.Id);
                if (liste.Count == 1)
                {
                    CRelationGroupeActeur_GroupeActeur rel = (CRelationGroupeActeur_GroupeActeur)liste[0];
                    tableElementsASupprimer.Remove(rel);                    //On ne supprime pas
                }
                else
                {
                    //Crée la relation
                    CRelationGroupeActeur_GroupeActeur rel = new CRelationGroupeActeur_GroupeActeur(groupe.ContexteDonnee);
                    rel.CreateNewInCurrentContexte();
                    rel.GroupeContenant = groupeCorrespondant;
                    rel.GroupeContenu   = groupe;
                }
                return(true);
            }
            return(false);
        }