Create customSecurityAttributeDefinition

命名空间:microsoft.graph

Create新的 customSecurityAttributeDefinition 对象。

此 API 可用于以下国家级云部署

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考

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

还必须至少为已登录用户分配 属性定义管理员目录角色。 默认情况下, 全局管理员 和其他管理员角色无权读取、定义或分配自定义安全属性。

HTTP 请求

POST /directory/customSecurityAttributeDefinitions

请求标头

名称 说明
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权
Content-Type application/json. 必需。

请求正文

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

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

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

ID 属性是自动生成的,无法设置。

响应

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

示例

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

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

  • 属性集:Engineering
  • 属性:ProjectDate

请求

以下示例显示了一个请求。

POST https://graph.microsoft.com/v1.0/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/v1.0/$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/v1.0/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/v1.0/$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:添加具有预定义值列表的自定义安全属性

以下示例添加一个新的自定义安全属性定义,其中包含预定义值列表作为 Strings 的集合。

  • 属性集:Engineering
  • 属性:Project
  • 属性数据类型:字符串集合
  • 预定义值: AlpineBakerCascade

请求

以下示例显示了一个请求。

POST https://graph.microsoft.com/v1.0/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/v1.0/$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
}