Microsoft Information Protection SDK - Protection SDK-Profilkonzepte

Die folgenden beiden Beispiele zeigen, wie Sie das Objekt profileSettings erstellen, indem Sie entweder den lokalen Speicher zur Speicherung des Zustands oder ausschließlich den Arbeitsspeicher verwenden.

Laden eines Profils

Nachdem ProtectionProfileObserverImpl definiert wurde, verwenden Sie es, um mip::ProtectionProfile zu instanziieren. Damit das mip::ProtectionProfile-Objekt erstellt werden kann, wird mip::ProtectionProfile::Settings benötigt.

Parameter von ProtectionProfile::Settings

  • std::shared_ptr<MipContext>: Das mip::MipContext Objekt, das zum Speichern von Anwendungsinformationen, Statuspfad und anderen Einstellungen initialisiert wurde.
  • mip::CacheStorageType: Definiert, wie der Zustand gespeichert wird: im Arbeitsspeicher, auf dem Datenträger oder auf dem Datenträger und verschlüsselt.
  • std::shared_ptr<mip::ConsentDelegate>: Ein gemeinsam genutzter Zeiger der Klasse mip::ConsentDelegate.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: Ein gemeinsam genutzter Zeiger auf die Profilimplementierung Observer (in PolicyProfile, ProtectionProfile und FileProfile).

Die folgenden beiden Beispiele zeigen, wie Sie das Objekt profileSettings erstellen, indem Sie den lokalen Speicher zur Zustandsspeicherung oder ausschließlich den Arbeitsspeicher verwenden.

Zustand nur im Arbeitsspeicher speichern

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

Profileinstellungen vom Speicherpfad auf der Festplatte lesen/schreiben

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

Verwenden Sie als Nächstes das Promise-/Future-Muster, um ProtectionProfile zu laden.

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

Wenn das Profil erfolgreich geladen wird, ruft das SDK ProtectionProfileObserverImpl::OnLoadSuccess auf, die Implementierung von mip::ProtectionProfile::Observer::OnLoadSuccess. Das SDK übergibt den resultierenden Objekt- oder Ausnahmezeiger und den Kontext als Parameter an die Funktion. Der Kontext ist ein Zeiger auf das zur Verarbeitung der asynchronen Operation erstellte std::promise. Die Funktion legt den Wert der Zusage auf das ProtectionProfile-Objekt (Kontext) fest. Wenn die Hauptfunktion Future.get() verwendet, können Sie das Ergebnis in einem neuen Objekt speichern.

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

Gesamtbild

Nachdem Sie den Beobachter- und Authentifizierungsdelegat implementiert haben, können Sie ein Profil vollständig laden. Im folgenden Codeausschnitt wird davon ausgegangen, dass alle erforderlichen Header bereits enthalten sind.

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

Der Code lädt das Profil und speichert es im aufgerufenen profileObjekt.

Nächste Schritte

Nachdem Sie das Profil geladen haben, besteht der nächste Schritt darin, dem Profil eine Engine hinzuzufügen.

Schutzmaschinenkonzepte