创建 customSecurityAttributeDefinition

命名空间:microsoft.graph

重要

Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。

创建新的 customSecurityAttributeDefinition 对象。

权限

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限

权限类型 权限(从最低特权到最高特权)
委派(工作或学校帐户) CustomSecAttributeDefinition.ReadWrite.All
委派(个人 Microsoft 帐户) 不支持。
应用程序 CustomSecAttributeDefinition.ReadWrite.All

还必须为登录用户分配属性定义管理员 [目录角色] (/azure/active-directory/roles/permissions-reference。 默认情况下,全局管理员和其他管理员角色没有读取、定义或分配自定义安全属性的权限。

HTTP 请求

POST /directory/customSecurityAttributeDefinitions

请求标头

名称 说明
Authorization Bearer {token}。必需。
Content-Type application/json. Required.

请求正文

在请求正文中,提供 customSecurityAttributeDefinition 对象的 JSON 表示形式。

下表显示可在创建自定义 SecurityAttributeDefinition时配置的属性

属性 类型 说明
attributeSet String 属性集的名称。 不区分大小写。 必需。
description String 自定义安全属性的说明。 可最多为 128 个字符,并且包含 Unicode 字符。 不能包含空格或特殊字符。 稍后可更改。 可选。
isCollection 布尔 指示是否可以将多个值分配给自定义安全属性。 以后无法更改。 如果 type 设置为 Boolean, isCollection 则不能设置为 true。 必需。
isSearchable 布尔 指示是否将为自定义安全属性值编制索引,以在分配了属性值的对象上搜索。 以后无法更改。 必需。
name String 自定义安全属性的名称。 在属性集内必须是唯一的。 可最多为 32 个字符,并且包含 Unicode 字符。 不能包含空格或特殊字符。 以后无法更改。 不区分大小写。 必需。
状态 String 指定自定义安全属性是处于活动状态还是已停用。 可接受的值为 和 Available Deprecated。 稍后可更改。 此为必需属性。
type String 自定义安全属性值的数据类型。 支持的类型包括 、 Boolean``IntegerString。 以后无法更改。 必需。
usePreDefinedValuesOnly Boolean 指示是否只能将预定义值分配给自定义安全属性。 如果设置为 false,则允许自由格式的值。 稍后可以从 true 更改为 false,但无法从 false 更改为 true。 如果 type 设置为 Boolean, usePreDefinedValuesOnly 则不能设置为 true。 必需。

该属性 id 是自动生成的,不能设置。

响应

如果成功,此方法在响应 201 Created 正文中返回 响应 代码和 customSecurityAttributeDefinition 对象。

示例

示例 1:添加自定义安全属性

以下示例添加一个新的自定义安全属性定义,该定义是 String 类型的单个自由格式值。

  • 属性集:Engineering
  • 属性:ProjectDate

请求

POST https://graph.microsoft.com/beta/directory/customSecurityAttributeDefinitions
Content-Type: application/json

{
    "attributeSet":"Engineering",
    "description":"Target completion date",
    "isCollection":false,
    "isSearchable":true,
    "name":"ProjectDate",
    "status":"Available",
    "type":"String",
    "usePreDefinedValuesOnly": false
}

响应

HTTP/1.1 201 Created
Content-Type: application/json

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#directory/customSecurityAttributeDefinitions/$entity",
    "attributeSet": "Engineering",
    "description": "Target completion date",
    "id": "Engineering_ProjectDate",
    "isCollection": false,
    "isSearchable": true,
    "name": "ProjectDate",
    "status": "Available",
    "type": "String",
    "usePreDefinedValuesOnly": false
}

示例 2:添加支持多个预定义值的自定义安全属性

以下示例添加一个新的自定义安全属性定义,该定义支持预定义的 String 类型的多个值。

  • 属性集:Engineering
  • 属性:Project

请求

POST https://graph.microsoft.com/beta/directory/customSecurityAttributeDefinitions
Content-Type: application/json
Content-length: 310

{
    "attributeSet":"Engineering",
    "description":"Active projects for user",
    "isCollection":true,
    "isSearchable":true,
    "name":"Project",
    "status":"Available",
    "type":"String",
    "usePreDefinedValuesOnly": true
}

响应

HTTP/1.1 201 Created
Content-Type: application/json

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#directory/customSecurityAttributeDefinitions/$entity",
    "attributeSet": "Engineering",
    "description": "Active projects for user",
    "id": "Engineering_Project",
    "isCollection": true,
    "isSearchable": true,
    "name": "Project",
    "status": "Available",
    "type": "String",
    "usePreDefinedValuesOnly": true
}

示例 3:添加具有预定义值列表的自定义安全属性

以下示例添加一个新的自定义安全属性定义,并将预定义值列表作为字符串集合。

  • 属性集:Engineering
  • 属性:Project
  • 属性数据类型:字符串集合
  • 预定义值:、Alpine``Baker、、Cascade

请求

POST https://graph.microsoft.com/beta/directory/customSecurityAttributeDefinitions
Content-Type: application/json

{
    "attributeSet": "Engineering",
    "description": "Active projects for user",
    "isCollection": true,
    "isSearchable": true,
    "name": "Project",
    "status": "Available",
    "type": "String",
    "usePreDefinedValuesOnly": true,
    "allowedValues": [
        {
            "id": "Alpine",
            "isActive": true
        },
        {
            "id": "Baker",
            "isActive": true
        },
        {
            "id": "Cascade",
            "isActive": true
        }
    ]
}

响应

HTTP/1.1 201 Created
Content-Type: application/json

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#directory/customSecurityAttributeDefinitions/$entity",
    "attributeSet": "Engineering",
    "description": "Active projects for user",
    "id": "Engineering_Project",
    "isCollection": true,
    "isSearchable": true,
    "name": "Project",
    "status": "Available",
    "type": "String",
    "usePreDefinedValuesOnly": true
}