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

Los dos ejemplos siguientes muestran cómo crear el objeto profileSettings mediante el almacenamiento local para el almacenamiento de estado, así como para el almacenamiento solo en memoria.

Carga de un perfil

Ahora que ya se ha definido ProtectionProfileObserverImpl, se usará para crear instancias de mip::ProtectionProfile. La creación del objeto mip::ProtectionProfile requiere mip::ProtectionProfile::Settings.

Parámetros de ProtectionProfile::Settings

  • std::shared_ptr<MipContext>: objeto mip::MipContext que se inicializó para almacenar la información de la aplicación, la ruta de acceso de estado, etc.
  • mip::CacheStorageType: define cómo almacenar el estado: en la memoria, en el disco o en el disco con cifrado.
  • std::shared_ptr<mip::ConsentDelegate>: puntero compartido de la clase mip::ConsentDelegate.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: puntero compartido en la implementación del perfil Observer (en PolicyProfile, ProtectionProfile y FileProfile).

Los dos ejemplos siguientes muestran cómo crear el objeto profileSettings mediante el almacenamiento local para el almacenamiento de estado, así como para el almacenamiento solo en 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>(mAppInfo,
				                                                                                  "mip_data",
                                                                                        		  mip::LogLevel::Trace,
                                                                                                  false);

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

Configuración del perfil de lectura y escritura desde la ruta de acceso 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>(mAppInfo,
    		                                                                                       "mip_data",
                                                                                       			   mip::LogLevel::Trace,
                                                                                                   false);

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 hemos cargado un perfil y esa operación se ha completado correctamente, ProtectionProfileObserverImpl::OnLoadSuccess, se llama a la implementación de mip::ProtectionProfile::Observer::OnLoadSuccess. El objeto o el puntero de excepción resultantes, así como el contexto, se pasan en forma de parámetros a la función. El contexto es un puntero dirigido al std::promise que creamos para controlar la operación asincrónica. La función simplemente establece el valor de la promesa en el objeto ProtectionProfile (contexto). Cuando la función principal usa Future.get(), el resultado se puede almacenar en un nuevo objeto.

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

Combinación de todo

Después de implementar los observadores y el delegado de autenticación, podrá cargar completamente un perfil. En el fragmento de código siguiente se presupone 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>(mAppInfo,
				                                                                                       "mip_data",
                                                                                        			   mip::LogLevel::Trace,
                                                                                                       false);

    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 resultado final es que hemos cargado correctamente el perfil y lo hemos almacenado en el objeto denominado profile.

Pasos siguientes

Ahora que se ha agregado el perfil, el siguiente paso es agregar un motor al perfil.

Conceptos del motor de protección