Microsoft Information Protection SDK - Policy SDK profile concepts

Load mip::Profile before you perform any Policy SDK operations.

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

Load a profile

After you define MipContext and ProfileObserver, use them to instantiate mip::PolicyProfile. Creating the mip::PolicyProfile object requires mip::PolicyProfile::Settings and mip::MipContext.

Profile::Settings parameters

The PolicyProfile::Settings constructor accepts the following four parameters:

  • const std::shared_ptr<MipContext>: The mip::MipContext object that was initialized to store application info, state path, etc.
  • mip::CacheStorageType: Defines how to store state: In memory, on disk, or on disk and encrypted. For more details, see the Cache storage concepts.
  • std::shared_ptr<mip::PolicyProfile::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 in-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>(mAppInfo,
				                                                                                  "mip_data",
                                                                                        		  mip::LogLevel::Trace,
                                                                                                  false);

std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

PolicyProfile::Settings profileSettings(
    mMipContext,                                  // mipContext object
    mip::CacheStorageType::InMemory,              // use in memory storage
    std::make_shared<PolicyProfileObserverImpl>()); // 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>(mAppInfo,
			                                                                                      "mip_data",
                                                                                       			  mip::LogLevel::Trace,
                                                                                                  false);

std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

PolicyProfile::Settings profileSettings(
    mipContext,                                    // mipContext object
    mip::CacheStorageType::OnDisk,                 // use on disk storage
    std::make_shared<PolicyProfileObserverImpl>());  // new protection profile observer

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

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

If the application successfully loads a profile, ProfileObserver::OnLoadSuccess, the implementation of mip::Profile::Observer::OnLoadSuccess, is notified. The SDK passes the resulting object, in this case a mip::Profile, and the context as parameters to the observer 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 Profile object passed in for the first parameter. When the main function uses Future.get(), it can store the result in a new object in the calling thread.

//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 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>(mAppInfo,
				                                                                                       "mip_data",
                                                                                        			   mip::LogLevel::Trace,
                                                                                                       false);

    std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);

    PolicyProfile::Settings profileSettings(
        mMipContext,                                    // mipContext object
        mip::CacheStorageType::OnDisk,                 // use on disk storage
        std::make_shared<PolicyProfileObserverImpl>());  // new protection profile observer

    auto profilePromise = std::make_shared<promise<shared_ptr<PolicyProfile>>>();
    auto profileFuture = profilePromise->get_future();
    Profile::LoadAsync(profileSettings, profilePromise);
    auto profile = profileFuture.get();
}

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

Next steps

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

Policy engine concepts