例: Microsoft Graph API (プレビュー) を使用してカスタム セキュリティ属性の割り当てを割り当て、更新、一覧表示、または削除する

重要

カスタム セキュリティ属性機能は現在プレビュー段階です。 ベータ版、プレビュー版、または一般公開されていない Azure 機能に適用される法的条件については、「 Microsoft Azure プレビューの補足使用条件 」を参照してください。

Azure Active Directory (Azure AD) のカスタム セキュリティ属性は、Azure AD オブジェクトを定義して割り当てることができるビジネス固有の属性 (キーと値のペア) です。

この記事では、ユーザーとアプリケーション (サービス プリンシパル) のさまざまな種類のカスタム セキュリティ属性を割り当て、更新、一覧表示、または削除する方法の例を示します。 カスタム セキュリティ属性の割り当てを割り当てる、更新する、または削除するには、Update user または Update servicePrincipal API の操作を使用PATCHする必要があります。 カスタム セキュリティ属性の割り当てを一覧表示するには、 Get userList usersGet servicePrincipal、または List servicePrincipals API を使用します。

アクセス許可

割り当て、更新、または削除

カスタム セキュリティ属性の割り当てを割り当てる、更新する、または削除するには、呼び出し元プリンシパルに次の Azure AD ロールを割り当てる必要があります。 既定では、グローバル管理者やその他の管理者ロールには、カスタム セキュリティ属性の読み取り、定義、または割り当てに対するアクセス許可がありません。

また、呼び出し元プリンシパルには、次のアクセス許可が付与されている必要があります。

アプリケーションのカスタム セキュリティ属性の割り当てを読み取り、割り当て、更新、または削除するためのアクセス許可は、 CustomSecAttributeAssignment.ReadWrite.All によって付与されます。 ユーザーなどのリソース オブジェクトを読み取るアクセス許可は、 User.Read.All などのリソース オブジェクトのアクセス許可を使用して個別に付与されます。

リスト

カスタム セキュリティ属性の割り当てを一覧表示または読み取りするには、呼び出し元プリンシパルに次のいずれかの Azure AD ロールを割り当てる必要があります。 既定では、グローバル管理者やその他の管理者ロールには、カスタム セキュリティ属性の読み取り、定義、または割り当てに対するアクセス許可がありません。

また、呼び出し元プリンシパルには、次のアクセス許可が付与されている必要があります。

アプリケーションのカスタム セキュリティ属性の割り当てを読み取るためのアクセス許可は、 CustomSecAttributeAssignment.Read.All によって付与されます。 ユーザーなどのリソース オブジェクトを読み取るアクセス許可は、 User.Read.All などのリソース オブジェクトのアクセス許可を使用して個別に付与されます。

カスタム セキュリティ属性を割り当てる

例 1: 文字列値を持つカスタム セキュリティ属性をユーザーに割り当てる

次の例は、 Update ユーザー API を使用して、文字列値を持つカスタム セキュリティ属性をユーザーに割り当てる方法を示しています。

  • 属性セット: 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: 文字列値を持つカスタム セキュリティ属性をサービス プリンシパルに割り当てる

次の例では、 Update ユーザー API を使用して、文字列値を持つカスタム セキュリティ属性をサービス プリンシパルに割り当てる方法を示します。

  • 属性セット: 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: 複数文字列値を持つカスタム セキュリティ属性をユーザーに割り当てる

次の例は、 Update ユーザー API を使用して、複数文字列値を持つカスタム セキュリティ属性をユーザーに割り当てる方法を示しています。

  • 属性セット: 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: 整数値を持つカスタム セキュリティ属性をユーザーに割り当てる

次の例は、 Update ユーザー API を使用して、整数値を持つカスタム セキュリティ属性をユーザーに割り当てる方法を示しています。

  • 属性セット: 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: 複数整数値を持つカスタム セキュリティ属性をユーザーに割り当てる

次の例では、 Update ユーザー API を使用して、複数の整数値を持つカスタム セキュリティ属性をユーザーに割り当てる方法を示します。

  • 属性セット: 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: ブール値を持つカスタム セキュリティ属性をユーザーに割り当てる

次の例は、 Update ユーザー API を使用して、ブール値を持つカスタム セキュリティ属性をユーザーに割り当てる方法を示しています。

  • 属性セット: 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: ユーザーの整数値を使用してカスタム セキュリティ属性の割り当てを更新する

次の例では、Update ユーザー API を使用して 、ユーザー の整数値を使用してカスタム セキュリティ属性の割り当てを更新する方法を示します。

  • 属性セット: 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: ユーザーのブール値を使用してカスタム セキュリティ属性の割り当てを更新する

