示例#1
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);
                    }
                }
            }
        }
示例#2
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);
                }
            }
        }