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.
Os dois exemplos a seguir mostram como criar o objeto profileSettings usando o armazenamento local somente para armazenamento de estado ou memória.
Carregar um perfil
Agora que ProtectionProfileObserverImpl está definido, use-o para instanciar mip::ProtectionProfile. A criação do objeto mip::ProtectionProfile exige mip::ProtectionProfile::Settings.
Parâmetros de ProtectionProfile::Settings
-
std::shared_ptr<MipContext>: omip::MipContextobjeto inicializado para armazenar informações do aplicativo, caminho de estado e outras configurações. -
mip::CacheStorageType: define como armazenar o estado: na memória, no disco ou no disco e criptografado. -
std::shared_ptr<mip::ConsentDelegate>: um ponteiro compartilhado da classemip::ConsentDelegate. -
std::shared_ptr<mip::ProtectionProfile::Observer> observer: um ponteiro compartilhado para a implementação do perfilObserver(emPolicyProfile,ProtectionProfileeFileProfile).
Os dois exemplos a seguir mostram como criar o objeto profileSettings usando o armazenamento local somente para armazenamento de estado ou memória.
Armazenar estado somente na memória
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(appInfo,
"mip_data",
mip::LogLevel::Trace,
false, mip::CacheStorageType::OnDisk);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::InMemory, // use in memory storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile observer
Ler/gravar configurações de perfil no caminho de armazenamento no disco
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(appInfo,
"mip_data",
mip::LogLevel::Trace,
false, mip::CacheStorageType::OnDisk);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile
Em seguida, use o padrão promise/future para carregar o ProtectionProfile.
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
Se o perfil for carregado com sucesso, o SDK chamará ProtectionProfileObserverImpl::OnLoadSuccess, a implementação de mip::ProtectionProfile::Observer::OnLoadSuccess. O SDK passa o objeto resultante ou o ponteiro de exceção e o contexto como parâmetros para a função. O contexto é um ponteiro para o std::promise criado para lidar com a operação assíncrona. A função define o valor da promessa para o objeto ProtectionProfile (contexto). Quando a função principal usa Future.get(), você pode armazenar o resultado em um novo objeto.
//get the future value and store in profile.
auto profile = profileFuture.get();
Juntando tudo
Depois de implementar os observadores e o delegado de autenticação, você pode carregar totalmente um perfil. O snippet de código a seguir pressupõe que todos os cabeçalhos necessários já estão incluídos.
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>(appInfo,
"mip_data",
mip::LogLevel::Trace,
false, mip::CacheStorageType::OnDisk);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProfileObserver>()); // new protection profile observer
auto profilePromise = std::make_shared<promise<shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
auto profile = profileFuture.get();
}
O código carrega o perfil e o armazena no objeto chamado profile.
Próximas Etapas
Agora que o perfil foi carregado, a próxima etapa é adicionar um motor ao perfil.
Conceitos do mecanismo de proteção
- Confira o exemplo em C++ do SDK do MIP Protection no GitHub.