次の例では、Update ユーザー API を使用して 、ユーザー のブール値を使用してカスタム セキュリティ属性の割り当てを更新する方法を示します。

  • 属性セット: 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: ユーザーのカスタム セキュリティ属性の割り当てを取得する

次の例では、Get user API を使用して 、ユーザー のカスタム セキュリティ属性の割り当てを取得する方法を示します。

属性 #1

  • 属性セット: Engineering
  • 属性: Project
  • 属性データ型: 文字列のコレクション
  • 属性値: ["Baker","Cascade"]

属性 #2

  • 属性セット: Engineering
  • 属性: CostCenter
  • 属性データ型: 整数のコレクション
  • 属性値: [1001]

属性 #3

  • 属性セット: Engineering
  • 属性: Certification
  • 属性データ型: ブール値
  • 属性値: true

属性 #4

  • 属性セット: Marketing
  • 属性: EmployeeId
  • 属性データ型: 文字列
  • 属性値: "QN26904"

要求

GET https://graph.microsoft.com/beta/users/{id}?$select=customSecurityAttributes

応答

HTTP/1.1 200 OK

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(customSecurityAttributes)/$entity",
    "customSecurityAttributes": {
        "Marketing": {
            "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
            "EmployeeId": "QN26904"
        },
        "Engineering": {
            "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
            "Project@odata.type": "#Collection(String)",
            "Project": [
                "Baker",
                "Cascade"
            ],
            "CostCenter@odata.type": "#Collection(Int32)",
            "CostCenter": [
                1001
            ],
            "Certification": true
        }
    }
}

ユーザーにカスタム セキュリティ属性が割り当てられていない場合、または呼び出し元のプリンシパルにアクセス権がない場合、次の応答が返されます。

HTTP/1.1 200 OK
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(customSecurityAttributes)/$entity",
    "customSecurityAttributes": null
}

例 2: 値と等しいカスタム セキュリティ属性の割り当てを持つすべてのユーザーを一覧表示する

次の例では、 List users API を使用して、値と等しいカスタム セキュリティ属性の割り当てを持つすべてのユーザーを一覧表示する方法を示します。 この例では、 と等しい値を持つ という名前 AppCountry のカスタム セキュリティ属性を持つユーザーを取得します Canada。 フィルター値では、大文字と小文字が区別されます。 要求またはヘッダーを追加 ConsistencyLevel=eventual する必要があります。 要求が正しくルーティングされるようにも 含める $count=true 必要があります。

ユーザー #1

  • 属性セット: Marketing
  • 属性: AppCountry
  • 属性データ型: 文字列のコレクション
  • 属性値: ["India","Canada"]

ユーザー #2

  • 属性セット: Marketing
  • 属性: AppCountry
  • 属性データ型: 文字列のコレクション
  • 属性値: ["Canada","Mexico"]

要求

GET https://graph.microsoft.com/beta/users?$count=true&$select=id,displayName,customSecurityAttributes&$filter=customSecurityAttributes/Marketing/AppCountry eq 'Canada'
ConsistencyLevel: eventual

応答

HTTP/1.1 200 OK

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(id,displayName,customSecurityAttributes)",
    "@odata.count": 2,
    "value": [
        {
            "id": "dbaf3778-4f81-4ea0-ac1c-502a293c12ac",
            "displayName": "Jiya",
            "customSecurityAttributes": {
                "Engineering": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "Datacenter@odata.type": "#Collection(String)",
                    "Datacenter": [
                        "India"
                    ]
                },
                "Marketing": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "AppCountry@odata.type": "#Collection(String)",
                    "AppCountry": [
                        "India",
                        "Canada"
                    ],
                    "EmployeeId": "KX19476"
                }
            }
        },
        {
            "id": "6bac433c-48c6-4213-a316-1428de32701b",
            "displayName": "Jana",
            "customSecurityAttributes": {
                "Marketing": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "AppCountry@odata.type": "#Collection(String)",
                    "AppCountry": [
                        "Canada",
                        "Mexico"
                    ],
                    "EmployeeId": "GS46982"
                }
            }
        }
    ]
}

例 3: 値で始まるカスタム セキュリティ属性の割り当てを持つすべてのユーザーを一覧表示する

