Notatka
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
mip::PolicyEngine implementuje wszystkie operacje, które może wykonać Policy SDK, z wyjątkiem ładowania profilu.
Implementacja: Dodaj mechanizm zasad
Implementacja: Tworzenie ustawień silnika zasad
Podobnie jak profil, silnik wymaga również obiektu ustawień. mip::PolicyEngine::Settings Ten obiekt przechowuje unikatowy identyfikator silnika, obiekt Twojej implementacji mip::AuthDelegate, konfigurowalne dane klienta do debugowania lub telemetrii oraz opcjonalnie ustawienia regionalne.
Poniższy przykład tworzy PolicyEngine::Settings obiekt o nazwie engineSettings 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 `engineSettings` w ten sposób należy również jawnie ustawić unikatowy `engineId`:
engineSettings.SetEngineId(engineId);
Użycie nazwy użytkownika lub adresu e-mail pomaga zagwarantować, że ten sam silnik będzie ładował się za każdym razem, gdy użytkownik korzysta z usługi lub aplikacji.
Ponadto dopuszczalne jest podanie niestandardowego identyfikatora silnika:
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.
Zgodnie z najlepszymi praktykami użyj pierwszego parametru id, który łączy silnik z powiązanym użytkownikiem, najlepiej nazwą główną użytkownika.
Implementacja: Dodawanie silnika zasad
Aby dodać silnik, wróć do wzorca future/promise używanego do ładowania profilu. Zamiast tworzyć obiekt Promise dla mip::Profile, użyj 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();
Kod dodaje silnik do profilu uwierzytelnionego użytkownika.
Implementacja: Wyświetlanie etykiet poufności
Za pomocą dodanego silnika można wyświetlić listę wszystkich etykiet poufności dostępnych dla uwierzytelnionego użytkownika, wywołując 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 pokazuje, że aplikacja pomyślnie ściągnęła zasady z usługi i uzyskała etykiety. Aby zastosować etykietę, potrzebny jest identyfikator etykiety. Zmodyfikuj poprzedni fragment kodu, aby zwrócić identyfikator etykiety:
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;
}
}
Możesz użyć kolekcji mip::Label zwróconej przez ListSensitivityLabels(), aby wyświetlić wszystkie etykiety dostępne dla użytkownika, a następnie po wybraniu etykiety użyć identyfikatora do zastosowania etykiety do pliku.