2012-09-25 75 views
0

我的用户是“SPR”,它位于下,DC = aaaldap,DC = com的LDAP嵌套组成员

现在我尝试发送过滤器(IDEA:解压到哪个用户SPR所属的所有组到) 过滤器:

(&(objectclass=*)(memberof:1.2.840.113556.1.4.1941:=cn=SPR,dc=aaaldap,dc=com)) 

由于这种搜索结果的一部分,我收到来自AD服务器的响应为ldapsearchresref(这在我的理解是,从LDAP服务器表明它无法找到入口的服务器,并因此提供可能有助于解决条目的另一个服务器的URL的引用)。

我的疑问是为什么它无法找到任何条目,我确信条目存在吗?

另外,其次我读了LDAP搜索过滤器不能用逗号工作的地方。有人可以帮我弄这个吗?

+0

为什么不使用** PrincipalContext **和** PrincipalSearchResult **查询? – RL89

+0

嗨拉胡尔, 请你详细说明一下吗? –

回答

0

如果您需要找到该用户的所有组属于您可以通过用户PrincipalContext

让我来告诉你如何

PrincipalContext pr = new PrincipalContext(ContextType.Domain, "aaaldap.com", "dc=aaaldap,dc=com", username, password); 
List<string> lst = new List<string>(); 
UserPrincipal user = UserPrincipal.FindByIdentity(pr, DomainId); 
if (user != null) 
    { 
    PrincipalSearchResult<Principal> results = user.GetGroups(); 

    foreach (Principal p in results) 
    { 
     lst.Add(p.ToString()); 
    } 
    lst.OrderBy(item => item.ToString()); 
    } 
    pr.Dispose(); 
return lst; 

我想这就是你要找的人。

干杯

+0

此方法未找到嵌套组。从MSDN:这个重载的方法只返回主体直接作为其成员的组;不执行递归搜索。 http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.userprincipal.getgroups(v=vs.110).aspx可能与GetAuthorizationGroups? –

1

要喜欢所有组的用户是包括嵌套groupsYou的成员需要搜索组的成员属性:

(member:1.2.840.113556.1.4.1941:=(cn=SPR,dc=aaaldap,dc=com)) 

-Jim

0

当使用LDAP和查询你有时可以得到一个引用网址,这意味着该帐户是已知的,但在不同的域。当我查询我们的全球目录时会发生这种情况,所以我现在不在了。 :)

这适用于我们的域名。注意我的过滤器中有逗号。

private static void showMemberships() 
    { 
         // instantiate the DirectoryEntry instance with the FQDN of the domain to connect to 
      DirectoryEntry directoryObject = new DirectoryEntry("LDAP://CHILD.DOMAIN.ORG"); 

      // create a DirectorySearcher object and pass the DirectoryEntry instance 
      DirectorySearcher ds = new DirectorySearcher(directoryObject); 

      // set search filter using LDAP query format 
      // this example fetches members for a group limiting to users only (not groups) 
      // and where the users are not in the stale objects ou 
      ds.Filter = "(&(objectCategory=User)(!ou=Stale Objects)(memberOf=CN=GROUPNAME,CN=Users,DC=CHILD,DC=DOMAIN,DC=ORG))"; 

      // perform the search using the filter and store in a SearchResultsCollection 
      SearchResultCollection results = ds.FindAll(); 

      // iterate through the results and do something with the info 
      foreach (SearchResult current in results) 
      { 
       string userId = current.Properties["cn"][0].ToString().Trim().ToUpper(); 
       string userDn = current.Properties["distinguishedName"][0].ToString().Trim().ToUpper(); 

       Console.Write(userId + " (" + userDn + ")\n"); 
      } 

      // set the resource instances as released 
      directoryObject.Close(); 
      directoryObject.Dispose(); 
    }