Microsoft Information Protection-SDK – Konzepte des Policy-SDK-Profils

Laden Sie mip::Profile, bevor Sie Policy SDK-Vorgänge ausführen.

Die folgenden beiden Beispiele zeigen, wie Sie das profileSettings-Objekt mithilfe des lokalen Speichers für den Zustandsspeicher oder nur im Arbeitsspeicher erstellen.

Laden eines Profils

Nachdem Sie MipContext und ProfileObserver definiert haben, verwenden Sie sie, um mip::PolicyProfile zu instanziieren. Damit das mip::PolicyProfile-Objekt erstellt werden kann, werden mip::PolicyProfile::Settings und mip::MipContext benötigt.

Profile::Settings-Parameter

Der PolicyProfile::Settings Konstruktor akzeptiert die folgenden vier Parameter:

  • const 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. Weitere Details finden Sie in den Cachespeicherkonzepten.
  • std::shared_ptr<mip::PolicyProfile::Observer> observer: Ein gemeinsam genutzter Zeiger auf die Profilimplementierung Observer (in PolicyProfile, ProtectionProfile und FileProfile).

Die folgenden beiden Beispiele zeigen, wie Sie das profileSettings-Objekt mithilfe des lokalen Speichers für den Zustandsspeicher oder nur im Arbeitsspeicher erstellen.

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

PolicyProfile::Settings profileSettings(
    mMipContext,                                  // mipContext object
    mip::CacheStorageType::InMemory,              // use in memory storage
    std::make_shared<PolicyProfileObserverImpl>()); // new protection profile observer

Profileinstellungen mit Lese-/Schreibzugriff vom Speicherpfad auf der Disk

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

PolicyProfile::Settings profileSettings(
    mipContext,                                    // mipContext object
    mip::CacheStorageType::OnDisk,                 // use on disk storage
    std::make_shared<PolicyProfileObserverImpl>());  // new protection profile observer

Verwenden Sie als Nächstes das Zusage-/zukünftige Muster, um in Profile zu laden.

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

Wenn die Anwendung erfolgreich ein Profil (ProfileObserver::OnLoadSuccess) lädt, wird die Implementierung von mip::Profile::Observer::OnLoadSuccess benachrichtigt. Das SDK übergibt das resultierende Objekt in diesem Fall a mip::Profileund den Kontext als Parameter an die Beobachterfunktion.

Der Kontext ist ein Zeiger auf das std::promise, das zur Verarbeitung der asynchronen Operation erstellt wurde. Die Funktion legt den Wert der Zusage auf das Profil-Objekt fest, das für den ersten Parameter übergeben wird. Wenn die Hauptfunktion Future.get() verwendet, kann sie das Ergebnis in einem neuen Objekt im aufrufenden Thread 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>(mAppInfo,
				                                                                                       "mip_data",
                                                                                        			   mip::LogLevel::Trace,
                                                                                                       false);

    std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

    PolicyProfile::Settings profileSettings(
        mMipContext,                                    // mipContext object
        mip::CacheStorageType::OnDisk,                 // use on disk storage
        std::make_shared<PolicyProfileObserverImpl>());  // new protection profile observer

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

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

Nächste Schritte

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

Richtlinien-Enginekonzepte