Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Este guia de início rápido mostra como implementar o padrão de inicialização do cliente usado pelo SDK de Políticas do MIP C++ em tempo de execução.
Observação
Qualquer aplicativo cliente que usa o SDK de Política de MIP precisa das etapas neste início rápido. Conclua a configuração e configure o SDK do MIP antes de começar.
Pré-requisitos
Caso ainda não tenha feito isso, certifique-se de:
- Instalação e configuração do SDK do Microsoft Proteção de Informações (MIP). Conclua estas etapas antes deste início rápido.
- Opcionalmente:
- Examine o perfil e os objetos do mecanismo.
- Examine os conceitos de Autenticação.
- Examine os conceitos do Observer.
Criar uma solução e um projeto do Visual Studio
Abra o Visual Studio 2022 ou posterior, selecione o menu Arquivo , Novo, Projeto.
- Selecione Console App em Modelos C++.
- Forneça um nome e um local para o projeto.
Adicione o pacote NuGet para o SDK de Política de MIP ao seu projeto:
- Em Gerenciador de Soluções, clique com o botão direito do mouse no nó do projeto e selecione Gerenciar pacotes NuGet....
- Selecione Procurar e insira "Microsoft.InformationProtection" na caixa de pesquisa.
- Selecione o pacote Microsoft.InformationProtection.Policy e selecione Instalar.
Implementar uma classe de observador
Crie uma implementação básica para uma classe de observador de perfil de política estendendo a classe do mip::PolicyProfile::Observer SDK.
Adicione uma nova classe ao projeto chamado
profile_observer.Substitua o conteúdo de
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; };Substitua o conteúdo de
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); }
Implementar um delegado de autenticação e uma função principal
Adicione uma nova classe ao projeto chamado
auth_delegate. Consulte os conceitos de Autenticação para obter detalhes sobre como implementar amip::AuthDelegateinterface.Atualize
main()para criar oMipContext, carregue umPolicyProfilee adicione umPolicyEngine:#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 mip::ApplicationInfo appInfo{ "your_app_id", // Application ID from Microsoft Entra app registration "MIP SDK Policy Quickstart", // Friendly name "1.0" // Version }; auto mipConfiguration = make_shared<mip::MipConfiguration>( appInfo, // ApplicationInfo object "mip_data", // Path to store settings and logs mip::LogLevel::Trace, // Log level false, // isOfflineOnly mip::CacheStorageType::OnDiskEncrypted // Cache storage type ); 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, profileObserver ); // Load Policy Profile auto profilePromise = make_shared<std::promise<shared_ptr<mip::PolicyProfile>>>(); auto profileFuture = profilePromise->get_future(); mip::PolicyProfile::LoadAsync(profileSettings, 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, 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; }Compilar e testar. O aplicativo deve ser inicializado com êxito e conectar-se ao serviço de política.