Microsoft Information Protection SDK - 保護 SDK プロファイルの概念

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

プロファイルの読み込み

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

保護プロファイル::設定パラメータ

  • std::shared_ptr<MipContext>: アプリケーション情報、状態パスなどを格納するために初期化された mip::MipContext オブジェクト。
  • mip::CacheStorageType: 状態を格納する方法 (メモリ内、ディスク上、またはディスク上かつ暗号化) を定義します。
  • std::shared_ptr<mip::ConsentDelegate>: クラス mip::ConsentDelegate の共有ポインター。
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: プロファイル Observer 実装への共有ポインター (PolicyProfileProtectionProfile および 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);

ProtectionProfile::Settings profileSettings(
    mMipContext,                                        // mipContext object
    mip::CacheStorageType::InMemory,                   // use in memory storage    
    std::make_shared<ConsentDelegateImpl>(),           // new consent delegate
    std::make_shared<ProtectionProfileObserverImpl>()); // 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);

ProtectionProfile::Settings profileSettings(
    mMipContext,                                         // mipContext object
    mip::CacheStorageType::OnDisk,                      // use on disk storage    
    std::make_shared<ConsentDelegateImpl>(),            // new consent delegate
    std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile

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

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

プロファイルをロード済みで、その操作に成功した場合は、mip::ProtectionProfile::Observer::OnLoadSuccess の実装である ProtectionProfileObserverImpl::OnLoadSuccess が呼び出されます。 結果オブジェクトまたは例外ポインターとコンテキストは、パラメーターとして関数に渡されます。 コンテキストは、非同期操作を処理するために作成した std::promise へのポインターです。 この関数は、Promise の値を ProtectionProfile オブジェクト (コンテキスト) に設定するだけです。 メイン関数が 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);

    ProtectionProfile::Settings profileSettings(
        mMipContext,                                    // mipContext object
        mip::CacheStorageType::OnDisk,                 // use on disk storage        
        std::make_shared<ConsentDelegateImpl>(),       // new consent delegate
        std::make_shared<ProfileObserver>());          // new protection profile observer

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

最終的な結果として、プロファイルが正常にロードされ、profile と呼ばれるオブジェクトに格納されます。

次のステップ

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

Protection エンジンの概念