Microsoft Information Protection SDK — koncepcje aparatu SDK zasad
mip::PolicyEngine implementuje wszystkie operacje, które może wykonywać zestaw SDK zasad, z wyjątkiem ładowania profilu.
Implementacja: Dodawanie aparatu zasad
Implementacja: Tworzenie aparatu Ustawienia
Podobnie jak profil aparat wymaga również obiektu ustawień, mip::PolicyEngine::Settings . Ten obiekt przechowuje unikatowy identyfikator aparatu, obiekt implementacji, dostosowywalne dane klienta, które mogą być używane do debugowania lub telemetrii, oraz opcjonalnie informacje o mip::AuthDelegate ustawieniach regionalnych.
Poniżej tworzymy FileEngine::Settings obiekt o nazwie FileEngine::Settings przy użyciu tożsamości użytkownika aplikacji:
PolicyEngine::Settings engineSettings(
mip::Identity(mUsername), // mip::Identity.
authDelegateImpl, // Auth delegate object
"", // Client data. Customizable by developer, stored with engine.
"en-US", // Locale.
false); // Load sensitive information types for driving classification.
Podczas tworzenia ustawienia engineSettings w ten sposób należy jawnie ustawić również unikatowy identyfikator engineId za pośrednictwem:
engineSettings.SetEngineId(engineId);
Użycie nazwy użytkownika lub adresu e-mail pomaga zapewnić, że ten sam aparat jest ładowany za każdym razem, gdy użytkownik korzysta z usługi lub aplikacji.
Prawidłowy jest również identyfikator aparatu niestandardowego:
PolicyEngine::Settings engineSettings(
"myEngineId", // String
authDelegateImpl, // Auth delegate object
"", // Client data in string format. Customizable by developer, stored with engine.
"en-US", // Locale. Default is en-US
false); // Load sensitive information types for driving classification. Default is false.
Najlepszym rozwiązaniem jest, aby pierwszy parametr , identyfikator, był czymś, co umożliwia łatwe połączenie aparatu ze skojarzonym użytkownikiem, najlepiej nazwą główną użytkownika.
Implementacja: Dodawanie aparatu zasad
Aby dodać aparat, wrócimy do wzorca przyszłej/obietnicy użytego do ładowania profilu. Zamiast tworzyć obietnicę mip::Profile dla , użyjemy mip::PolicyEngine .
// Auto profile will be std::shared_ptr<mip::Profile>.
auto profile = profileFuture.get();
// Create the delegate
auto authDelegateImpl = std::make_shared<sample::auth::AuthDelegateImpl>(appInfo, userName, password);
// Create the PolicyEngine::Settings object.
PolicyEngine::Settings engineSettings("UniqueID", authDelegateImpl, "");
// Create a promise for std::shared_ptr<mip::PolicyEngine>.
auto enginePromise = std::make_shared<std::promise<std::shared_ptr<mip::PolicyEngine>>>();
// Instantiate the future from the promise.
auto engineFuture = enginePromise->get_future();
// Add the engine using AddEngineAsync, passing in the engine settings and the promise.
profile->AddEngineAsync(engineSettings, enginePromise);
// Get the future value and store in std::shared_ptr<mip::PolicyEngine>.
auto engine = engineFuture.get();
Wynikiem powyższego kodu jest pomyślne dodanie aparatu uwierzytelnionego użytkownika do profilu.
Implementacja: Lista etykiet wrażliwości
Za pomocą dodanego aparatu można teraz wyświetlić listę wszystkich etykiet wrażliwości dostępnych dla uwierzytelnionego użytkownika, dzwoniąc pod numer engine->ListSensitivityLabels() .
ListSensitivityLabels() pobiera listę etykiet i atrybutów tych etykiet dla określonego użytkownika z usługi. Wynik jest przechowywany w wektorze std::shared_ptr<mip::Label> .
Implementacja: ListSensitivityLabels()
std::vector<shared_ptr<mip::Label>> labels = engine->ListSensitivityLabels();
Implementacja: Drukowanie etykiet
//Iterate through all labels in the vector
for (const auto& label : labels) {
//print the label name
cout << label->GetName() << endl;
//Iterate through all child labels
for (const auto& child : label->GetChildren()) {
//Print the label with some formatting
cout << "-> " << child->GetName() << endl;
}
}
Drukowanie nazw to łatwy sposób na pokazanie, że pomyślnie pozysuliśmy zasady z usługi i że udało nam się pobrać etykiety. Aby zastosować etykietę, wymagany jest identyfikator etykiety. Zmodyfikowanie powyższej wycinka w celu zwrócenia identyfikatora etykiety powoduje:
for (const auto& label : labels) {
//Print label name and GUID
cout << label->GetName() << " : " << label->GetId() << endl;
//Print child label name and GUID
for (const auto& child : label->GetChildren()) {
cout << "-> " << child->GetName() << " : " << child->GetId() << endl;
}
}
Kolekcji zwróconych przez można użyć w celu wyświetlenia wszystkich etykiet dostępnych dla użytkownika, a następnie, jeśli ta opcja jest zaznaczona, użyć tego identyfikatora w celu zastosowania etykiet mip::LabelGetSensitivityLabels() do pliku.