次の例では、 List users API を使用して、値で始まるカスタム セキュリティ属性の割り当てを持つすべてのユーザーを一覧表示する方法を示します。 この例では、 で始まる値を持つ という名前 EmployeeId のカスタム セキュリティ属性を持つユーザーを GS取得します。 フィルター値では、大文字と小文字が区別されます。 要求またはヘッダーを追加 ConsistencyLevel=eventual する必要があります。 要求が正しくルーティングされるようにも 含める $count=true 必要があります。

ユーザー #1

  • 属性セット: Marketing
  • 属性: EmployeeId
  • 属性データ型: 文字列
  • 属性値: "KX19476"

ユーザー #2

  • 属性セット: Marketing
  • 属性: EmployeeId
  • 属性データ型: 文字列
  • 属性値: "GS46982"

要求

GET https://graph.microsoft.com/beta/users?$count=true&$select=id,displayName,customSecurityAttributes&$filter=startsWith(customSecurityAttributes/Marketing/EmployeeId,'GS')
ConsistencyLevel: eventual

応答

HTTP/1.1 200 OK

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(id,displayName,customSecurityAttributes)",
    "@odata.count": 1,
    "value": [
        {
            "id": "6bac433c-48c6-4213-a316-1428de32701b",
            "displayName": "Jana",
            "customSecurityAttributes": {
                "Marketing": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "AppCountry@odata.type": "#Collection(String)",
                    "AppCountry": [
                        "Canada",
                        "Mexico"
                    ],
                    "EmployeeId": "GS46982"
                }
            }
        }
    ]
}

例 4: 値と等しくないカスタム セキュリティ属性の割り当てを持つすべてのユーザーを一覧表示する

次の例では、 List users API を使用して、値と等しくないカスタム セキュリティ属性の割り当てを持つすべてのユーザーを一覧表示する方法を示します。 この例では、 と等しくないCanada値を持つ という名前AppCountryのカスタム セキュリティ属性を持つユーザーを取得します。 フィルター値では、大文字と小文字が区別されます。 要求またはヘッダーを追加 ConsistencyLevel=eventual する必要があります。 要求が正しくルーティングされるようにも 含める $count=true 必要があります。

ユーザー #1

  • 属性セット: Marketing
  • 属性: AppCountry
  • 属性データ型: 文字列のコレクション
  • 属性値: ["France"]

その他のすべてのユーザー

  • AppCountry 属性が追加されていない

要求

GET https://graph.microsoft.com/beta/users?$count=true&$select=id,displayName,customSecurityAttributes&$filter=customSecurityAttributes/Marketing/AppCountry ne 'Canada'
ConsistencyLevel: eventual

応答

HTTP/1.1 200 OK

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(id,displayName,customSecurityAttributes)",
    "@odata.count": 32,
    "value": [
        {
            "id": "c4f9ecd3-d3c1-4544-b49a-bc9bb62beb67",
            "displayName": "Alain",
            "customSecurityAttributes": null
        },
        {
            "id": "de4f1218-b0fb-4449-b3a0-1e1dd193e6e7",
            "displayName": "Joe",
            "customSecurityAttributes": {
                "Engineering": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "Project3@odata.type": "#Collection(String)",
                    "Project3": [
                        "Baker",
                        "Cascade"
                    ],
                    "CostCenter@odata.type": "#Collection(Int32)",
                    "CostCenter": [
                        1001
                    ],
                    "Certification": true
                },
                "Marketing": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "EmployeeId": "QN26904"
                }
            }
        },
        {
            "id": "f24d1474-ded5-432d-be08-8abd39921aac",
            "displayName": "Isabella",
            "customSecurityAttributes": {
                "Marketing": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "AppCountry@odata.type": "#Collection(String)",
                    "AppCountry": [
                        "France"
                    ]
                }
            }
        },
        {
            "id": "849e81fe-1109-4d57-9536-a25d537eec1f",
            "displayName": "Dara",
            "customSecurityAttributes": {
                "Engineering": {
                    "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
                    "ProjectDate": "2023-04-12"
                }
            }
        },
        {
            "id": "42c88239-db99-45f0-85af-cbb6c8acb2a3",
            "displayName": "Chandra",
            "customSecurityAttributes": null
        }
    ]
}

カスタム セキュリティ属性の割り当てを削除する

例 1: 単一値のカスタム セキュリティ属性の割り当てをユーザーから削除する

次の例では、Update ユーザー API を使用して 、ユーザー から 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: ユーザーから複数値のカスタム セキュリティ属性の割り当てを削除する

次の例では、 Update ユーザー API を使用して、ユーザーから複数の値をサポートするカスタム セキュリティ属性の割り当てを削除する方法を示します。

  • 属性セット: 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

次の手順