Bagikan melalui


Microsoft Information Protection SDK - Konsep profil SDK Perlindungan

Dua contoh di bawah ini menunjukkan cara membuat profil Pengaturan objek menggunakan penyimpanan lokal untuk penyimpanan status serta hanya dalam memori.

Memuat Profil

Sekarang setelah ProtectionProfileObserverImpl ditentukan, kita akan menggunakannya untuk membuat instans mip::ProtectionProfile. mip::ProtectionProfile Membuat objek memerlukan mip::ProtectionProfile::Settings.

Parameter ProtectionProfile::Pengaturan

  • std::shared_ptr<MipContext>: Objek mip::MipContext yang diinisialisasi untuk menyimpan info aplikasi, jalur status, dll.
  • mip::CacheStorageType: Menentukan cara menyimpan status: Dalam memori, pada disk, atau pada disk dan dienkripsi.
  • std::shared_ptr<mip::ConsentDelegate>: Pointer bersama kelas mip::ConsentDelegate.
  • std::shared_ptr<mip::ProtectionProfile::Observer> observer: Pointer bersama ke implementasi profil Observer (dalam PolicyProfile, ProtectionProfile, dan FileProfile).

Dua contoh di bawah ini menunjukkan cara membuat profil Pengaturan objek menggunakan penyimpanan lokal untuk penyimpanan status serta hanya dalam memori.

Simpan status dalam memori saja

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

Membaca/menulis pengaturan profil dari jalur penyimpanan pada 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);

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

Selanjutnya, gunakan pola janji/masa depan untuk memuat ProtectionProfile.

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

Jika kita telah memuat profil, dan operasi itu berhasil, ProtectionProfileObserverImpl::OnLoadSuccess, implementasi mip::ProtectionProfile::Observer::OnLoadSuccess kita dipanggil. Objek yang dihasilkan atau penunjuk pengecualian, serta konteks, diteruskan sebagai parameter ke fungsi. Konteksnya adalah penunjuk ke yang std::promise kami buat untuk menangani operasi asinkron. Fungsi ini hanya menetapkan nilai janji ke objek ProtectionProfile (konteks). Ketika fungsi utama menggunakan Future.get(), hasilnya dapat disimpan di objek baru.

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

Meletakkannya Bersama-sama

Setelah sepenuhnya menerapkan pengamat dan delegasi autentikasi, sekarang dimungkinkan untuk memuat profil sepenuhnya. Cuplikan kode di bawah ini mengasumsikan semua header yang diperlukan sudah disertakan.

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

Hasil akhirnya adalah bahwa kita telah berhasil memuat profil dan disimpan dalam objek yang disebut profile.

Langkah berikutnya

Sekarang setelah profil ditambahkan, langkah selanjutnya adalah menambahkan mesin ke profil.

Konsep mesin perlindungan