Microsoft Information Protection SDK - Konsep profil File SDK

Profil adalah kelas root untuk semua operasi di MIP SDK. Sebelum menggunakan fungsionalitas File SDK apa pun, buat FileProfile. Profil atau objek lain yang ditambahkan ke profil melakukan semua operasi di masa mendatang.

Penuhi prasyarat kode berikut sebelum Anda membuat instans profil:

  • MipContext: Buat MipContext dan simpan di objek yang dapat diakses oleh mip::FileProfile objek.
  • Delegasi persetujuan: ConsentDelegateImpl mengimplementasikan mip::ConsentDelegate.
  • Pendaftaran aplikasi: Daftarkan aplikasi di Microsoft Entra ID dan kode keras ID klien ke dalam file aplikasi atau konfigurasi.
  • Pemantau profil berkas: Implementasikan kelas yang mewarisi dari mip::FileProfile::Observer.

Memuat profil

Setelah Anda menentukan ProfileObserver dan ConsentDelegateImpl, Anda dapat membuat instans mip::FileProfile. Membuat objek mip::FileProfile memerlukan mip::MipContext dan mip::FileProfile::Settings, yang menyimpan semua informasi setelan mengenai FileProfile.

Parameter FileProfile::Pengaturan

FileProfile::Settings Konstruktor menerima lima parameter berikut:

  • 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>: Penunjuk bersama kelas mip::ConsentDelegate.
  • std::shared_ptr<mip::FileProfile::Observer> observer: Penunjuk bersama ke implementasi profil Observer (dalam PolicyProfile, ProtectionProfile, dan FileProfile).

Contoh berikut menunjukkan cara membuat profileSettings objek dengan menggunakan penyimpanan lokal untuk penyimpanan status atau 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);

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

Membaca/menulis pengaturan profil dari jalur penyimpanan pada disk

Cuplikan kode berikut menginstruksikan FileProfile untuk menyimpan semua data status aplikasi di ./mip_app_data.

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

Muat profil

Setelah Anda menggunakan salah satu dari kedua pendekatan sebelumnya, gunakan pola promise/future untuk memuat FileProfile.

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

Jika aplikasi berhasil memuat profil, ProfileObserver::OnLoadSuccess, implementasi dari mip::FileProfile::Observer::OnLoadSuccess, dipanggil. SDK meneruskan objek yang dihasilkan atau penunjuk pengecualian, dan konteksnya, sebagai parameter ke fungsi. Konteks adalah pointer ke std::promise yang dibuat untuk menangani operasi asinkron. Fungsi ini menetapkan nilai Promise ke objek FileProfile yang diteruskan sebagai parameter pertama. Ketika fungsi utama menggunakan Future.get(), fungsi tersebut dapat menyimpan hasilnya dalam objek baru.

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

Menyusunnya menjadi satu

Setelah Anda menerapkan observer dan delegat autentikasi, Anda dapat memuat profil secara penuh. Cuplikan kode berikut 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);

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

Kode memuat profil dan menyimpannya di objek yang disebut profile.

Langkah berikutnya

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