Microsoft Information Protection SDK - 파일 SDK 프로파일 개념

프로필은 MIP SDK의 모든 작업에 대한 루트 클래스입니다. File SDK 기능을 사용하기 전에 FileProfile를 생성하세요. 프로필 또는 프로필에 추가된 다른 개체는 이후의 모든 작업을 수행합니다.

프로필을 인스턴스화하기 전에 다음 코드 필수 구성 요소를 충족합니다.

  • MipContext: mip::FileProfile를 만들고 MipContext 개체가 액세스할 수 있는 개체에 저장합니다.
  • 동의 대리자: ConsentDelegateImpl 구현합니다.mip::ConsentDelegate
  • 애플리케이션 등록: Microsoft Entra ID 애플리케이션을 등록하고 클라이언트 ID를 애플리케이션 또는 구성 파일에 하드 코딩합니다.
  • 파일 프로필 관찰자: 상속되는 클래스를 구현합니다 mip::FileProfile::Observer.

프로필 로드

ProfileObserver 및 ConsentDelegateImpl를 정의한 후 mip::FileProfile를 인스턴스화할 수 있습니다. mip::FileProfile 개체를 만들려면 FileProfile 및 mip::FileProfile::Settings에 대한 모든 설정 정보를 저장하는 mip::MipContext가 필요합니다.

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 구현(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

디스크의 스토리지 경로에서 프로필 설정 읽기/쓰기

다음 코드 스니펫은 ./mip_app_data에 모든 앱 상태 데이터를 FileProfile에 저장하도록 지시합니다.

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

애플리케이션이 프로필을 성공적으로 로드하는 데 성공하면 mip::FileProfile::Observer::OnLoadSuccess의 구현인 ProfileObserver::OnLoadSuccess이 호출됩니다. SDK는 결과 개체 또는 예외 포인터와 컨텍스트를 함수에 매개 변수로 전달합니다. 컨텍스트는 비동기 std::promise 작업을 처리하기 위해 만든 항목에 대한 포인터입니다. 이 함수는 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된 개체에 저장합니다.

다음 단계

이제 프로필이 추가되었으므로 다음 단계는 프로필에 엔진을 추가하는 것입니다.