首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Active directory检查用户是否属于某个组

Active directory检查用户是否属于某个组
EN

Stack Overflow用户
提问于 2017-03-04 04:58:12
回答 1查看 1K关注 0票数 1

我正在使用下面的代码拉取active directory组。如何判断用户是否属于xyz组?

代码语言:javascript
复制
// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// define a "query-by-example" principal - here, we search for a GroupPrincipal 
GroupPrincipal qbeGroup = new GroupPrincipal(ctx);

// create your principal searcher passing in the QBE principal    
PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);

// find all matches
foreach(var found in srch.FindAll())
{
    // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-04 05:30:44

您可以通过查询user对象的memberOf导航属性来获取用户所属组的列表。

阅读关于它的here

代码语言:javascript
复制
https://graph.windows.net/myorganization/users/{user_id}/$links/memberOf?api-version

请注意,您可以删除查询的$links部分以返回整个组对象,而不是对象的链接。但是,为了简单地验证用户是某个组的成员,您可以使用这些链接,并将返回的组的对象id与您正在查找的组的对象id进行比较。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42588322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档