Delen via


Microsoft Information Protection SDK - Concepten van beveiligings-SDK-profielen

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

Een profiel laden

Nu de ProtectionProfileObserverImpl definitie is, gebruiken we deze om te instantiëren mip::ProtectionProfile. Voor het maken van het mip::ProtectionProfile object is vereist mip::ProtectionProfile::Settings.

ProtectionProfile::Instellingenparameters

  • 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.
  • std::shared_ptr<mip::ConsentDelegate>: Een gedeelde aanwijzer van klasse mip::ConsentDelegate.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: Een gedeelde aanwijzer naar de profiel-implementatie Observer (in PolicyProfile, ProtectionProfileen FileProfile).

In de twee onderstaande voorbeelden ziet u hoe u het profileSettings-object maakt met behulp van lokale opslag voor statusopslag en 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);

ProtectionProfile::Settings profileSettings(
    mMipContext,                                        // mipContext object
    mip::CacheStorageType::InMemory,                   // use in memory storage    
    std::make_shared<ConsentDelegateImpl>(),           // new consent delegate
    std::make_shared<ProtectionProfileObserverImpl>()); // 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);

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

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

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

Als we een profiel hebben geladen en die bewerking is geslaagd, ProtectionProfileObserverImpl::OnLoadSuccess, wordt onze implementatie van mip::ProtectionProfile::Observer::OnLoadSuccess aangeroepen. De resulterende object- of uitzonderingspointer, evenals de context, worden doorgegeven als parameters aan de functie. De context is een aanwijzer naar de std::promise die we maakten om de asynchrone bewerking te verwerken. De functie stelt eenvoudigweg de waarde van de promise in op het object ProtectionProfile (context). Wanneer de hoofdfunctie wordt gebruikt Future.get(), kan het resultaat worden opgeslagen in een nieuw object.

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

Samenvatting

Door de waarnemers en authenticatie-gedelegeerde volledig te hebben geïmplementeerd, is het nu mogelijk om een profiel volledig te laden. In het onderstaande 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);

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

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

Het eindresultaat is dat het profiel is geladen en is opgeslagen in het object met de naam profile.

Volgende stappen

Nu het profiel is toegevoegd, is de volgende stap dan het toevoegen van een motor aan het profiel.

Concepten van beveiligingsengines