Microsoft Information Protection SDK – SDK-profilbegrepp för skydd

Följande två exempel visar hur du skapar profileSettings-objektet med hjälp av lokal lagring endast för tillståndslagring eller minne.

Ladda en profil

Nu när har ProtectionProfileObserverImpl definierats använder du den för att instansiera mip::ProtectionProfile. För att skapa mip::ProtectionProfile objektet krävs mip::ProtectionProfile::Settings.

ProtectionProfile::Inställningsparametrar

  • std::shared_ptr<MipContext>: Objektet mip::MipContext initierades för att lagra programinformation, tillståndssökväg och andra inställningar.
  • mip::CacheStorageType: Definierar hur du lagrar tillstånd: i minne, på disk eller på disk och krypterad.
  • std::shared_ptr<mip::ConsentDelegate>: En delad pekare för klassen mip::ConsentDelegate.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: En delad pekare till profilimplementeringen Observer (i PolicyProfile, ProtectionProfileoch FileProfile).

Följande två exempel visar hur du skapar profileSettings-objektet med hjälp av lokal lagring endast för tillståndslagring eller minne.

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>(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

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>(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

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

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

Om profilen läses in korrekt anropar SDK:t ProtectionProfileObserverImpl::OnLoadSuccess, som är implementeringen av mip::ProtectionProfile::Observer::OnLoadSuccess. SDK skickar det resulterande objektet eller undantagspekaren och kontexten som parametrar till funktionen. Kontexten är en pekare till std::promise, som skapades för att hantera den asynkrona åtgärden. Funktionen anger värdet för löftet till Objektet ProtectionProfile (kontext). När huvudfunktionen använder Future.get()kan du lagra resultatet i ett nytt objekt.

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

Sammanfoga

När du har implementerat observatörerna och autentiseringsdelegaten kan du läsa in en profil fullständigt. Följande kodfragment förutsätter att alla nödvändiga rubriker redan ingår.

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

Koden läser in profilen och lagrar den i objektet med namnet profile.

Nästa steg

Nu när du har laddat in profilen är nästa steg att lägga till en motor till profilen.

Begrepp för skyddsmotor