Freigeben über


Microsoft Information Protection SDK - Protection SDK-Profilkonzepte

In den beiden folgenden Beispielen wird gezeigt, wie Sie das Profil-Einstellungsobjekt erstellen, indem Sie den lokalen Speicher für die Zustandspeicherung und den Arbeitsspeicher für die alleinige Nutzung verwenden.

Ein Profil laden

Da ProtectionProfileObserverImpl jetzt definiert ist, werden wir es verwenden, um mip::ProtectionProfile zu instanziieren. Damit das mip::ProtectionProfile-Objekt erstellt werden kann, wird mip::ProtectionProfile::Settings benötigt.

Schutzprofil::Einstellungen Parameter

  • std::shared_ptr<MipContext>: Das mip::MipContext Objekt, das initialisiert wurde, um Anwendungsinformationen, Statuspfad usw. zu speichern.
  • mip::CacheStorageType: Legt fest, wie der Status zu speichern ist: Im Speicher, auf der Festplatte, oder auf der Festplatte 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 beiden folgenden Beispiele zeigen, wie Sie das ProfilEinstellungs-Objekt erstellen, das sowohl den lokalen Speicher zur Zustandsablage als auch ausschließlich den Arbeitsspeicher verwendet.

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

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

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 wir ein Profil geladen haben und dieser Vorgang erfolgreich war, ProtectionProfileObserverImpl::OnLoadSuccess, wird unsere Implementierung mip::ProtectionProfile::Observer::OnLoadSuccess aufgerufen. Der resultierende Objekt- oder Ausnahmezeiger sowie der Kontext werden als Parameter an die Funktion übergeben. Der Kontext ist ein Zeiger auf den std::promise, den wir erstellt haben, um die asynchrone Operation zu behandeln. Die Funktion legt einfach den Wert der Zusage auf das ProtectionProfile-Objekt (Kontext) fest. Wenn die Standard-Funktion Future.get() verwendet, kann das Ergebnis in einem neuen Objekt gespeichert werden.

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

Zusammenfügen

Nachdem die Beobachter und der Authentifizierungsdelegat vollständig implementiert wurden, ist es jetzt möglich, ein Profil vollständig zu laden. Im folgenden Code-Snip 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>(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();
}

Als Endergebnis haben wir das Profil erfolgreich geladen und im profilegenannten Objekt gespeichert haben.

Nächste Schritte

Nachdem das Profil hinzugefügt wurde, besteht der nächste Schritt darin, dem Profil eine Engine hinzuzufügen.

Schutzmaschinenkonzepte