Dela via


Microsoft Information Protection SDK – Princip-SDK-profilbegrepp

mip::Profile Måste läsas in innan några princip-SDK-åtgärder kan utföras.

De två exemplen nedan visar hur du skapar profilen Inställningar-objektet med hjälp av lokal lagring för både tillståndslagring och endast minnesinternt.

Läsa in en profil

Nu när MipContext och ProfileObserver har definierats använder vi dem för att instansiera mip::PolicyProfile. För att skapa mip::PolicyProfile objektet krävs mip::PolicyProfile::Settings och mip::MipContext.

Profil::Inställningar Parametrar

Konstruktorn PolicyProfile::Settings accepterar fyra parametrar som anges nedan:

  • const std::shared_ptr<MipContext>: Objektet mip::MipContext som initierades för att lagra programinformation, tillståndssökväg osv.
  • mip::CacheStorageType: Definierar hur du lagrar tillstånd: I minne, på disk eller på disk och krypterad. Mer information finns i begreppen cachelagring.
  • std::shared_ptr<mip::PolicyProfile::Observer> observer: En delad pekare till profilimplementeringen Observer (i PolicyProfile, ProtectionProfileoch FileProfile).

De två exemplen nedan visar hur du skapar profilen Inställningar-objektet med hjälp av lokal lagring för både tillståndslagring och endast minnesinternt.

Lagra endast tillstånd i minnet

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

Läs-/skrivprofilinställningar från lagringssökväg på disk

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

Använd sedan mönstret promise/future för att läsa in Profile.

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

Om en profil har lästs in meddelas ProfileObserver::OnLoadSuccessvår implementering av mip::Profile::Observer::OnLoadSuccess . Det resulterande objektet, i det här fallet en mip::Profile, samt kontexten, skickas in som parametrar till observatörsfunktionen.

Kontexten är en pekare till den std::promise vi skapade för att hantera asynkroniseringsåtgärden. Funktionen anger helt enkelt värdet för löftet till det profilobjekt som skickades in för den första parametern. När huvudfunktionen använder Future.get()kan resultatet lagras i ett nytt objekt i den anropande tråden.

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

Sätta ihop den

Efter att ha implementerat observatörerna och autentiseringsdelegaten är det nu möjligt att läsa in en profil fullt ut. Kodfragmentet nedan förutsätter att alla nödvändiga rubriker redan ingår.

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

Slutresultatet är att vi har läst in profilen och lagrat i objektet med namnet profile.

Nästa steg

Nu när profilen har lagts till är nästa steg att lägga till en motor i profilen.

Principmotorbegrepp