Microsoft Information Protection SDK - Protection SDK profile concepts

The following two examples show how to create the profileSettings object by using local storage for state storage or memory only.

Load a profile

Now that ProtectionProfileObserverImpl is defined, use it to instantiate mip::ProtectionProfile. Creating the mip::ProtectionProfile object requires mip::ProtectionProfile::Settings.

ProtectionProfile::Settings parameters

  • std::shared_ptr<MipContext>: The mip::MipContext object initialized to store application info, state path, and other settings.
  • mip::CacheStorageType: Defines how to store state: in memory, on disk, or on disk and encrypted.
  • std::shared_ptr<mip::ConsentDelegate>: A shared pointer of class mip::ConsentDelegate.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: A shared pointer to the profile Observer implementation (in PolicyProfile, ProtectionProfile, and FileProfile).

The following two examples show how to create the profileSettings object by using local storage for state storage or memory only.

Store state in memory only

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

Read/write profile settings from storage path on disk

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

Next, use the promise/future pattern to load the ProtectionProfile.

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

If the profile loads successfully, the SDK calls ProtectionProfileObserverImpl::OnLoadSuccess, the implementation of mip::ProtectionProfile::Observer::OnLoadSuccess. The SDK passes the resulting object or exception pointer and the context as parameters to the function. The context is a pointer to the std::promise created to handle the async operation. The function sets the value of the promise to the ProtectionProfile object (context). When the main function uses Future.get(), you can store the result in a new object.

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

Putting it together

After you implement the observers and authentication delegate, you can fully load a profile. The following code snippet assumes that all necessary headers are already included.

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

The code loads the profile and stores it in the object called profile.

Next steps

Now that you loaded the profile, the next step is to add an engine to the profile.

Protection engine concepts