Microsoft Information Protection SDK - ポリシーSDKプロファイルの考え方

ポリシー SDK 操作を実行する前に、 mip::Profile を読み込みます。

次の 2 つの例は、状態ストレージまたはメモリ内専用のローカル ストレージを使用して profileSettings オブジェクトを作成する方法を示しています。

プロファイルを読み込む

MipContextとProfileObserverを定義したら、それらを使用してmip::PolicyProfileをインスタンス化します。 mip::PolicyProfile オブジェクトの作成には、mip::PolicyProfile::Settings と mip::MipContext が必要です。

Profile::Settings パラメータ

PolicyProfile::Settings コンストラクターは、次の 4 つのパラメーターを受け入れます。

  • const std::shared_ptr<MipContext>: アプリケーション情報、状態パスなどを格納するために初期化された mip::MipContext オブジェクト。
  • mip::CacheStorageType: 状態を格納する方法 (メモリ内、ディスク上、またはディスク上かつ暗号化) を定義します。 詳細については、キャッシュ ストレージの概念に関する記事を参照してください。
  • std::shared_ptr<mip::PolicyProfile::Observer> observer: プロファイル Observer 実装への共有ポインター (PolicyProfile、ProtectionProfile および FileProfile 内)。

次の 2 つの例は、状態ストレージまたはメモリ内専用のローカル ストレージを使用して profileSettings オブジェクトを作成する方法を示しています。

メモリにのみの状態を格納する

mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };

std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(mAppInfo,
				                                                                                  "mip_data",
                                                                                        		  mip::LogLevel::Trace,
                                                                                                  false);

std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

PolicyProfile::Settings profileSettings(
    mMipContext,                                  // mipContext object
    mip::CacheStorageType::InMemory,              // use in memory storage
    std::make_shared<PolicyProfileObserverImpl>()); // new protection profile observer

ディスク上のストレージ パスからのプロファイル設定の読み取り/書き込み

mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };

std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(mAppInfo,
			                                                                                      "mip_data",
                                                                                       			  mip::LogLevel::Trace,
                                                                                                  false);

std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

PolicyProfile::Settings profileSettings(
    mipContext,                                    // mipContext object
    mip::CacheStorageType::OnDisk,                 // use on disk storage
    std::make_shared<PolicyProfileObserverImpl>());  // new protection profile observer

次に、promise/future パターンを使用して、Profile をロードします。

auto profilePromise = std::make_shared<std::promise<std::shared_ptr<Profile>>>();
auto profileFuture = profilePromise->get_future();
Profile::LoadAsync(profileSettings, profilePromise);

アプリケーションがプロファイルを正常に読み込む場合、 ProfileObserver::OnLoadSuccess、 mip::Profile::Observer::OnLoadSuccessの実装が通知されます。 SDK は、結果のオブジェクト (この場合は mip::Profile)、コンテキストをパラメーターとしてオブザーバー関数に渡します。

コンテキストは、非同期操作を処理するために作成されたstd::promiseへのポインターです。 この関数は、最初のパラメーターに渡された Profile オブジェクトに promise の値を設定します。 main 関数は、 Future.get()を使用すると、呼び出し元のスレッドに新しいオブジェクトに結果を格納できます。

//get the future value and store in profile.
auto profile = profileFuture.get();

全体をまとめる

オブザーバーと認証デリゲートを実装したら、プロファイルを完全に読み込むことができます。 次のコード スニペットでは、必要なすべてのヘッダーが既に含まれていることを前提としています。

int main()
{
    const string userName = "MyTestUser@contoso.com";
    const string password = "P@ssw0rd!";
    const string clientId = "MyClientId";

    mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
 
    std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(mAppInfo,
				                                                                                       "mip_data",
                                                                                        			   mip::LogLevel::Trace,
                                                                                                       false);

    std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

    PolicyProfile::Settings profileSettings(
        mMipContext,                                    // mipContext object
        mip::CacheStorageType::OnDisk,                 // use on disk storage
        std::make_shared<PolicyProfileObserverImpl>());  // new protection profile observer

    auto profilePromise = std::make_shared<promise<shared_ptr<PolicyProfile>>>();
    auto profileFuture = profilePromise->get_future();
    Profile::LoadAsync(profileSettings, profilePromise);
    auto profile = profileFuture.get();
}

このコードはプロファイルを読み込み、 profileというオブジェクトに格納します。

次のステップ

プロファイルが追加されたので、次の手順は、プロファイルにエンジンを追加することです。

ポリシー エンジンの概念