Exemple #1
0
        /// <summary>
        /// Retourne un objet UtilisateurConnecté avec les informations provenant de l'AD pour l'utilisateur courant :
        /// nom , prenom , libellé (displayname), email , login, employéID (AstreRH), GUID, SID, Structure hiérarchique
        /// Une fois récupéré, les valeurs sont stockées en variable de session, et ne seront récupérées à nouveau depuis l'AD que si nécessaire
        /// </summary>
        /// <returns>L'utilisateur connecté</returns>
        public static Models.UtilisateurConnecte getUtilisateurConnecte()
        {
            //On récupère l'utilisateur depuis le cache de session
            Models.UtilisateurConnecte utilisateurConnecte = HttpContext.Current.Session["UtilisateurConnecte"] as Models.UtilisateurConnecte;

            //S'il est vide, on le met à jour
            if (utilisateurConnecte == null)
            {
                try
                {
                    DirectoryEntry userEntry = getUserEntry();
                    utilisateurConnecte = new Models.UtilisateurConnecte()
                    {
                        nom        = GetValue(userEntry.Properties["sn"]),
                        prenom     = GetValue(userEntry.Properties["givenName"]),
                        libelle    = GetValue(userEntry.Properties["displayName"]),
                        email      = GetValue(userEntry.Properties["mail"]),
                        login      = GetValue(userEntry.Properties["sAMAccountName"]),
                        employeeID = userEntry.Properties["employeeID"].Value == null ? (int?)null : int.Parse(userEntry.Properties["employeeID"].Value.ToString()),
                        guid       = userEntry.Properties["objectGUID"].Value == null ? (Guid?)null : new Guid((byte[])userEntry.Properties["objectGUID"].Value),
                        sid        = new SecurityIdentifier((byte[])userEntry.Properties["objectSid"].Value, 0).ToString(),
                        structure  = String.Join(@"\", getOUs(userEntry))
                    };
                }
                catch (Exception ex)
                {
                    throw new Exception("Erreur lors de l'interrogation AD", ex);
                }
            }
            HttpContext.Current.Session["UtilisateurConnecte"] = utilisateurConnecte;

            return(utilisateurConnecte);
        }
Exemple #2
0
        /// <summary>
        /// Retourne un objet UtilisateurConnecté avec les informations prnvenant de l'AD pour un utilisateur :
        /// nom , prenom , libellé (displayname), email , login, employéID (AstreRH), GUID, SID, Structure hiérarchique
        /// </summary>
        /// <param name="SID">SID de l'utilisateur souhaité</param>
        /// <returns>Utilisateur correspondant au SID</returns>
        public static Models.UtilisateurConnecte getUtilisateur(string SID)
        {
            try
            {
                DirectoryEntry             userEntry   = getUserEntry(SID);
                Models.UtilisateurConnecte utilisateur = new Models.UtilisateurConnecte()
                {
                    nom        = GetValue(userEntry.Properties["sn"]),
                    prenom     = GetValue(userEntry.Properties["givenName"]),
                    libelle    = GetValue(userEntry.Properties["displayName"]),
                    email      = GetValue(userEntry.Properties["mail"]),
                    login      = GetValue(userEntry.Properties["sAMAccountName"]),
                    employeeID = userEntry.Properties["employeeID"].Value == null ? (int?)null : int.Parse(userEntry.Properties["employeeID"].Value.ToString()),
                    guid       = userEntry.Properties["objectGUID"].Value == null ? (Guid?)null : new Guid((byte[])userEntry.Properties["objectGUID"].Value),
                    sid        = new SecurityIdentifier((byte[])userEntry.Properties["objectSid"].Value, 0).ToString(),
                    structure  = String.Join(@"\", getOUs(userEntry))
                };

                return(utilisateur);
            }
            catch (Exception ex)
            {
                throw new Exception("Erreur lors de l'interrogation AD", ex);
            }
        }