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

プロファイルは、MIP SDK のすべての操作のルート クラスです。 ファイル SDK 機能のいずれかを使用する前に、FileProfile を作成する必要があり、今後の操作はすべて、プロファイルまたはプロファイルに追加されたその他のオブジェクトによって実行されます。

プロファイルのインスタンス化を試みる前に満たす必要があるコード前提条件がいくつかあります。

  • MipContext が作成され、mip::FileProfile オブジェクトにアクセスできるオブジェクトに格納されています。
  • ConsentDelegateImpl は、mip::ConsentDelegate を実装します。
  • アプリケーションは、Microsoft Entra ID に登録されており、クライアント ID は、アプリケーションまたは構成ファイルにハードコーディングされています。
  • mip::FileProfile::Observer に継承するクラスが適切に実装されています。

プロファイルの読み込み

ProfileObserver および ConsentDelegateImpl が定義されると、mip::FileProfile はインスタンス化できるようになります。 mip::FileProfile オブジェクトを作成するには、FileProfile に関する設定情報をすべて保持するために [mip::MipContext] が必要で、格納するために mip::FileProfile::Settings が必要です。

FileProfile::設定パラメーター

FileProfile::Settings コンストラクターは、以下に一覧されている 5 ちのパラメーターを承認します。

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

次の例では、状態ストレージとメモリ内専用のローカル ストレージを使用して 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);

FileProfile::Settings profileSettings(
    mMipContext,                                  // mipContext object
    mip::CacheStorageType::InMemory,              // use in memory storage
    std::make_shared<ConsentDelegateImpl>(),      // new consent delegate
    std::make_shared<FileProfileObserverImpl>()); // new protection profile observer

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

次のコード切り取りは、./mip_app_data にすべてのアプリ状態データを保管するように FileProfile に指示します。

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);

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

プロファイルのロード

上記のいずれかのアプローチの詳細を使用して、promise/future パターンを使用して、FileProfile をロードします。

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

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

    FileProfile::Settings profileSettings(
        mMipContext,                                   // MipContext object
        mip::CacheStorageType::OnDisk,                 // use on disk storage        
        std::make_shared<ConsentDelegateImpl>(),       // new consent delegate
        std::make_shared<FileProfileObserverImpl>());  // new file profile observer

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

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

次のステップ

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