Microsoft Information Protection SDK - ポリシー SDK エンジンの概念

mip::PolicyEngine は、プロファイルの読み込みを除き、Policy SDK が実行できるすべての操作を実装します。

実装: ポリシー エンジンを追加する

実装: ポリシー エンジン設定を作成する

プロファイルと同様に、エンジンには設定オブジェクト mip::PolicyEngine::Settingsも必要です。 このオブジェクトには、一意のエンジン識別子、 mip::AuthDelegate 実装のオブジェクト、デバッグまたはテレメトリに使用できるカスタマイズ可能なクライアント データ、および必要に応じてロケールが格納されます。

ここでは、アプリケーション ユーザーの ID を使用して FileEngine::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;
  }
}

mip::Labelによって返されるListSensitivityLabels()のコレクションを使用して、ユーザーが使用できるすべてのラベルを表示し、選択した場合は ID を使用してファイルにラベルを適用できます。