Microsoft Information Protection SDK - Beleids-SDK-profielconcepten

Laad mip::Profile voordat u bewerkingen met de Policy SDK uitvoert.

In de volgende twee voorbeelden ziet u hoe u het profileSettings-object maakt met behulp van lokale opslag voor statusopslag of alleen in het geheugen.

Een profiel laden

Nadat u deze hebt gedefinieerd MipContext en ProfileObserver, gebruikt u deze om te instantiëren mip::PolicyProfile. Het maken van het mip::PolicyProfile object vereist mip::PolicyProfile::Settings en mip::MipContext.

Profiel::Instellingenparameters

De PolicyProfile::Settings constructor accepteert de volgende vier parameters:

  • const std::shared_ptr<MipContext>: Het mip::MipContext object dat is geïnitialiseerd voor het opslaan van toepassingsgegevens, het statuspad, enzovoort.
  • mip::CacheStorageType: Definieert hoe de status moet worden opgeslagen: In het geheugen, op schijf of op schijf en versleuteld. Zie de cacheopslagconcepten voor meer informatie.
  • std::shared_ptr<mip::PolicyProfile::Observer> observer: Een gedeelde aanwijzer naar de profiel-implementatie Observer (in PolicyProfile, ProtectionProfileen FileProfile).

In de volgende twee voorbeelden ziet u hoe u het profileSettings-object maakt met behulp van lokale opslag voor statusopslag of alleen in het geheugen.

Alleen de status opslaan in het geheugen

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

Profielinstellingen lezen/schrijven vanuit het opslagpad op schijf

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

Gebruik vervolgens het promise/future-patroon om het Profile te laden.

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

Als de toepassing succesvol een profiel laadt, wordt ProfileObserver::OnLoadSuccess, de implementatie van mip::Profile::Observer::OnLoadSuccess, op de hoogte gesteld. De SDK geeft het resulterende object door, in dit geval een mip::Profile, en de context als parameters aan de waarnemersfunctie.

De context is een aanwijzer naar de std::promise die is gemaakt om de asynchrone bewerking af te handelen. De functie stelt de waarde van de belofte in voor het profielobject dat is doorgegeven voor de eerste parameter. Wanneer de hoofdfunctie gebruikmaakt Future.get(), kan het resultaat worden opgeslagen in een nieuw object in de aanroepende thread.

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

Alles samenbrengen

Nadat u de observers en authenticatiedelegate hebt geïmplementeerd, kunt u een profiel volledig laden. In het volgende codefragment wordt ervan uitgegaan dat alle benodigde headers al zijn opgenomen.

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

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

De code laadt het profiel en slaat het op in het object met de naam profile.

Volgende stappen 

Nu het profiel is toegevoegd, is de volgende stap om een motor aan het profiel toe te voegen.

Concepten van beleidsengines