创建 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``Integer和 String。 以后无法更改。 必需。 |
| 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
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var customSecurityAttributeDefinition = new CustomSecurityAttributeDefinition
{
AttributeSet = "Engineering",
Description = "Target completion date",
IsCollection = false,
IsSearchable = true,
Name = "ProjectDate",
Status = "Available",
Type = "String",
UsePreDefinedValuesOnly = false
};
await graphClient.Directory.CustomSecurityAttributeDefinitions
.Request()
.AddAsync(customSecurityAttributeDefinition);
const options = {
authProvider,
};
const client = Client.init(options);
const customSecurityAttributeDefinition = {
attributeSet: 'Engineering',
description: 'Target completion date',
isCollection: false,
isSearchable: true,
name: 'ProjectDate',
status: 'Available',
type: 'String',
usePreDefinedValuesOnly: false
};
await client.api('/directory/customSecurityAttributeDefinitions')
.version('beta')
.post(customSecurityAttributeDefinition);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directory/customSecurityAttributeDefinitions"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphCustomSecurityAttributeDefinition *customSecurityAttributeDefinition = [[MSGraphCustomSecurityAttributeDefinition alloc] init];
[customSecurityAttributeDefinition setAttributeSet:@"Engineering"];
[customSecurityAttributeDefinition setDescription:@"Target completion date"];
[customSecurityAttributeDefinition setIsCollection: false];
[customSecurityAttributeDefinition setIsSearchable: true];
[customSecurityAttributeDefinition setName:@"ProjectDate"];
[customSecurityAttributeDefinition setStatus:@"Available"];
[customSecurityAttributeDefinition setType:@"String"];
[customSecurityAttributeDefinition setUsePreDefinedValuesOnly: false];
NSError *error;
NSData *customSecurityAttributeDefinitionData = [customSecurityAttributeDefinition getSerializedDataWithError:&error];
[urlRequest setHTTPBody:customSecurityAttributeDefinitionData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
CustomSecurityAttributeDefinition customSecurityAttributeDefinition = new CustomSecurityAttributeDefinition();
customSecurityAttributeDefinition.attributeSet = "Engineering";
customSecurityAttributeDefinition.description = "Target completion date";
customSecurityAttributeDefinition.isCollection = false;
customSecurityAttributeDefinition.isSearchable = true;
customSecurityAttributeDefinition.name = "ProjectDate";
customSecurityAttributeDefinition.status = "Available";
customSecurityAttributeDefinition.type = "String";
customSecurityAttributeDefinition.usePreDefinedValuesOnly = false;
graphClient.directory().customSecurityAttributeDefinitions()
.buildRequest()
.post(customSecurityAttributeDefinition);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewCustomSecurityAttributeDefinition()
attributeSet := "Engineering"
requestBody.SetAttributeSet(&attributeSet)
description := "Target completion date"
requestBody.SetDescription(&description)
isCollection := false
requestBody.SetIsCollection(&isCollection)
isSearchable := true
requestBody.SetIsSearchable(&isSearchable)
name := "ProjectDate"
requestBody.SetName(&name)
status := "Available"
requestBody.SetStatus(&status)
type := "String"
requestBody.SetType(&type)
usePreDefinedValuesOnly := false
requestBody.SetUsePreDefinedValuesOnly(&usePreDefinedValuesOnly)
result, err := graphClient.Directory().CustomSecurityAttributeDefinitions().Post(requestBody)
Import-Module Microsoft.Graph.Identity.DirectoryManagement
$params = @{
AttributeSet = "Engineering"
Description = "Target completion date"
IsCollection = $false
IsSearchable = $true
Name = "ProjectDate"
Status = "Available"
Type = "String"
UsePreDefinedValuesOnly = $false
}
New-MgDirectoryCustomSecurityAttributeDefinition -BodyParameter $params
响应
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
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var customSecurityAttributeDefinition = new CustomSecurityAttributeDefinition
{
AttributeSet = "Engineering",
Description = "Active projects for user",
IsCollection = true,
IsSearchable = true,
Name = "Project",
Status = "Available",
Type = "String",
UsePreDefinedValuesOnly = true
};
await graphClient.Directory.CustomSecurityAttributeDefinitions
.Request()
.AddAsync(customSecurityAttributeDefinition);
const options = {
authProvider,
};
const client = Client.init(options);
const customSecurityAttributeDefinition = {
attributeSet: 'Engineering',
description: 'Active projects for user',
isCollection: true,
isSearchable: true,
name: 'Project',
status: 'Available',
type: 'String',
usePreDefinedValuesOnly: true
};
await client.api('/directory/customSecurityAttributeDefinitions')
.version('beta')
.post(customSecurityAttributeDefinition);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directory/customSecurityAttributeDefinitions"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphCustomSecurityAttributeDefinition *customSecurityAttributeDefinition = [[MSGraphCustomSecurityAttributeDefinition alloc] init];
[customSecurityAttributeDefinition setAttributeSet:@"Engineering"];
[customSecurityAttributeDefinition setDescription:@"Active projects for user"];
[customSecurityAttributeDefinition setIsCollection: true];
[customSecurityAttributeDefinition setIsSearchable: true];
[customSecurityAttributeDefinition setName:@"Project"];
[customSecurityAttributeDefinition setStatus:@"Available"];
[customSecurityAttributeDefinition setType:@"String"];
[customSecurityAttributeDefinition setUsePreDefinedValuesOnly: true];
NSError *error;
NSData *customSecurityAttributeDefinitionData = [customSecurityAttributeDefinition getSerializedDataWithError:&error];
[urlRequest setHTTPBody:customSecurityAttributeDefinitionData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
CustomSecurityAttributeDefinition customSecurityAttributeDefinition = new CustomSecurityAttributeDefinition();
customSecurityAttributeDefinition.attributeSet = "Engineering";
customSecurityAttributeDefinition.description = "Active projects for user";
customSecurityAttributeDefinition.isCollection = true;
customSecurityAttributeDefinition.isSearchable = true;
customSecurityAttributeDefinition.name = "Project";
customSecurityAttributeDefinition.status = "Available";
customSecurityAttributeDefinition.type = "String";
customSecurityAttributeDefinition.usePreDefinedValuesOnly = true;
graphClient.directory().customSecurityAttributeDefinitions()
.buildRequest()
.post(customSecurityAttributeDefinition);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewCustomSecurityAttributeDefinition()
attributeSet := "Engineering"
requestBody.SetAttributeSet(&attributeSet)
description := "Active projects for user"
requestBody.SetDescription(&description)
isCollection := true
requestBody.SetIsCollection(&isCollection)
isSearchable := true
requestBody.SetIsSearchable(&isSearchable)
name := "Project"
requestBody.SetName(&name)
status := "Available"
requestBody.SetStatus(&status)
type := "String"
requestBody.SetType(&type)
usePreDefinedValuesOnly := true
requestBody.SetUsePreDefinedValuesOnly(&usePreDefinedValuesOnly)
result, err := graphClient.Directory().CustomSecurityAttributeDefinitions().Post(requestBody)
Import-Module Microsoft.Graph.Identity.DirectoryManagement
$params = @{
AttributeSet = "Engineering"
Description = "Active projects for user"
IsCollection = $true
IsSearchable = $true
Name = "Project"
Status = "Available"
Type = "String"
UsePreDefinedValuesOnly = $true
}
New-MgDirectoryCustomSecurityAttributeDefinition -BodyParameter $params
响应
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
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var customSecurityAttributeDefinition = new CustomSecurityAttributeDefinition
{
AttributeSet = "Engineering",
Description = "Active projects for user",
IsCollection = true,
IsSearchable = true,
Name = "Project",
Status = "Available",
Type = "String",
UsePreDefinedValuesOnly = true,
AllowedValues = new CustomSecurityAttributeDefinitionAllowedValuesCollectionPage()
{
new AllowedValue
{
Id = "Alpine",
IsActive = true
},
new AllowedValue
{
Id = "Baker",
IsActive = true
},
new AllowedValue
{
Id = "Cascade",
IsActive = true
}
}
};
await graphClient.Directory.CustomSecurityAttributeDefinitions
.Request()
.AddAsync(customSecurityAttributeDefinition);
const options = {
authProvider,
};
const client = Client.init(options);
const customSecurityAttributeDefinition = {
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
}
]
};
await client.api('/directory/customSecurityAttributeDefinitions')
.version('beta')
.post(customSecurityAttributeDefinition);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directory/customSecurityAttributeDefinitions"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphCustomSecurityAttributeDefinition *customSecurityAttributeDefinition = [[MSGraphCustomSecurityAttributeDefinition alloc] init];
[customSecurityAttributeDefinition setAttributeSet:@"Engineering"];
[customSecurityAttributeDefinition setDescription:@"Active projects for user"];
[customSecurityAttributeDefinition setIsCollection: true];
[customSecurityAttributeDefinition setIsSearchable: true];
[customSecurityAttributeDefinition setName:@"Project"];
[customSecurityAttributeDefinition setStatus:@"Available"];
[customSecurityAttributeDefinition setType:@"String"];
[customSecurityAttributeDefinition setUsePreDefinedValuesOnly: true];
NSMutableArray *allowedValuesList = [[NSMutableArray alloc] init];
MSGraphAllowedValue *allowedValues = [[MSGraphAllowedValue alloc] init];
[allowedValues setId:@"Alpine"];
[allowedValues setIsActive: true];
[allowedValuesList addObject: allowedValues];
MSGraphAllowedValue *allowedValues = [[MSGraphAllowedValue alloc] init];
[allowedValues setId:@"Baker"];
[allowedValues setIsActive: true];
[allowedValuesList addObject: allowedValues];
MSGraphAllowedValue *allowedValues = [[MSGraphAllowedValue alloc] init];
[allowedValues setId:@"Cascade"];
[allowedValues setIsActive: true];
[allowedValuesList addObject: allowedValues];
[customSecurityAttributeDefinition setAllowedValues:allowedValuesList];
NSError *error;
NSData *customSecurityAttributeDefinitionData = [customSecurityAttributeDefinition getSerializedDataWithError:&error];
[urlRequest setHTTPBody:customSecurityAttributeDefinitionData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
CustomSecurityAttributeDefinition customSecurityAttributeDefinition = new CustomSecurityAttributeDefinition();
customSecurityAttributeDefinition.attributeSet = "Engineering";
customSecurityAttributeDefinition.description = "Active projects for user";
customSecurityAttributeDefinition.isCollection = true;
customSecurityAttributeDefinition.isSearchable = true;
customSecurityAttributeDefinition.name = "Project";
customSecurityAttributeDefinition.status = "Available";
customSecurityAttributeDefinition.type = "String";
customSecurityAttributeDefinition.usePreDefinedValuesOnly = true;
LinkedList<AllowedValue> allowedValuesList = new LinkedList<AllowedValue>();
AllowedValue allowedValues = new AllowedValue();
allowedValues.id = "Alpine";
allowedValues.isActive = true;
allowedValuesList.add(allowedValues);
AllowedValue allowedValues1 = new AllowedValue();
allowedValues1.id = "Baker";
allowedValues1.isActive = true;
allowedValuesList.add(allowedValues1);
AllowedValue allowedValues2 = new AllowedValue();
allowedValues2.id = "Cascade";
allowedValues2.isActive = true;
allowedValuesList.add(allowedValues2);
AllowedValueCollectionResponse allowedValueCollectionResponse = new AllowedValueCollectionResponse();
allowedValueCollectionResponse.value = allowedValuesList;
AllowedValueCollectionPage allowedValueCollectionPage = new AllowedValueCollectionPage(allowedValueCollectionResponse, null);
customSecurityAttributeDefinition.allowedValues = allowedValueCollectionPage;
graphClient.directory().customSecurityAttributeDefinitions()
.buildRequest()
.post(customSecurityAttributeDefinition);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewCustomSecurityAttributeDefinition()
attributeSet := "Engineering"
requestBody.SetAttributeSet(&attributeSet)
description := "Active projects for user"
requestBody.SetDescription(&description)
isCollection := true
requestBody.SetIsCollection(&isCollection)
isSearchable := true
requestBody.SetIsSearchable(&isSearchable)
name := "Project"
requestBody.SetName(&name)
status := "Available"
requestBody.SetStatus(&status)
type := "String"
requestBody.SetType(&type)
usePreDefinedValuesOnly := true
requestBody.SetUsePreDefinedValuesOnly(&usePreDefinedValuesOnly)
requestBody.SetAllowedValues( []AllowedValue {
msgraphsdk.NewAllowedValue(),
id := "Alpine"
SetId(&id)
isActive := true
SetIsActive(&isActive)
msgraphsdk.NewAllowedValue(),
id := "Baker"
SetId(&id)
isActive := true
SetIsActive(&isActive)
msgraphsdk.NewAllowedValue(),
id := "Cascade"
SetId(&id)
isActive := true
SetIsActive(&isActive)
}
result, err := graphClient.Directory().CustomSecurityAttributeDefinitions().Post(requestBody)
Import-Module Microsoft.Graph.Identity.DirectoryManagement
$params = @{
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
}
)
}
New-MgDirectoryCustomSecurityAttributeDefinition -BodyParameter $params
响应
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
}