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

Microsoft Entra IDのカスタム セキュリティ属性は、Microsoft Entra オブジェクトに定義して割り当てることができるビジネス固有の属性 (キーと値のペア) です。 これらの属性は、Azure 属性ベースのアクセス制御 (Azure ABAC) を使用して、情報の格納、オブジェクトの分類、特定の Azure リソースに対するきめ細かいアクセス制御の適用に使用できます。

カスタム セキュリティ属性は、ユーザーとサービス プリンシパルでのみサポートされます。 この記事では、Microsoft Graph を使用してユーザーとアプリケーションのさまざまな種類のカスタム セキュリティ属性を割り当て、更新、一覧表示、または削除する方法の例を示します。

前提条件

  • カスタム セキュリティ属性を作成します。 カスタム セキュリティ属性定義を定義および管理する方法の詳細については、「 Microsoft Graph を使用したカスタム セキュリティ属性の概要」を参照してください。
  • 委任されたシナリオの場合、呼び出しには次のアクセス許可と管理ロールを割り当てる必要があります。
    • 割り当て、更新、または削除するには:
      • Microsoft Entra ロール: 属性割り当て管理者
      • Microsoft Graph には、次のアクセス許可が必要です。
        • ユーザー: CustomSecAttributeAssignment.ReadWrite.All と User.Read.All
        • サービス プリンシパル: CustomSecAttributeAssignment.ReadWrite.All と Application.Read.All
    • というコードを次のように変更してください。
      • Microsoft Entraロール: 属性割り当て閲覧者または属性割り当て管理者
      • Microsoft Graph には、次のアクセス許可が必要です。
        • ユーザー: CustomSecAttributeAssignment.Read.All と User.Read.All
        • サービス プリンシパル: CustomSecAttributeAssignment.Read.All と Application.Read.All

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

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

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

  • 属性セット: Engineering
  • 属性: ProjectDate
  • 属性データ型: 文字列
  • 属性値: "2022-10-01"

要求

PATCH https://graph.microsoft.com/v1.0/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 servicePrincipal API を使用して、文字列値を持つカスタム セキュリティ属性をサービス プリンシパルに割り当てる方法を示しています。

  • 属性セット: Engineering
  • 属性: ProjectDate
  • 属性データ型: 文字列
  • 属性値: "2022-10-01"

要求

PATCH https://graph.microsoft.com/v1.0/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/v1.0/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/v1.0/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/v1.0/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/v1.0/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/v1.0/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/v1.0/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/v1.0/users/{id}?$select=customSecurityAttributes

応答

HTTP/1.1 200 OK

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$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/v1.0/$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/v1.0/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/v1.0/$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/v1.0/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/v1.0/$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/v1.0/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/v1.0/$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/v1.0/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/v1.0/users/{id}
Content-type: application/json

{
    "customSecurityAttributes":
    {
        "Engineering":
        {
            "@odata.type":"#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
            "Project":[]
        }
    }
}

応答

HTTP/1.1 204 No Content

次の手順