Active directory ldap嵌套组成员身份
我的用户是“SPR”,它位于dc=aaaldap,dc=com下 现在我尝试发送的过滤器是(想法:提取用户SPR所属的所有组) 过滤器: 作为这个搜索结果的一部分,我从AD服务器得到了响应,名为ldapsearchresref(据我所知,这表示ldap服务器无法在其服务器中找到条目,因此提供了对另一个服务器的URL的引用,这可能有助于解析条目) 我的疑问是,为什么它不能在我确信存在的条目中找到任何条目Active directory ldap嵌套组成员身份,active-directory,ldap,Active Directory,Ldap,我的用户是“SPR”,它位于dc=aaaldap,dc=com下 现在我尝试发送的过滤器是(想法:提取用户SPR所属的所有组) 过滤器: 作为这个搜索结果的一部分,我从AD服务器得到了响应,名为ldapsearchresref(据我所知,这表示ldap服务器无法在其服务器中找到条目,因此提供了对另一个服务器的URL的引用,这可能有助于解析条目) 我的疑问是,为什么它不能在我确信存在的条目中找到任何条目 另外,第二,我在某个地方读到LDAP搜索过滤器不能使用逗号。有人能帮我吗?如果您需要查找该用户
另外,第二,我在某个地方读到LDAP搜索过滤器不能使用逗号。有人能帮我吗?如果您需要查找该用户所属的所有组,您可以使用用户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;
PrincipalContext pr=newprincipalcontext(ContextType.Domain,“aaaldap.com”,“dc=aaaldap,dc=com”,用户名,密码);
List lst=新列表();
UserPrincipal user=UserPrincipal.FindByIdentity(pr,DomainId);
如果(用户!=null)
{
PrincipalSearchResult results=user.GetGroups();
foreach(结果中的主要p)
{
添加(p.ToString());
}
lst.OrderBy(item=>item.ToString());
}
pr.Dispose();
返回lst;
我想这就是你想要的
干杯要喜欢用户是其成员的所有组,请包括嵌套组您需要在组中搜索“成员”属性:
(member:1.2.840.113556.1.4.1941:=(cn=SPR,dc=aaaldap,dc=com))
-jim在使用LDAP和查询时,您有时会得到一个引用URL,这意味着该帐户是已知的,但位于不同的域中。当我查询我们的全球目录时会发生这种情况,所以我不再这样做了。:) 这在我们的领域中起作用。注意,我的过滤器中有逗号
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();
}
为什么不使用PrincipalContext和PrincipalSearchResult进行查询?嗨,Rahul,你能详细说明一下吗?这个方法找不到嵌套组。来自MSDN:此重载方法仅返回主体直接作为成员的组;不执行递归搜索。也许是GetAuthorizationGroup?
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();
}