mip::PolicyEngine は、プロファイルの読み込みを除き、Policy SDK が実行できるすべての操作を実装します。
実装: ポリシー エンジンを追加する
実装: ポリシー エンジン設定を作成する
プロファイルと同様に、エンジンには設定オブジェクト mip::PolicyEngine::Settingsも必要です。 このオブジェクトには、一意のエンジン識別子、 mip::AuthDelegate 実装のオブジェクト、デバッグまたはテレメトリ用のカスタマイズ可能なクライアント データ、および必要に応じてロケールが格納されます。
次の例では、アプリケーション ユーザーの ID を使用して engineSettings というPolicyEngine::Settings オブジェクトを作成します。
PolicyEngine::Settings engineSettings(
mip::Identity(mUsername), // mip::Identity.
authDelegateImpl, // Auth delegate object
"", // Client data. Customizable by developer, stored with engine.
"en-US", // Locale.
false); // Load sensitive information types for driving classification.
この方法で engineSettings を作成する場合は、一意の engineId も明示的に設定します。
engineSettings.SetEngineId(engineId);
ユーザー名または電子メールを使用すると、ユーザーがサービスまたはアプリケーションを使用するたびに、同じエンジンが確実に読み込まれます。
また、カスタム エンジン ID を指定することも有効です。
PolicyEngine::Settings engineSettings(
"myEngineId", // String
authDelegateImpl, // Auth delegate object
"", // Client data in string format. Customizable by developer, stored with engine.
"en-US", // Locale. Default is en-US
false); // Load sensitive information types for driving classification. Default is false.
ベスト プラクティスとして、関連付けられているユーザー (できればユーザー プリンシパル名) にエンジンを接続する最初のパラメーター id を使用します。
実装: ポリシー エンジンを追加する
エンジンを追加するには、プロファイルの読み込みに使用される future/promise パターンに戻ります。
mip::Profileの約束を作成する代わりに、mip::PolicyEngineを使用します。
// Auto profile will be std::shared_ptr<mip::Profile>.
auto profile = profileFuture.get();
// Create the delegate
auto authDelegateImpl = std::make_shared<sample::auth::AuthDelegateImpl>(appInfo, userName, password);
// Create the PolicyEngine::Settings object.
PolicyEngine::Settings engineSettings("UniqueID", authDelegateImpl, "");
// Create a promise for std::shared_ptr<mip::PolicyEngine>.
auto enginePromise = std::make_shared<std::promise<std::shared_ptr<mip::PolicyEngine>>>();
// Instantiate the future from the promise.
auto engineFuture = enginePromise->get_future();
// Add the engine using AddEngineAsync, passing in the engine settings and the promise.
profile->AddEngineAsync(engineSettings, enginePromise);
// Get the future value and store in std::shared_ptr<mip::PolicyEngine>.
auto engine = engineFuture.get();
このコードは、認証されたユーザーのエンジンをプロファイルに追加します。
実装: 秘密度ラベルを一覧表示する
追加されたエンジンを使用すると、 engine->ListSensitivityLabels()を呼び出すことによって、認証されたユーザーが使用できるすべての秘密度ラベルを一覧表示できます。
ListSensitivityLabels() は、サービスから特定のユーザーについて、ラベルの一覧と各ラベルの属性を取得します。 結果は、 std::shared_ptr<mip::Label>のベクターに格納されます。
実装: ListSensitivityLabels()
std::vector<shared_ptr<mip::Label>> labels = engine->ListSensitivityLabels();
実装: ラベルを印刷する
//Iterate through all labels in the vector
for (const auto& label : labels) {
//print the label name
cout << label->GetName() << endl;
//Iterate through all child labels
for (const auto& child : label->GetChildren()) {
//Print the label with some formatting
cout << "-> " << child->GetName() << endl;
}
}
名前を印刷すると、アプリケーションがサービスからポリシーを正常にプルし、ラベルを取得したことが示されます。 ラベルを適用するには、ラベル識別子が必要です。 前のスニペットを変更してラベル ID を返します。
for (const auto& label : labels) {
//Print label name and GUID
cout << label->GetName() << " : " << label->GetId() << endl;
//Print child label name and GUID
for (const auto& child : label->GetChildren()) {
cout << "-> " << child->GetName() << " : " << child->GetId() << endl;
}
}
ListSensitivityLabels()によって返されるmip::Labelのコレクションを使用して、ユーザーが使用できるすべてのラベルを表示し、選択した場合は ID を使用してファイルにラベルを適用できます。