SDK de Microsoft Information Protection: Conceptos del perfil de SDK de protección

En los dos ejemplos siguientes se muestra cómo crear el objeto profileSettings mediante el almacenamiento local solo para el almacenamiento de estado o la memoria.

Cargar un perfil

Ahora que ProtectionProfileObserverImpl está definido, úsalo para crear una instancia de mip::ProtectionProfile. La creación del objeto mip::ProtectionProfile requiere mip::ProtectionProfile::Settings.

Parámetros de ProtectionProfile::Settings

  • std::shared_ptr<MipContext>: El objeto mip::MipContext, inicializado para almacenar la información de la aplicación, la ruta del estado y otras configuraciones.
  • mip::CacheStorageType: define cómo almacenar el estado: en memoria, en disco o en disco y cifrado.
  • std::shared_ptr<mip::ConsentDelegate>: puntero compartido de la clase mip::ConsentDelegate.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: Un puntero compartido a la implementación del perfil Observer (en PolicyProfile, ProtectionProfile y FileProfile).

En los dos ejemplos siguientes se muestra cómo crear el objeto profileSettings mediante el almacenamiento local solo para el almacenamiento de estado o la memoria.

Almacenamiento del estado solo en memoria

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

Leer/escribir configuraciones de perfil desde la ruta de almacenamiento en el 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

A continuación, use el patrón promesa/futuro para cargar ProtectionProfile.

auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);

Si el perfil se carga correctamente, el SDK llama a ProtectionProfileObserverImpl::OnLoadSuccess, la implementación de mip::ProtectionProfile::Observer::OnLoadSuccess. El SDK pasa el objeto resultante o el puntero de excepción y el contexto como parámetros a la función. El contexto es un puntero al std::promise creado para gestionar la operación asíncrona. La función establece el valor de la promesa en el objeto ProtectionProfile (contexto). Cuando la función principal usa Future.get(), puede almacenar el resultado en un nuevo objeto.

//get the future value and store in profile.
auto profile = profileFuture.get();

Ensamblándolo

Después de implementar los observadores y el delegado de autenticación, ya puede cargar un perfil por completo. En el fragmento de código siguiente se supone que ya se incluyen todos los encabezados necesarios.

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();
}

El código carga el perfil y lo almacena en el objeto denominado profile.

Pasos siguientes

Una vez cargado el perfil, el siguiente paso es añadir un motor al perfil.

Conceptos del motor de protección