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

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

Een profiel laden

Nu ProtectionProfileObserverImpl is gedefinieerd, gebruikt u het om mip::ProtectionProfile te instantiëren. Voor het maken van het mip::ProtectionProfile object is vereist mip::ProtectionProfile::Settings.

ProtectionProfile::Instellingenparameters

  • std::shared_ptr<MipContext>: Het mip::MipContext object is geïnitialiseerd voor het opslaan van toepassingsgegevens, het statuspad en andere instellingen.
  • 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 volgende twee voorbeelden ziet u hoe u het profileSettings-object maakt met behulp van lokale opslag voor alleen statusopslag of 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>(appInfo,
				                                                                                  "mip_data",
                                                                                        		  mip::LogLevel::Trace,
                                                                                                  false, mip::CacheStorageType::OnDisk);

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>(appInfo,
    		                                                                                       "mip_data",
                                                                                       			   mip::LogLevel::Trace,
                                                                                                   false, mip::CacheStorageType::OnDisk);

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 het profiel succesvol wordt geladen, roept de SDK ProtectionProfileObserverImpl::OnLoadSuccess aan, de implementatie van mip::ProtectionProfile::Observer::OnLoadSuccess. De SDK geeft het resulterende object of de uitzonderingspointer en de context als parameters door aan de functie. De context is een verwijzing naar de std::promise die is gemaakt om de asynchrone bewerking af te handelen. De functie stelt de waarde van de promise in op het ProtectionProfile-object (context). Wanneer de hoofdfunctie gebruikmaakt Future.get(), kunt u het resultaat opslaan in een nieuw object.

//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>(appInfo,
				                                                                                       "mip_data",
                                                                                        			   mip::LogLevel::Trace,
                                                                                                       false, mip::CacheStorageType::OnDisk);

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

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

Volgende stappen 

Nu u het profiel hebt geladen, is de volgende stap om een engine aan het profiel toe te voegen.

Concepten van beveiligingsengines