Microsoft インフォメーション プロテクション SDK - ファイル SDK プロファイルの概念

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

プロファイルをインスタンス化する前に、次のコードの前提条件を満たします。

  • MipContext: 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::Settings パラメータ

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 実装への共有ポインター (PolicyProfile、ProtectionProfile および 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 が呼び出されます。 SDK は、結果のオブジェクトまたは例外ポインターとコンテキストをパラメーターとして関数に渡します。 コンテキストは、非同期操作を処理するために作成された std::promise へのポインターです。 この関数は、最初のパラメーターに渡された FileProfile オブジェクトに 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);

    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というオブジェクトに格納します。

次のステップ

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