프로필은 MIP SDK의 모든 작업에 대한 루트 클래스입니다. 파일 SDK 기능을 사용하기 전에 FileProfile을 생성해야 하며 이후의 모든 작업은 프로필 또는 프로필에 추가된 기타 개체에 의해 수행됩니다.
프로필을 인스턴스화하기 전에 충족해야 하는 몇 가지 코드 필수 구성 요소가 있습니다.
-
MipContext이 만들어지고mip::FileProfile개체에 액세스할 수 있는 개체에 저장되었습니다. -
ConsentDelegateImpl는mip::ConsentDelegate를 구현합니다. - 애플리케이션이 Microsoft Entra ID에 등록되었으며 클라이언트 ID가 애플리케이션 또는 구성 파일에 하드 코딩됩니다.
- 클래스 상속이
mip::FileProfile::Observer적절하게 구현되었습니다.
프로필 로드
ProfileObserver 및 ConsentDelegateImpl이 정의되면 이제 mip::FileProfile을 인스턴스화할 수 있습니다.
mip::FileProfile 객체를 만들려면 [mip::MipContext]에 mip::FileProfile::Settings에 대한 모든 설정 정보를 저장하려면 FileProfile가 있어야 합니다.
FileProfile::Settings 매개 변수
FileProfile::Settings 생성자는 아래에 나열된 5개의 매개 변수를 허용합니다.
-
std::shared_ptr<MipContext>: 애플리케이션 정보, 상태 경로 등을 저장하도록 초기화된mip::MipContext개체입니다. -
mip::CacheStorageType: 메모리 내, 디스크 내 또는 디스크 내 및 암호화된 상태를 저장하는 방법을 정의합니다. -
std::shared_ptr<mip::ConsentDelegate>: 클래스mip::ConsentDelegate의 공유 포인터입니다. -
std::shared_ptr<mip::FileProfile::Observer> observer: 프로필Observer구현(in ,PolicyProfile및ProtectionProfile)에FileProfile대한 공유 포인터입니다.
다음 예제에서는 메모리 내뿐 아니라 상태 스토리지에 대한 로컬 스토리지를 사용하여 개체를 만드는 profileSettings 방법을 보여 줍니다.
메모리에만 상태 저장
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
디스크의 스토리지 경로에서 프로필 설정 읽기/쓰기
다음 코드 조각은 모든 앱 상태 데이터를 FileProfile저장하도록 지시 ./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
프로필 로드
위의 방법 세부 정보 중 하나를 사용하여 이제 promise/future 패턴을 사용하여 .FileProfile
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<FileProfile>>>();
auto profileFuture = profilePromise->get_future();
FileProfile::LoadAsync(profileSettings, profilePromise);
프로필을 로드했고 해당 작업이 성공한 ProfileObserver::OnLoadSuccess경우 구현 mip::FileProfile::Observer::OnLoadSuccess 이 호출됩니다. 결과 개체 또는 예외 포인터와 컨텍스트는 함수에 매개 변수로 전달됩니다. 컨텍스트는 비동기 작업을 처리하기 위해 std::promise 만든 포인터입니다. 함수는 프라미스 값을 첫 번째 매개 변수에 대해 전달된 FileProfile 개체로 설정하기만 하면 됩니다. main 함수가 사용하는 Future.get()경우 결과를 새 개체에 저장할 수 있습니다.
//get the future value and store in profile.
auto profile = profileFuture.get();
함께 배치
관찰자 및 인증 대리자를 완전히 구현했으므로 이제 프로필을 완전히 로드할 수 있습니다. 아래 코드 조각에서는 필요한 모든 헤더가 이미 포함되어 있다고 가정합니다.
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();
}
최종 결과는 프로필을 성공적으로 로드하고 호출 profile된 개체에 저장한 것입니다.
다음 단계
이제 프로필이 추가되었으므로 다음 단계는 프로필에 엔진을 추가하는 것입니다.