惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
N
News and Events Feed by Topic
T
Tenable Blog
P
Proofpoint News Feed
W
WeLiveSecurity
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
Help Net Security
Help Net Security
I
Intezer
T
Threat Research - Cisco Blogs
S
Secure Thoughts
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
AWS News Blog
AWS News Blog
Google Online Security Blog
Google Online Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
The Hacker News
The Hacker News
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tor Project blog
N
News | PayPal Newsroom
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
Arctic Wolf
Forbes - Security
Forbes - Security
O
OpenAI News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Latest
Security Latest
P
Palo Alto Networks Blog
S
Schneier on Security
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
H
Heimdal Security Blog
V
Vulnerabilities – Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园_首页
T
Troy Hunt's Blog
Latest news
Latest news
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
L
LINUX DO - 热门话题
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
V
Visual Studio Blog
H
Hacker News: Front Page

博客园 - 害羞的狮子王

无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.5 Delete删除用户] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.4 Edit修改用户信息] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.3 Details用户详细信息] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息] 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证-2.2身份验证开发] 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证--2.1使用Azure AD需要了解几个概念] 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证] 无责任Windows Azure SDK .NET开发入门篇一[Windows Azure开发前准备工作] 建立小型开发团队的工作协作:翻译工作 建立小型开发团队的工作协作:讨论区 建立小型开发团队的工作协作:BugList 建立小型开发团队的工作协作:任务日历 建立小型开发团队的工作协作:简单的文档管理 建立小型开发团队的工作协作:管理调查和投票 建立小型开发团队的工作协作:管理链接 建立小型开发团队的工作协作:总览效果图 感谢微软BPOS4China技术支持组 远程为服务器安装Windows 2008 Server
无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.1 Index用户列表]
害羞的狮子王 · 2015-08-10 · via 博客园 - 害羞的狮子王

3.1 Index用户列表

或许当前域下的用户列表

[Authorize]
public async Task<ActionResult> Index()
{
    var userList = new List<IUser>();

    try
    {
        var client = AuthenticationHelper.GetActiveDirectoryClient();
        var pagedCollection = await client.Users.ExecuteAsync();
        while (pagedCollection != null)
        {
            userList.AddRange(pagedCollection.CurrentPage.ToList());
            pagedCollection = await pagedCollection.GetNextPageAsync();
        }
    }
    catch (Exception e)
    {
        if (e.Message == "Authorization Required.")
        {
            HttpContext.GetOwinContext().Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType);
            return View(userList);
        }
    }
    return View(userList);
}

Index被修饰为[Authorize],当用户没有登录就会跳转到登录界面要求用户登录,当身份被验证后将执行Action的代码。

var client = AuthenticationHelper.GetActiveDirectoryClient();

上面这行代码获得了Microsoft.Azure.ActiveDirectory.GraphClient.ActiveDirectoryClient对象,该对象是对Azure AD Graph API的封装,该实例提供通过租户对象 ID和通过使用“Me”别名的两种Azure AD Graph REST API进行的服务。

Microsoft.Azure.ActiveDirectory.GraphClient.ActiveDirectoryClien实例暴露的属性,可以通过对Context和Query来了解到对Url的封装。

比如

l Applications中的BaseUri的值是https://graph.chinacloudapi.cn/<你的租户ID>

l Users的Query的Url是https://graph.chinacloudapi.cn/<你的租户ID>/users

l DeletedDirectoryObjectsde Query的Url是https://graph.chinacloudapi.cn/<你的租户ID>/deletedDirectoryObjects

有意思的是Me,Me是别名仅当使用 OAuth 授权代码授予类型(3 重)身份验证时,此别名才可用。此别名不区分大小写。它将替换 URL 中的对象 ID 或租户域。使用此别名时,Graph API 将从附加到请求的令牌中提供的声明获取用户。所以Me属性中提供的CreatedObjects、CreatedOnBehalfOf、DirectReports、Manager、MemberOf、Members、OwnedObjects、Owners这些操作的Url都是如下格式

https://graph.chinacloudapi.cn/<你的租户ID>/me/<操作名称>

所以说ActiveDirectoryClient提供的非常良好的RESTAPI的封装。

var pagedCollection = await client.Users.ExecuteAsync();

Users以IPagedCollection<IUser>对象返回,每Page包含一定数量的User,我们需要遍历集合中的User对象。

最后将我们获得的User集合返回给View。对应的View的代码如下

@model IEnumerable<Microsoft.Azure.ActiveDirectory.GraphClient.IUser>


@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

<div class="table-responsive">
    <table id="directoryObjects" class="table table-bordered table-striped table-condensed">
        <tr>
            <th>
                用户名
            </th>
            <th>
                显示名称
            </th>
            <th>
                别名
            </th>
            <th>
                职务
            </th>
            <th />
        </tr>
        @foreach (var item in Model)
        {
            var user = item as Microsoft.Azure.ActiveDirectory.GraphClient.User;
            <tr>
                <td>
                    @Html.ActionLink(item.UserPrincipalName, "Details", new { objectId = item.ObjectId })
                </td>
                <td>
                    @Html.DisplayFor(modelItem => user.DisplayName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => user.MailNickname)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => user.JobTitle)
                </td>
                <td>
                    @Html.ActionLink("Edit", "Edit", new { objectId = item.ObjectId }) <br />
                    @Html.ActionLink("Delete", "Delete", new { objectId = item.ObjectId })  <br />
                </td>
            </tr>
        }
    </table>
</div>

运行结果如图

1