Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
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:
-
MipContexttelah dibuat dan disimpan dalam objek yang dapat diakses olehmip::FileProfileobjek. -
ConsentDelegateImplmengimplementasikanmip::ConsentDelegate. - Aplikasi telah terdaftar di ID Microsoft Entra dan ID klien dikodekan secara permanen ke file aplikasi atau konfigurasi.
- Kelas yang mewarisi
mip::FileProfile::Observertelah diimplementasikan dengan tepat.
Memuat Sebuah Profil
Dengan ProfileObserver, dan ConsentDelegateImpl didefinisikan, mip::FileProfile sekarang dapat diinstansiasi. Membuat objek mip::FileProfile mengharuskan [mip::MipContext] untuk memiliki dan mip::FileProfile::Settings untuk 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::MipContextyang 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 kelasmip::ConsentDelegate. -
std::shared_ptr<mip::FileProfile::Observer> observer: Penunjuk 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 operasinya 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 std::promise yang kami buat guna menangani operasi asinkron. Fungsi ini hanya mengatur nilai promise pada objek FileProfile yang diteruskan sebagai 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();
Menyatukannya
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.