Aracılığıyla paylaş


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

Profil, MIP SDK'sı içindeki tüm işlemlerin kök sınıfıdır. Dosya SDK'sı işlevselliğinden herhangi birini kullanmadan önce bir FileProfile oluşturulması gerekir ve gelecekteki tüm işlemler profil tarafından veya profile eklenen diğer nesneler tarafından gerçekleştirilir.

Bir profilin örneğini oluşturmadan önce karşılanması gereken birkaç kod önkoşulu vardır:

  • MipContext oluşturuldu ve nesne tarafından erişilebilen bir nesnede mip::FileProfile depolandı.
  • ConsentDelegateImpl uygular mip::ConsentDelegate.
  • Uygulama Microsoft Entra Kimliği'ne kaydedilmiştir ve istemci kimliği uygulama veya yapılandırma dosyalarına sabit kodlanmıştır.
  • Devralan mip::FileProfile::Observer bir sınıf uygun şekilde uygulandı.

Profil Yükleme

ProfileObserver, ve ConsentDelegateImpltanımlandığında artık mip::FileProfile örneği oluşturulabilir. nesnesinin mip::FileProfile oluşturulması için [mip::MipContext] öğesinin sahip olması ve mip::FileProfile::Settings ile ilgili FileProfiletüm ayar bilgilerinin depolanması gerekir.

FileProfile::Ayarlar Parametreleri

Oluşturucu FileProfile::Settings , aşağıda listelenen beş parametreyi kabul eder:

  • 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::FileProfile::Observer> observer: Profil Observer uygulamasının paylaşılan işaretçisi (, ProtectionProfileve FileProfileiçindePolicyProfile).

Aşağıdaki örneklerde, hem durum depolaması profileSettings hem de yalnızca bellek içi depolama için yerel depolama kullanarak nesnenin nasıl oluşturulacağı gösterilmektedir.

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

FileProfile::Settings profileSettings(
    mMipContext,                                  // mipContext object
    mip::CacheStorageType::InMemory,              // use in memory storage
    std::make_shared<ConsentDelegateImpl>(),      // new consent delegate
    std::make_shared<FileProfileObserverImpl>()); // new protection profile observer

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

Aşağıdaki kod alıntısı, içindeki tüm uygulama durumu verilerini ./mip_app_datadepolamasını FileProfile bildirir.

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

FileProfile::Settings profileSettings(
    mMipContext,                                   // mipContext object
    mip::CacheStorageType::OnDisk,                 // use on disk storage    
    std::make_shared<ConsentDelegateImpl>(),       // new consent delegate
    std::make_shared<FileProfileObserverImpl>());  // new protection profile observer

Profili Yükleme

Yukarıdaki yaklaşım ayrıntılarından birini kullanarak, şimdi promise/future desenini kullanarak dosyasını FileProfileyükleyin.

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

Bir profil yüklediysek ve bu işlem başarılı olursa, ProfileObserver::OnLoadSuccessuygulamamız mip::FileProfile::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 . İşlev, ilk parametre için geçirilen FileProfile nesnesine 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);

    FileProfile::Settings profileSettings(
        mMipContext,                                   // MipContext object
        mip::CacheStorageType::OnDisk,                 // use on disk storage        
        std::make_shared<ConsentDelegateImpl>(),       // new consent delegate
        std::make_shared<FileProfileObserverImpl>());  // new file profile observer

        auto profilePromise = std::make_shared<promise<shared_ptr<FileProfile>>>();
        auto profileFuture = profilePromise->get_future();
        FileProfile::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.