Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves the specified groups from the LDAP server.
        /// </summary>
        /// <param name="guid">The GUID of the the group to be retrieved.</param>
        public LdapGroupCollection GetGroupsByGuids(List <Guid> guids)
        {
            var groups = new LdapGroupCollection();

            if (guids.Count == 0)
            {
                return(groups);
            }
            var sb = new StringBuilder();

            sb.Append("(&(objectClass=group)");
            if (guids.Count > 1)
            {
                sb.Append("(|");
            }
            foreach (var guid in guids)
            {
                sb.Append($@"(objectGUID={ConvertGuidToOctetString(guid)})");
            }
            if (guids.Count > 1)
            {
                sb.Append(")");
            }
            sb.Append(")");
            string filter = sb.ToString();
            SearchResultCollection resList = GetSearchResults(GetRootEntry(), filter, searchSubtrees: true);

            foreach (SearchResult res in resList)
            {
                var entry = res.GetDirectoryEntry();
                var group = entry.CopyTo(new LdapGroupInfo());
                groups.Add(group);
            }
            return(groups);
        }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 5
0
 public LdapUserInfo(LdapUserInfo entry) : base(entry)
 {
     LoginName         = entry.LoginName;
     UserPrincipalName = entry.UserPrincipalName;
     Email             = entry.Email;
     FirstName         = entry.FirstName;
     MiddleName        = entry.MiddleName;
     LastName          = entry.LastName;
     PrimaryGroupSID   = entry.PrimaryGroupSID;
     LockedOut         = entry.LockedOut;
     Disabled          = entry.Disabled;
     Groups            = new LdapGroupCollection();
     foreach (LdapGroupInfo group in entry.Groups)
     {
         Groups.Add(new LdapGroupInfo(group));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns a list of the groups in the specified folder (ogranizationalUnit).
        /// </summary>
        /// <param name="folderDN">The distinctive name of the folder holding the groups to be returned.
        /// <param name="includeSubFlders">Set to true to include subfolds in the search.
        public LdapGroupCollection GetGroupsInFolder(string folderDN, bool includeSubFolders = false)
        {
            var            groups    = new LdapGroupCollection();
            string         filter    = "(objectClass=group)";
            DirectoryEntry baseEntry = GetEntryByDN(folderDN);

            if (baseEntry == null)
            {
                throw new NullReferenceException("Unable to find LDAP organizational unit with DN=" + folderDN ?? "");
            }
            SearchResultCollection resList = GetSearchResults(baseEntry, filter, searchSubtrees: includeSubFolders);

            foreach (SearchResult res in resList)
            {
                var entry = res.GetDirectoryEntry();
                var group = entry.CopyTo(new LdapGroupInfo());
                groups.Add(group);
            }
            return(groups);
        }