【问题标题】:Active directory check if user belongs to a groupActive Directory 检查用户是否属于某个组
【发布时间】:2022-04-29 01:56:16
【问题描述】:

我正在使用以下代码提取活动目录组。如何判断用户是否属于 xyz 组?

// 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.....          
}

【问题讨论】:

    标签: azure-active-directory


    【解决方案1】:

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

    阅读here

    https://graph.windows.net/myorganization/users/{user_id}/$links/memberOf?api-version
    

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

    【讨论】:

    • 非常有用的指针。当我在浏览器中运行它时,它说身份验证丢失。请对此有任何帮助
    • 您只是想访问该链接吗?您需要进行 REST 调用以从该 API 获取内容。您必须已经拥有访问令牌。
    • 感谢您的信息。听起来很有趣也很有帮助。
    • 要获得引导,您可以查看this。或者您可以关注我们的任何一个示例here
    • 您可以删除查询的$links 部分以返回整个组。该响应将包含组名。
    猜你喜欢
    • 2014-03-29
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    相关资源
    最近更新 更多