开发者

In SharePoint, is it possible to programmatically get the current list of users associated with the "nt authority/authenticated users" group?

In SharePoint, I'd like to find out all of the users who have been given access to 开发者_运维百科a site.

If the user is directly granted permissions, granted permissions via a SharePoint group, or granted permissions via a domain group; then I'm able to get the necessary information.

However, if the user is granted permissions via the "authenticated users" group, I am not sure how to find the list of users associated with that group.

Is this possible?


This is more of a .Net question than a Sharepoint question. Yes, you can do this - use the AD APIs to query your domain controller for a list of all users. Here is some code to get you started on programmatic AD access:

http://www.codeproject.com/KB/system/everythingInAD.aspx

You could try to do a query for all objects in AD that are Users.

Please note that this will not list any users outside of AD that might have access to the Sharepoint content. Also, if you have multiple domains, be sure to query all of the AD domains that might have access to the Sharepoint server.


Kyle, thanks for the response.

Using that information, I came up with the following to get all of the users in all of the domains:

private List<Principal> GetAllAuthenticatedUsers()
{
    List<Principal> users = new List<string>();
    foreach (string domain in GetAllDomains())
    {
        try
        {
            PrincipalContext context = new PrincipalContext(ContextType.Domain, domain);

            // Create search condition for all enabled users
            PrincipalSearcher searcher = new PrincipalSearcher();
            UserPrincipal user = new UserPrincipal(context);
            user.Enabled = true;
            user.Name = "*";
            searcher.QueryFilter = user;

            // Get the users
            System.DirectoryServices.AccountManagement.PrincipalSearchResult<Principal> results = searcher.FindAll();
            foreach (Principal principal in results)
            {
                users.Add(principal);
            }
        }
        catch
        {
        }
    }

    return users;

}

private static List<string> GetAllDomains()
{
    List<string> domains = new List<string>();
    using (Forest forest = Forest.GetCurrentForest())
    {
        foreach (Domain domain in forest.Domains)
        {
            domains.Add(domain.Name);
        }
    }

    return domains;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