active-directory - 我可以将用户与跨不同域的组匹配吗?

标签 active-directory ldap ldap-query

我正在尝试编写一个 LDAP 查询,它将发现用户是否是与通配符查询匹配的组的成员,并且我正在尝试使用 LDAP_MATCHING_RULE_IN_CHAIN OID 来执行此操作。我基本上遵循此页面上的示例 2:

http://support.microsoft.com/kb/914828

我发现这种方法在域中运行良好,即如果 user1 在 group1 中,group1 在 group2 中,那么我可以编写一个匹配“*2”的查询,LDAP 查询将找到嵌套关系并将用户与组匹配.

但是,现在我被要求支持同一林中域之间的关系。所以现在我有:

  • user1 是域 1
  • 中 group1 的成员
  • 域 1 中的 group1 是域 2 中 group2 的成员

  • 我希望能够将 user1 与 group2 进行匹配......我不知道如何让 LDAP_MATCHING_RULE_IN_CHAIN 这样做:

    我尝试将查询的基础设置为以下内容:
  • 域 1,但这仅返回域 1 中的组
  • 域 1 和域 2 的父域,但这不会返回任何结果。
  • GC,通过查询“rootDSE”属性找到,但这只会返回域 1(即 GC 服务器)内的组

  • 有谁知道我怎样才能做到这一点?

    最佳答案

    据我了解,这样做的一种方法是:

  • 从 RootDSE 中查找配置 NamingContext。
  • 在配置 NamingContext 中寻找类 crossRef 的对象带有属性 nETBIOSName现存的。
  • 从这些条目中使用您通过使用 dnsRoot 来描述的算法和 nCName属性。工作林 DNS 允许您加入 dnsRoot 的域 Controller . nCName允许从根搜索。

  • 作为企业管理员组的成员,请小心执行此操作。

    这是代码的示例。
    /* Retreiving RootDSE
     */
    string ldapBase = "LDAP://WM2008R2ENT:389/";
    string sFromWhere = ldapBase + "rootDSE";
    DirectoryEntry root = new DirectoryEntry(sFromWhere, "dom\\jpb", "PWD");
    string configurationNamingContext = root.Properties["configurationNamingContext"][0].ToString();
    
    /* Retreiving the root of all the domains
     */
    sFromWhere = ldapBase + configurationNamingContext;
    DirectoryEntry deBase = new DirectoryEntry(sFromWhere, "dom\\jpb", "PWD");
    
    DirectorySearcher dsLookForDomain = new DirectorySearcher(deBase);
    dsLookForDomain.Filter = "(&(objectClass=crossRef)(nETBIOSName=*))";
    dsLookForDomain.SearchScope = SearchScope.Subtree;
    dsLookForDomain.PropertiesToLoad.Add("nCName");
    dsLookForDomain.PropertiesToLoad.Add("dnsRoot");
    
    SearchResultCollection srcDomains = dsLookForDomain.FindAll();
    
    foreach (SearchResult aSRDomain in srcDomains)
    {
      /* For each root look for the groups containing my user
       */
      string nCName = aSRDomain.Properties["nCName"][0].ToString();
      string dnsRoot = aSRDomain.Properties["dnsRoot"][0].ToString();
    
      /* To find all the groups that "user1" is a member of :
       * Set the base to the groups container DN; for example root DN (dc=dom,dc=fr) 
       * Set the scope to subtree
       * Use the following filter :
       * (member:1.2.840.113556.1.4.1941:=cn=user1,cn=users,DC=x)
       */
      /* Connection to Active Directory
       */
      sFromWhere = "LDAP://" + dnsRoot + "/" + nCName;
      deBase = new DirectoryEntry(sFromWhere, "dom\\jpb", "PWD");
    
      DirectorySearcher dsLookFor = new DirectorySearcher(deBase);
      // you cancomplete the filter here  (&(member:1.2.840.113556.1.4.1941:=CN=user1 Users,OU=MonOu,DC=dom,DC=fr)(cn=*2)
      dsLookFor.Filter = "(member:1.2.840.113556.1.4.1941:=CN=user1 Users,OU=MonOu,DC=dom,DC=fr)";
      dsLookFor.SearchScope = SearchScope.Subtree;
      dsLookFor.PropertiesToLoad.Add("cn");
    
      SearchResultCollection srcGroups = dsLookFor.FindAll();
    
      foreach (SearchResult srcGroup in srcGroups)
      {
        Console.WriteLine("{0}", srcGroup.Path);
      }
    }
    

    这只是一个概念证明,您必须完成:

    使用 using(){}用于处理 DirectoryEntry 对象的表单

    异常管理

    已编辑 (2011-10-18 13:25)

    您对解决问题方式的评论可以在 System.DirectoryServices.AccountManagement Namespace 中给出的方法中找到。 .这是一种递归解决方案。这一次,我使用属于 group1(在另一个域中)的用户进行测试,该用户属于 group2(在第三个域中)并且它似乎可以工作。
    /* Retreiving a principal context
     */
    Console.WriteLine("Retreiving a principal context");
    PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "dc=dom,dc=fr", "jpb", "PWD");
    
    
    /* Look for all the groups a user belongs to
     */
    UserPrincipal aUser = UserPrincipal.FindByIdentity(domainContext, "user1");
    PrincipalSearchResult<Principal> a =  aUser.GetAuthorizationGroups();
    
    foreach (GroupPrincipal gTmp in a)
    {
      Console.WriteLine(gTmp.Name);    
    }
    

    关于active-directory - 我可以将用户与跨不同域的组匹配吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7648692/

    相关文章:

    python - 使用 AD 作为 Django 的身份验证

    java - 从用户的多个 OU 递归查询 LDAP 角色

    ldap - 如何进行 LDAP 查询以仅返回所有级别中具有 OU=Groups 的组?

    security - 在 Active Directory 中存储私有(private) "octet string";默认情况下什么是安全的?

    php - Active Directory LDAPS 通过自签名证书启用。但是 PHP 客户端无法通过 AD 服务器进行身份验证

    active-directory - 真实用户和系统用户帐户之间的区别

    email - LDAP 获取用户邮箱

    tsql - 通过SQL递归查询AD组成员身份

    网络 MVC : SSO + AD group?

    authentication - Apache Shiro - 使用 cn 以外的属性进行身份验证?