Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Bu hızlı başlangıçta, çalışma zamanında MIP C++ Policy SDK tarafından kullanılan istemci başlatma örüntüsünün nasıl uygulandığı gösterilmektedir.
Uyarı
Bu hızlı başlangıçta özetlenen adımlar, MIP İlkesi SDK'sını kullanan tüm istemci uygulamaları için gereklidir. Bu hızlı başlangıç , MIP SDK'sı ayarlandıktan ve yapılandırıldıktan sonra tamamlanmalıdır.
Önkoşullar
Henüz yapmadıysanız şunları yaptığınızdan emin olun:
- Microsoft Information Protection (MIP) SDK kurulumu ve yapılandırmasındaki adımları tamamlayın.
- Isteğe bağlı olarak:
- Profil ve altyapı nesnelerini gözden geçirin.
- Kimlik doğrulama kavramlarını gözden geçirin.
- Gözlemci kavramlarını gözden geçirin.
Visual Studio çözümü ve projesi oluşturma
Visual Studio 2022 veya sonraki bir sürümünü açın, Dosya menüsünü ( Yeni, Proje) seçin.
- C++ şablonları altında Konsol Uygulaması'nı seçin.
- Proje için bir Ad ve Konum belirtin.
MIP İlkesi SDK'sı için NuGet paketini projenize ekleyin:
- Çözüm Gezgini'nde proje düğümüne sağ tıklayın ve NuGet paketlerini yönet...'i seçin.
- Gözat'ı seçin ve arama kutusuna "Microsoft.InformationProtection" yazın.
- Microsoft.InformationProtection.Policy paketini seçin ve Yükle'ye tıklayın.
Gözlemci sınıfı uygulama
SDK'nın mip::PolicyProfile::Observer sınıfını genişleterek İlke profili gözlemci sınıfı için temel bir uygulama oluşturun.
Projenize adlı
profile_observeryeni bir sınıf ekleyin.öğesinin içeriğini değiştirin:
profile_observer.h#include <memory> #include "mip/upe/policy_profile.h" class PolicyProfileObserver final : public mip::PolicyProfile::Observer { public: PolicyProfileObserver() { } void OnLoadSuccess(const std::shared_ptr<mip::PolicyProfile>& profile, const std::shared_ptr<void>& context) override; void OnLoadFailure(const std::exception_ptr& error, const std::shared_ptr<void>& context) override; void OnAddEngineSuccess(const std::shared_ptr<mip::PolicyEngine>& engine, const std::shared_ptr<void>& context) override; void OnAddEngineFailure(const std::exception_ptr& error, const std::shared_ptr<void>& context) override; };öğesinin içeriğini değiştirin:
profile_observer.cpp#include "profile_observer.h" #include <future> using std::promise; using std::shared_ptr; using std::exception_ptr; void PolicyProfileObserver::OnLoadSuccess(const shared_ptr<mip::PolicyProfile>& profile, const shared_ptr<void>& context) { auto loadPromise = static_cast<promise<shared_ptr<mip::PolicyProfile>>*>(context.get()); loadPromise->set_value(profile); } void PolicyProfileObserver::OnLoadFailure(const exception_ptr& error, const shared_ptr<void>& context) { auto loadPromise = static_cast<promise<shared_ptr<mip::PolicyProfile>>*>(context.get()); loadPromise->set_exception(error); } void PolicyProfileObserver::OnAddEngineSuccess(const shared_ptr<mip::PolicyEngine>& engine, const shared_ptr<void>& context) { auto addEnginePromise = static_cast<promise<shared_ptr<mip::PolicyEngine>>*>(context.get()); addEnginePromise->set_value(engine); } void PolicyProfileObserver::OnAddEngineFailure(const exception_ptr& error, const shared_ptr<void>& context) { auto addEnginePromise = static_cast<promise<shared_ptr<mip::PolicyEngine>>*>(context.get()); addEnginePromise->set_exception(error); }
Kimlik doğrulama temsilcisi ve ana işlevi uygulama
Projenize adlı
auth_delegateyeni bir sınıf ekleyin. Kimlik doğrulama kavramları hakkında ayrıntılı bilgi için Arabirimi uygulamasını inceleyin.main()güncelleştirin veMipContextöğesini oluşturun, birPolicyProfileyükleyin ve birPolicyEngineekleyin:#include "mip/mip_context.h" #include "mip/upe/policy_profile.h" #include "auth_delegate.h" #include "profile_observer.h" #include <iostream> #include <future> using std::cout; using std::endl; using std::make_shared; using std::shared_ptr; int main() { // Construct/initialize objects required by the application's profile object auto mipConfiguration = make_shared<mip::MipConfiguration>( "your_app_id", // Application ID from Microsoft Entra app registration "MIP SDK Policy Quickstart", // Friendly name "1.0", // Version true // GUID for each machine ); auto mipContext = mip::MipContext::Create(mipConfiguration); auto profileObserver = make_shared<PolicyProfileObserver>(); auto authDelegateImpl = make_shared<sample::auth::AuthDelegateImpl>("your_app_id"); mip::PolicyProfile::Settings profileSettings(mipContext, mip::CacheStorageType::OnDiskEncrypted, authDelegateImpl ); // Load Policy Profile auto profilePromise = make_shared<std::promise<shared_ptr<mip::PolicyProfile>>>(); auto profileFuture = profilePromise->get_future(); mip::PolicyProfile::LoadAsync(profileSettings, profileObserver, profilePromise); auto profile = profileFuture.get(); // Add a Policy Engine mip::PolicyEngine::Settings engineSettings( mip::Identity("user@contoso.com"), authDelegateImpl, "", "en-US", false ); auto enginePromise = make_shared<std::promise<shared_ptr<mip::PolicyEngine>>>(); auto engineFuture = enginePromise->get_future(); profile->AddEngineAsync(engineSettings, profileObserver, enginePromise); auto engine = engineFuture.get(); // Application using Policy engine is ready. // Engine can be used to list labels, compute actions, etc. cout << "Policy engine loaded successfully." << endl; return 0; }Oluştur ve test et. Uygulamanın başarıyla başlatılması ve İlke hizmetine bağlanması gerekir.