Aracılığıyla paylaş


Microsoft Information Protection SDK - Koruma SDK'sı profil kavramları

Aşağıdaki iki örnek, hem durum depolaması hem de yalnızca bellek içi depolama için yerel depolama kullanarak profil Ayarlar nesnesinin nasıl oluşturulacağını göstermektedir.

Profil Yükleme

artık tanımlandığına ProtectionProfileObserverImpl göre örneği için mip::ProtectionProfilekullanacağız. nesnesini oluşturmak mip::ProtectionProfile için mip::ProtectionProfile::Settingsgerekir.

ProtectionProfile::Ayarlar Parametreleri

  • std::shared_ptr<MipContext>mip::MipContext: Uygulama bilgilerini, durum yolunu vb. depolamak için başlatılan nesne.
  • mip::CacheStorageType: Durumu depolamayı tanımlar: Bellekte, diskte veya diskte ve şifrelenmiş.
  • std::shared_ptr<mip::ConsentDelegate>: sınıfının mip::ConsentDelegatepaylaşılan işaretçisi.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: Profil Observer uygulamasının paylaşılan işaretçisi (, ProtectionProfileve FileProfileiçindePolicyProfile).

Aşağıdaki iki örnek, hem durum depolaması hem de yalnızca bellek içi depolama için yerel depolama kullanarak profil Ayarlar nesnesinin nasıl oluşturulacağını göstermektedir.

Durumu yalnızca bellekte depolama

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

Disk üzerindeki depolama yolundan profil ayarlarını okuma/yazma

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

Ardından, promise/future desenini kullanarak dosyasını ProtectionProfileyükleyin.

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

Bir profil yüklediysek ve bu işlem başarılı olursa, ProtectionProfileObserverImpl::OnLoadSuccessuygulamamız mip::ProtectionProfile::Observer::OnLoadSuccess olarak adlandırılır. Sonuçta elde edilen nesne veya özel durum işaretçisi ve bağlam işlevine parametre olarak geçirilir. Bağlam, zaman uyumsuz işlemi işlemek için oluşturduğumuz işaretçidir std::promise . işlevi yalnızca ProtectionProfile nesnesine (bağlam) promise değerini ayarlar. Ana işlev kullandığında Future.get(), sonuç yeni bir nesnede depolanabilir.

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

Bir Araya Getirmek

Gözlemcileri ve kimlik doğrulama temsilcisini tam olarak uyguladıktan sonra artık bir profili tam olarak yüklemek mümkündür. Aşağıdaki kod alıntısı, tüm gerekli üst bilgilerin zaten dahil olduğunu varsayar.

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

Sonuç olarak, profili başarıyla yükledik ve adlı profilenesnede depoladık.

Sonraki Adımlar

Profil eklendiğine göre, bir sonraki adım profile bir altyapı eklemektir.

Koruma altyapısı kavramları