Microsoft 信息保护 SDK - 保护 SDK 引擎概念

实现:添加保护引擎

在文件 SDK 中,mip::ProtectionProfile 类是所有 SDK 操作的根类。 前面已经创建了配置文件,现在可以向配置文件添加引擎。

以下示例演示了如何为单个已通过身份验证的用户使用单个引擎。

实现:创建保护引擎设置

与配置文件类似,引擎也需要设置对象 mip::ProtectionEngine::Settings。 此对象存储唯一的引擎标识符、可用于调试或遥测的可自定义客户端数据,以及可选的区域设置。

我们将在此处创建一个名为 engineSettings ProtectionEngine::Settings 对象。

ProtectionEngine::Settings engineSettings("UniqueID", "");

注意

如果使用此方法创建保护设置对象,则还必须通过 setIdentity() 在 ProtectionEngineSettings 中手动设置身份或通过 setCloud() 在目标云环境下手动设置身份。

最佳做法是,第一个参数 id 应能让引擎轻松连接到关联的用户或者mip::Identity 对象。 使用 mip::Identity 初始化设置:

ProtectionEngine::Settings engineSettings(mip::Identity("Bob@Contoso.com", "");

以这种方式创建 engineSettings 时,通过以下方式显式设置唯一的 engineId 也很重要:

engineSettings.SetEngineId(engineId);

使用用户名或电子邮件有助于确保每次用户使用服务或应用程序时加载相同的引擎。

实现:添加保护引擎

为了添加引擎,我们将返回用于加载配置文件的未来/承诺模式。 我们将使用 mip::ProtectionEngine,而不是创建 mip::ProtectionProfile 的承诺。


  //auto profile will be std::shared_ptr<mip::ProtectionProfile>
  auto profile = profileFuture.get();

  //Create the ProtectionEngine::Settings object
  ProtectionEngine::Settings engineSettings("UniqueID", "");

  //Create a promise for std::shared_ptr<mip::ProtectionEngine>
  auto enginePromise = std::make_shared<std::promise<std::shared_ptr<mip::ProtectionEngine>>>();

  //Instantiate the future from the promise
  auto engineFuture = enginePromise->get_future();

  //Add the engine using AddEngineAsync, passing in the engine settings and the promise
  profile->AddEngineAsync(engineSettings, enginePromise);

  //get the future value and store in std::shared_ptr<mip::ProtectionEngine>
  auto engine = engineFuture.get();

上述代码的最终结果是,我们成功将已通过身份验证的用户的引擎添加到配置文件。

实现:列出模板

使用添加的引擎,现在可以通过调用 engine->GetTemplatesAsync() 来列出可供已通过身份验证的用户使用的所有敏感度模板。

GetTemplatesAsync() 将提取模板标识符的列表。 结果将存储在 std::shared_ptr<std::string> 的矢量中。

实现:ListSensitivityTemplates()

auto loadPromise = std::make_shared<std::promise<shared_ptr<vector<string>>>>();
std::future<std::shared_ptr<std::vector<std::string>>> loadFuture = loadPromise->get_future();
mEngine->GetTemplatesAsync(engineObserver, loadPromise);
auto templates = loadFuture.get();

实现:打印模板 ID

//Iterate through all template IDs in the vector
for (const auto& temp : *templates) {
  cout << "Template:" << "\n\tId: " << temp << endl;
}

打印名称是显示我们已成功从服务中拉取策略并且能够获取模板的简单方法。 要应用模板,则需要模板的标识符。

将模板映射到标签只能通过 Policy SDK 来完成,方法是检查 ComputeActions() 的结果。

后续步骤

加载配置文件、添加引擎并且拥有模板后,我们可以添加处理程序来开始读取、写入或移除文件中的模板。 请参阅保护处理程序概念