Esempio n. 1
0
        /// <summary>
        /// Retrieves a list of user accounts that are assigned to the specified group and/or the children of that group.
        /// note: The the Groups list for each found user will not be populated.  You will need to call the LoadGroupsAssignedToUser method to populate this list.
        /// </summary>
        public LdapUserCollection GetUsersInGroup(LdapGroupInfo group)
        {
            var groups = new LdapGroupCollection();

            groups.Add(group);
            return(GetUsersInGroups(groups));
        }
Esempio n. 2
0
        //public Task<LdapGroupCollection> GetGroupsAssignedToUserAsync(LdapUserInfo user)
        //{
        //    return Task<LdapGroupCollection>.Run(() => GetGroupsAssignedToUser(user));
        //}

        /// <summary>
        /// Recursive method to retrieve the parent groups of the spcified group.
        /// </summary>
        /// <param name="group">The child group of the parent groups to be found.</param>
        /// <param name="groups">A collection of all of the groups that have already been added to the list.</param>
        protected void LoadParentsOfGroup(LdapGroupInfo group, LdapGroupCollection groups)
        {
            if (group.MemberOf.Count > 0)
            {
                var sb = new StringBuilder();
                foreach (var parentDN in group.MemberOf)
                {
                    sb.Append($@"(distinguishedName={parentDN})");
                }
                if (group.MemberOf.Count > 1)
                {
                    sb.Insert(0, "(&(objectClass=group)(|");
                    sb.Append("))");
                }
                else
                {
                    sb.Insert(0, "(&(objectClass=group)");
                    sb.Append(")");
                }
                string filter = sb.ToString();
                SearchResultCollection resList = GetSearchResults(GetRootEntry(), filter, searchSubtrees: true);
                foreach (SearchResult groupRes in resList)
                {
                    var parentGroup = groupRes.GetDirectoryEntry().CopyTo(new LdapGroupInfo());
                    if (groups.IndexOfDN(parentGroup.DistinguishedName) == -1)
                    {
                        groups.Add(parentGroup);
                        LoadParentsOfGroup(parentGroup, groups);
                    }
                }
            }
        }
Esempio n. 3
0
 public LdapGroupInfo(LdapGroupInfo entry) : base(entry)
 {
     GroupName     = entry.GroupName;
     ContainerName = entry.ContainerName;
     Member        = new List <string>();
     Member.AddRange(entry.Member);
     MemberOf = new List <string>();
     MemberOf.AddRange(entry.MemberOf);
 }
Esempio n. 4
0
        /// <summary>
        /// Recursive method to retrieve the child groups of the spcified group.
        /// </summary>
        /// <param name="group">The parent group containing the children groups to be found.</param>
        /// <param name="groups">A collection of all of the groups that have already been added to the list.</param>
        protected void LoadChildrenOfGroup(LdapGroupInfo group, LdapGroupCollection groups)
        {
            string filter = $"(&(objectClass=group)(memberOf={group.DistinguishedName}))";
            SearchResultCollection resList = GetSearchResults(GetRootEntry(), filter, searchSubtrees: true);

            foreach (SearchResult groupRes in resList)
            {
                var childGroup = groupRes.GetDirectoryEntry().CopyTo(new LdapGroupInfo());
                if (groups.IndexOfDN(childGroup.DistinguishedName) == -1)
                {
                    groups.Add(childGroup);
                    LoadChildrenOfGroup(childGroup, groups);
                }
            }
        }