【问题标题】:In SharePoint, is it possible to programmatically get the current list of users associated with the "nt authority/authenticated users" group?在 SharePoint 中,是否可以以编程方式获取与“nt authority/authenticated users”组关联的当前用户列表?
【发布时间】:2011-08-13 12:06:57
【问题描述】:

在 SharePoint 中,我想找出所有有权访问网站的用户。

如果用户被直接授予权限、通过 SharePoint 组授予权限或通过域组授予权限;然后我就能得到必要的信息。

但是,如果用户通过“经过身份验证的用户”组授予权限,我不确定如何找到与该组关联的用户列表。

这可能吗?

【问题讨论】:

    标签: sharepoint active-directory


    【解决方案1】:

    这更像是一个 .Net 问题,而不是 Sharepoint 问题。是的,您可以这样做 - 使用 AD API 来查询您的域控制器以获取所有用户的列表。下面是一些代码,可帮助您开始进行程序化 AD 访问:

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

    您可以尝试查询 AD 中所有属于用户的对象。

    请注意,这不会列出 AD 之外可能有权访问 Sharepoint 内容的任何用户。此外,如果您有多个域,请务必查询所有可能有权访问 Sharepoint 服务器的 AD 域。

    【讨论】:

      【解决方案2】:

      凯尔,感谢您的回复。

      使用该信息,我想出了以下方法来获取所有域中的所有用户:

      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;
      }
      

      【讨论】:

      • 该组是指拥有有效凭据的任何人。如果您正在使用使用 Active Directory 作为其身份验证/授权来源的 SP 环境,那么它的字面意思是目录中任何当前未过期的帐户。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      相关资源
      最近更新 更多