Microsoft Information Protection SDK — pojęcia dotyczące profilu zestawu SDK plików

Profil jest klasą główną dla wszystkich operacji w zestawie MIP SDK. Przed użyciem dowolnej funkcji zestawu SDK plików utwórz element FileProfile. Profil lub inne obiekty dodane do profilu wykonują wszystkie przyszłe operacje.

Przed utworzeniem profilu spełnij poniższe wymagania dotyczące kodu:

  • MipContext: utwórz MipContext i zapisz je w obiekcie dostępnym dla obiektu mip::FileProfile.
  • Delegat zgody: ConsentDelegateImpl implementuje mip::ConsentDelegate.
  • Rejestracja aplikacji: zarejestruj aplikację w Microsoft Entra ID i zakoduj identyfikator klienta w plikach aplikacji lub konfiguracji.
  • Obserwator profilu pliku: Zaimplementuj klasę, która dziedziczy po mip::FileProfile::Observer.

Ładowanie profilu

Po zdefiniowaniu ProfileObserver i ConsentDelegateImpl można utworzyć wystąpienie mip::FileProfile. Tworzenie obiektu mip::FileProfile wymaga mip::MipContext i mip::FileProfile::Settings, który przechowuje wszystkie informacje o ustawieniach dotyczących FileProfile.

FileProfile::Settings parameters

Konstruktor FileProfile::Settings akceptuje następujące pięć parametrów:

  • std::shared_ptr<MipContext> mip::MipContext: obiekt, który został zainicjowany do przechowywania informacji o aplikacji, ścieżki stanu itp.
  • mip::CacheStorageType: definiuje sposób przechowywania stanu: w pamięci, na dysku lub na dysku z szyfrowaniem.
  • std::shared_ptr<mip::ConsentDelegate>: współużytkowany wskaźnik klasy mip::ConsentDelegate.
  • std::shared_ptr<mip::FileProfile::Observer> observer: współdzielony wskaźnik do implementacji profilu Observer (w PolicyProfile, ProtectionProfile i FileProfile).

W poniższych przykładach przedstawiono, jak utworzyć obiekt profileSettings przy użyciu magazynu lokalnego do przechowywania stanu lub wyłącznie w pamięci.

Przechowywanie stanu tylko w pamięci

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

Odczytywanie i zapisywanie ustawień profilu z i do ścieżki magazynowej na dysku

Poniższy fragment kodu instruuje element , FileProfile aby przechowywał wszystkie dane stanu aplikacji w programie ./mip_app_data.

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

Ładowanie profilu

Po zastosowaniu jednego z powyższych podejść użyj wzorca promise/future, aby wczytać FileProfile.

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

Jeśli aplikacja pomyślnie ładuje profil, ProfileObserver::OnLoadSuccesswywoływana jest implementacja metody mip::FileProfile::Observer::OnLoadSuccess. Zestaw SDK przekazuje wynikowy obiekt lub wskaźnik wyjątku oraz kontekst jako parametry funkcji. Kontekst jest wskaźnikiem do elementu std::promise, utworzonego w celu obsługi operacji asynchronicznej. Funkcja ustawia wartość obietnicy dla obiektu FileProfile przekazanego dla pierwszego parametru. Gdy funkcja main używa Future.get(), może zapisać wynik w nowym obiekcie.

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

Składanie całości

Po zaimplementowaniu obserwatorów i delegata uwierzytelniania można w pełni załadować profil. Poniższy fragment kodu zakłada, że wszystkie niezbędne nagłówki są już uwzględnione.

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

Kod ładuje profil i przechowuje go w obiekcie o nazwie profile.

Następne kroki

Teraz, gdy profil został dodany, następnym krokiem jest dodanie silnika do profilu.