Important: 自定义安全属性功能目前为预览版。 有关适用于 Beta、预览版或尚未发布到正式版的 Azure 功能的法律条款,请参阅 Microsoft Azure 预览版补充使用条款 。
Azure Active Directory (Azure AD) 中的自定义安全属性是特定于企业的属性, (键值对) 可以定义和分配给 Azure AD 对象。
本文提供有关如何为用户和应用程序分配、更新或删除不同类型的自定义安全属性的示例, (服务主体) 。 只能通过PATCH更新用户或 Update servicePrincipal 请求中的操作来分配或更新自定义安全属性。
权限
若要管理自定义安全属性,必须为调用主体分配以下 Azure AD 角色。 默认情况下,全局管理员和其他管理员角色无权读取、定义或分配自定义安全属性。
此外,必须向调用主体授予以下权限。
自定义SecAttributeAssignment.ReadWrite.All 授予对应用程序的读取、分配、更新或删除属性的权限。 使用资源对象权限(例如 User.Read.All)单独授予读取资源对象的权限(例如用户)。
分配自定义安全属性
示例 1:为用户分配具有字符串值的自定义安全属性
以下示例演示如何向用户分配具有字符串值的自定义安全属性。
- 属性集:
Engineering - 属性:
ProjectDate - 属性数据类型:字符串
- 属性值:
"2022-10-01"
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"ProjectDate":"2022-10-01"
}
}
}
响应
HTTP/1.1 204 No Content
示例 2:将具有字符串值的自定义安全属性分配给服务主体
下面的示例演示如何将具有字符串值的自定义安全属性分配给服务主体。
- 属性集:
Engineering - 属性:
ProjectDate - 属性数据类型:字符串
- 属性值:
"2022-10-01"
请求
PATCH https://graph.microsoft.com/beta/servicePrincipals/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"ProjectDate":"2022-10-01"
}
}
}
响应
HTTP/1.1 204 No Content
示例 3:为用户分配具有多字符串值的自定义安全属性
以下示例演示如何向用户分配具有多字符串值的自定义安全属性。
- 属性集:
Engineering - 属性:
Project - 属性数据类型:字符串集合
- 属性值:
["Baker","Cascade"]
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"Project@odata.type":"#Collection(String)",
"Project":["Baker","Cascade"]
}
}
}
响应
HTTP/1.1 204 No Content
示例 4:为用户分配具有整数值的自定义安全属性
以下示例演示如何为用户分配具有整数值的自定义安全属性。
- 属性集:
Engineering - 属性:
NumVendors - 属性数据类型:整数
- 属性值:
4
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"NumVendors@odata.type":"#Int32",
"NumVendors":4
}
}
}
响应
HTTP/1.1 204 No Content
示例 5:为用户分配具有多整数值的自定义安全属性
以下示例演示如何为用户分配具有多整数值的自定义安全属性。
- 属性集:
Engineering - 属性:
CostCenter - 属性数据类型:整数集合
- 属性值:
[1001,1003]
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"CostCenter@odata.type":"#Collection(Int32)",
"CostCenter":[1001,1003]
}
}
}
响应
HTTP/1.1 204 No Content
示例 6:为用户分配具有布尔值的自定义安全属性
以下示例演示如何为用户分配具有布尔值的自定义安全属性。
- 属性集:
Engineering - 属性:
Certification - 属性数据类型:布尔
- 属性值:
true
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"Certification":true
}
}
}
响应
HTTP/1.1 204 No Content
更新自定义安全属性分配
示例 1:使用用户的整数值更新自定义安全属性分配
以下示例演示如何使用用户的整数值更新自定义安全属性分配。
- 属性集:
Engineering - 属性:
NumVendors - 属性数据类型:整数
- 属性值:
8
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"NumVendors@odata.type":"#Int32",
"NumVendors":8
}
}
}
响应
HTTP/1.1 204 No Content
示例 2:使用用户的布尔值更新自定义安全属性分配
以下示例演示如何使用用户的布尔值更新自定义安全属性分配。
- 属性集:
Engineering - 属性:
Certification - 属性数据类型:布尔
- 属性值:
false
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"Certification":false
}
}
}
响应
HTTP/1.1 204 No Content
删除自定义安全属性分配
示例 1:从用户中删除单值自定义安全属性分配
以下示例演示如何从用户中删除支持单个值的自定义安全属性分配。
- 属性集:
Engineering - 属性:
ProjectDate - 属性值:
null
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"ProjectDate":null
}
}
}
响应
HTTP/1.1 204 No Content
示例 2:从用户中删除多值自定义安全属性分配
以下示例演示如何从用户中删除支持多个值的自定义安全属性分配。
- 属性集:
Engineering - 属性:
Project - 属性值:
[]
请求
PATCH https://graph.microsoft.com/beta/users/{id}
Content-type: application/json
{
"customSecurityAttributes":
{
"Engineering":
{
"@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
"Project":[]
}
}
}
响应
HTTP/1.1 204 No Content
后续步骤
历史资料。此文对应 2023-02-03 的中文文档快照,适用产品版本和命令行为以原文为准。
来源与署名:Microsoft 和文档贡献者(原始作者元数据 rolyon)。固定版本原文。文档采用 CC BY 4.0,示例代码采用 MIT 授权。本站将 Markdown 转为 HTML,规范化链接,移除外部媒体和导航标记。
