Microsoft Information Protection SDK – SDK-profilbegrepp för skydd
De två exemplen nedan visar hur du skapar profileSettings-objektet med hjälp av lokal lagring för tillståndslagring och endast minnesinternt.
Läsa in en profil
Nu när ProtectionProfileObserverImpl
har definierats använder vi den för att instansiera mip::ProtectionProfile
. För att skapa mip::ProtectionProfile
objektet krävs mip::ProtectionProfile::Settings
.
ProtectionProfile::Inställningsparametrar
-
std::shared_ptr<MipContext>
: Objektetmip::MipContext
som initierades för att lagra programinformation, tillståndssökväg osv. -
mip::CacheStorageType
: Definierar hur du lagrar tillstånd: I minne, på disk eller på disk och krypterad. -
std::shared_ptr<mip::ConsentDelegate>
: En delad pekare för klassenmip::ConsentDelegate
. -
std::shared_ptr<mip::ProtectionProfile::Observer> observer
: En delad pekare till profilimplementeringenObserver
(iPolicyProfile
,ProtectionProfile
ochFileProfile
).
De två exemplen nedan visar hur du skapar profileSettings-objektet med hjälp av lokal lagring för tillståndslagring och endast minnesinternt.
Lagra endast tillstånd i minnet
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);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::InMemory, // use in memory storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile observer
Läs-/skrivprofilinställningar från lagringssökväg på disk
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);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile
Använd sedan mönstret promise/future för att läsa in ProtectionProfile
.
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
Om vi har läst in en profil och åtgärden lyckades ProtectionProfileObserverImpl::OnLoadSuccess
anropas vår implementering av mip::ProtectionProfile::Observer::OnLoadSuccess
. Det resulterande objektet eller undantagspekaren samt kontexten skickas som parametrar till funktionen. Kontexten är en pekare till den std::promise
vi skapade för att hantera asynkroniseringsåtgärden. Funktionen anger helt enkelt värdet för löftet till Objektet ProtectionProfile (kontext). När huvudfunktionen använder Future.get()
kan resultatet lagras i ett nytt objekt.
//get the future value and store in profile.
auto profile = profileFuture.get();
Sätta ihop den
Efter att ha implementerat observatörerna och autentiseringsdelegaten är det nu möjligt att läsa in en profil fullt ut. Kodfragmentet nedan förutsätter att alla nödvändiga rubriker redan ingår.
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);
ProtectionProfile::Settings profileSettings(
mMipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProfileObserver>()); // new protection profile observer
auto profilePromise = std::make_shared<promise<shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
auto profile = profileFuture.get();
}
Slutresultatet är att vi har läst in profilen och lagrat i objektet med namnet profile
.
Nästa steg
Nu när profilen har lagts till är nästa steg att lägga till en motor i profilen.