共用方式為


Microsoft 資訊保護 SDK - 原則 SDK 配置檔概念

必須先載入 , mip::Profile 才能執行任何原則 SDK 作業。

下列兩個範例示範如何使用本機記憶體建立 profileSettings 物件,以用於狀態記憶體,以及僅限記憶體內部記憶體。

載入配置檔

現在已 MipContext 定義 和 ProfileObserver ,我們將使用它們來具現化 mip::PolicyProfilemip::PolicyProfile建立物件需要 mip::PolicyProfile::Settingsmip::MipContext

Profile::Settings 參數

PolicyProfile::Settings 構函式接受下列四個參數:

  • const std::shared_ptr<MipContext> mip::MipContext:初始化以儲存應用程式資訊、狀態路徑等的物件。
  • mip::CacheStorageType:定義如何儲存狀態:在記憶體、磁碟或磁碟上,以及加密。 如需詳細資訊,請參閱快 取記憶體概念
  • std::shared_ptr<mip::PolicyProfile::Observer> observer:配置文件 Observer 實作的共享指標(在 PolicyProfileProtectionProfileFileProfile中)。

下列兩個範例示範如何使用本機記憶體建立 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 。 在此情況下 mip::Profile,產生的物件會以參數的形式傳入觀察者函式,以及內容。

內容是我們建立來處理異步作業的指標std::promise。 函式只會將 promise 的值設定為針對第一個參數傳入的 Profile 物件。 當main函式使用 Future.get()時,結果可以儲存在呼叫線程的新物件中。

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

將它放在一起

完全實作觀察者和驗證委派之後,現在可以完全載入配置檔。 下列程式代碼狙擊假設已包含所有必要的標頭。

int main()
{
    const string userName = "MyTestUser@consoto.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的物件中。

後續步驟

現在已新增配置檔,下一個步驟是將引擎新增至配置檔。

原則引擎概念