Microsoft Information Protection SDK - Konsep profil File SDK
Profil adalah kelas root untuk semua operasi di MIP SDK. Sebelum menggunakan salah satu fungsi file SDK, FileProfile
harus dibuat dan semua operasi di masa mendatang akan dilakukan oleh profil atau oleh objek lain yang ditambahkan ke profil.
Ada beberapa prasyarat kode yang harus dipenuhi sebelum mencoba membuat instans profil:
MipContext
telah dibuat dan disimpan dalam objek yang dapat diakses olehmip::FileProfile
objek.ConsentDelegateImpl
penerapanmip::ConsentDelegate
.- Aplikasi telah terdaftar di ID Microsoft Entra dan ID klien dikodekan secara permanen ke file aplikasi atau konfigurasi.
- Pewarisan
mip::FileProfile::Observer
kelas telah diimplementasikan dengan tepat.
Memuat Profil
ProfileObserver
Dengan , dan ConsentDelegateImpl
, didefinisikan, mip::FileProfile
sekarang dapat diinisiasi. Membuat objek mengharuskan mip::FileProfile
[mip::MipContext
] memiliki dan mip::FileProfile::Settings
menyimpan semua informasi pengaturan tentang FileProfile
.
Parameter FileProfile::Pengaturan
FileProfile::Settings
Konstruktor menerima lima parameter, yang tercantum di bawah ini:
std::shared_ptr<MipContext>
: Objekmip::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 kelasmip::ConsentDelegate
.std::shared_ptr<mip::FileProfile::Observer> observer
: Pointer bersama ke implementasi profilObserver
(dalamPolicyProfile
,ProtectionProfile
, danFileProfile
).
Contoh berikut menunjukkan cara membuat profileSettings
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);
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 akan 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
Dengan menggunakan salah satu detail pendekatan di atas, sekarang gunakan pola janji/masa depan untuk memuat FileProfile
.
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<FileProfile>>>();
auto profileFuture = profilePromise->get_future();
FileProfile::LoadAsync(profileSettings, profilePromise);
Jika kita telah memuat profil, dan operasi itu berhasil, ProfileObserver::OnLoadSuccess
, implementasi mip::FileProfile::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 mengatur nilai janji ke objek FileProfile yang diteruskan untuk parameter pertama. 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);
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();
}
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.
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk