Exemplo n.º 1
0
        /// <summary>
        /// Produce a Collection of the simple names (Common Names)
        /// of the Network Groups of which the specified User is a member
        /// </summary>
        /// <param name="userCommonName">The name (sAMAccountName) of the User</param>
        /// <returns>A Collection of names (Common Names) of Groups of which the User is a member</returns>
        internal Collections.CaseIgnoringSortedSetType NetworkGroupsForUserName(string userCommonName)
        {
            var userGroupsCommonNameCollection = new Collections.CaseIgnoringSortedSetType();

            if (_DefaultNamingContext != null)
            {
                // There is a Default Naming Context

                try
                {
                    string userDistinguishedName = DistinguishedNameFromSAMAccountName(userCommonName);
                    if (userDistinguishedName != null)
                    {
                        // Got User distinguished Name

                        // Get a Collection of Groups of which the User is a member
                        Collections.CaseIgnoringSortedSetType userGroupDistinguishedNameCollection = NetworkGroupsForUser(LdapObjectPath(userDistinguishedName), true);

                        // Copy suitable details of the Collection of Group Distinguished Names to a Collection of Group Common Names
                        foreach (string groupDistinguishedName in userGroupDistinguishedNameCollection)
                        {
                            userGroupsCommonNameCollection.Add(CommonNameFromDistinguishedName(groupDistinguishedName));
                        }
                    } // Got User distinguished Name
                }
                catch (Exception eek)
                {
                }
            } // There is a Default Naming Context

            return(userGroupsCommonNameCollection);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return a Set of the Distinguished Names of all Users within the supplied Active Directory Group
        /// </summary>
        /// <param name="groupCommonName">The Common Name of the "group"</param>
        /// <returns>A "Case Ignoring Sorted Set" of Distinguished Names of group members</returns>
        internal Collections.CaseIgnoringSortedSetType NetworkDistinguishedNamesForGroupName(string groupCommonName)
        {
            Collections.CaseIgnoringSortedSetType groupUserDistinguishedNameCollection = new Collections.CaseIgnoringSortedSetType();

            SearchResultCollection groupSearchResultCollection =
                SearchResultCollectionFindAll("(&(cn=" + groupCommonName + ")(ObjectClass=group))");

            if (groupSearchResultCollection != null)
            {
                // The search returned at least one result

                foreach (SearchResult groupSearchResult in groupSearchResultCollection)
                {
                    DirectoryEntry groupDirectoryEntry = groupSearchResult.GetDirectoryEntry();

                    Collections.CaseIgnoringSortedSetType entryGroupUserDistinguishedNameCollection = NetworkUsersInGroup(groupDirectoryEntry.Path, true);
                    foreach (string distinguishedName in entryGroupUserDistinguishedNameCollection)
                    {
                        groupUserDistinguishedNameCollection.Add(distinguishedName);
                    }
                }
            }

            return(groupUserDistinguishedNameCollection);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return a Set containing the names of all Active Directory Objects of type "group"
        /// </summary>
        /// <returns>A "Case Ignoring Sorted Set" of Common Names of Active Directory Groups</returns>
        internal Collections.CaseIgnoringSortedSetType NetworkGroupSet()
        {
            Collections.CaseIgnoringSortedSetType networkGroupCommonNameCollection = new Collections.CaseIgnoringSortedSetType();
            SearchResultCollection groupSearchResultCollection = SearchResultCollectionFindAll("(&(cn=*)(ObjectClass=group))");

            if (groupSearchResultCollection != null)
            {
                // The search returned at least one result

                foreach (SearchResult groupSearchResult in groupSearchResultCollection)
                {
                    DirectoryEntry groupDirectoryEntry = groupSearchResult.GetDirectoryEntry();

                    networkGroupCommonNameCollection.Add(CommonNameFromDistinguishedName(groupDirectoryEntry.Path));
                }
            } // The search returned at least one result

            return(networkGroupCommonNameCollection);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Produce the possible multiple values of the specified Attribute for the supplied object
        /// without performing recursion
        /// </summary>
        /// <param name="attributeName">The name of the Attribute</param>
        /// <param name="objectEntry">The Directory Entry for the Object</param>
        /// <param name="valuesCollection">A Collection of values of the specified Attribute</param>
        /// <param name="recursive">Whether the search should be recursive or not</param>
        /// <returns>A Collection of Values for the specified Attribute</returns>
        private Collections.CaseIgnoringSortedSetType AttributeValuesMultiString(string attributeName, DirectoryEntry objectEntry, Collections.CaseIgnoringSortedSetType valuesCollection, bool recursive)
        {
            PropertyValueCollection ValueCollection = objectEntry.Properties[attributeName];
            IEnumerator             enumerator      = ValueCollection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Current != null)
                {
                    if (!valuesCollection.Contains(enumerator.Current.ToString()))
                    {
                        valuesCollection.Add(enumerator.Current.ToString());
                        if (recursive)
                        {
                            AttributeValuesMultiString(attributeName, LdapPrefix + enumerator.Current.ToString(), valuesCollection, true);
                        }
                    }
                }
            }
            return(valuesCollection);
        }