Microsoft Information Protection SDK – Konzepte der File-SDK-Engine

Das Profil ist die Stammklasse für alle Vorgänge im MIP SDK. Bevor Sie Funktionen des Datei-SDKs verwenden, erstellen Sie FileProfile. Das Profil oder andere dem Profil hinzugefügte Objekte führen alle künftigen Vorgänge aus.

Erfüllen Sie die folgenden Codevoraussetzungen, bevor Sie ein Profil instanziieren:

  • MipContext: Erstellen und speichern Sie MipContext es in einem Objekt, auf das für das mip::FileProfile Objekt zugegriffen werden kann.
  • Zustimmungsdelegat: mip::ConsentDelegate implementiert ConsentDelegateImpl.
  • Anwendungsregistrierung: Registrieren Sie die Anwendung in Microsoft Entra ID und codieren Sie die Client-ID in den Anwendungs- oder Konfigurationsdateien.
  • Dateiprofilbeobachter: Implementieren Sie eine Klasse, die erbt mip::FileProfile::Observer.

Laden eines Profils

Nachdem Sie definiert ProfileObserver und ConsentDelegateImpl, können Sie instanziieren mip::FileProfile. Das Erstellen des mip::FileProfile-Objekts erfordert mip::MipContext und mip::FileProfile::Settings, das alle Einstellungsinformationen zum FileProfile speichert.

FileProfile::Settings-Parameter

Der FileProfile::Settings Konstruktor akzeptiert die folgenden fünf 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::FileProfile::Observer> observer: Ein gemeinsam genutzter Zeiger auf die Profilimplementierung Observer (in PolicyProfile, ProtectionProfile und FileProfile).

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

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

FileProfile::Settings profileSettings(
    mMipContext,                                  // mipContext object
    mip::CacheStorageType::InMemory,              // use in memory storage
    std::make_shared<ConsentDelegateImpl>(),      // new consent delegate
    std::make_shared<FileProfileObserverImpl>()); // new protection profile observer

Profileinstellungen mit Lese-/Schreibzugriff vom Speicherpfad auf der Disk

Der folgende Codeausschnitt weist das FileProfile an, alle App-Zustandsdaten in ./mip_app_data zu 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);

FileProfile::Settings profileSettings(
    mMipContext,                                   // mipContext object
    mip::CacheStorageType::OnDisk,                 // use on disk storage    
    std::make_shared<ConsentDelegateImpl>(),       // new consent delegate
    std::make_shared<FileProfileObserverImpl>());  // new protection profile observer

Laden des Profils

Nachdem Sie einen der beiden vorherigen Ansätze verwendet haben, verwenden Sie das Promise-/Future-Muster, um FileProfile zu laden.

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

Wenn die Anwendung erfolgreich ein Profil lädt, wird ProfileObserver::OnLoadSuccess, die Implementierung von mip::FileProfile::Observer::OnLoadSuccess, aufgerufen. 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 FileProfile-Objekt fest, das für den ersten Parameter übergeben wird. Wenn die Hauptfunktion Future.get() verwendet, kann 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>(mAppInfo,
				                                                                                      "mip_data",
                                                                                        			  mip::LogLevel::Trace,
                                                                                                      false);

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

    FileProfile::Settings profileSettings(
        mMipContext,                                   // MipContext object
        mip::CacheStorageType::OnDisk,                 // use on disk storage        
        std::make_shared<ConsentDelegateImpl>(),       // new consent delegate
        std::make_shared<FileProfileObserverImpl>());  // new file profile observer

        auto profilePromise = std::make_shared<promise<shared_ptr<FileProfile>>>();
        auto profileFuture = profilePromise->get_future();
        FileProfile::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.