このクイック スタートでは、MIP Policy SDK を使用して、秘密度ラベルを適用または変更するときに実行する必要があるアクションを計算する方法について説明します。
Prerequisites
まだ行っていない場合は、続行する前に次の前提条件を満たしていることを確認してください。
- まず、クイック スタート: 秘密度ラベルの一覧表示 - Policy SDK (C++) を完了します。これにより、スターター Visual Studio ソリューションが構築されます。
- 必要に応じて、 ExecutionState の概念を確認します。
- 省略可能: 「コンピューティング アクションの概念」を確認してください。
ExecutionState を実装する
ComputeActions()を呼び出す前に、現在および目的のラベル状態を提供するmip::ExecutionStateの実装が必要です。
前のクイック スタートで作成した Visual Studio ソリューションを開きます。
ヘッダー ファイルをプロジェクトに追加し、簡略化された
ExecutionStateを実装してください。#include "mip/upe/execution_state.h" #include "mip/upe/policy_engine.h" #include "mip/upe/metadata_action.h" #include "mip/upe/protect_by_template_action.h" #include <algorithm> #include <iostream> #include <memory> #include <string> #include <unordered_map> #include <vector> struct ExecutionStateOptions { std::unordered_map<std::string, std::string> metadata; std::shared_ptr<mip::Label> newLabel; std::string contentIdentifier; mip::AssignmentMethod assignmentMethod = mip::AssignmentMethod::STANDARD; bool isDowngradeJustified = false; std::string downgradeJustification; std::string contentFormat = mip::GetFileContentFormat(); mip::ActionType supportedActions = mip::ActionType::METADATA | mip::ActionType::PROTECT_BY_TEMPLATE | mip::ActionType::JUSTIFY | mip::ActionType::ADD_CONTENT_FOOTER | mip::ActionType::ADD_CONTENT_HEADER | mip::ActionType::ADD_WATERMARK; }; class ExecutionStateImpl : public mip::ExecutionState { public: ExecutionStateImpl(const ExecutionStateOptions& options) : mOptions(options) {} std::shared_ptr<mip::Label> GetNewLabel() const override { return mOptions.newLabel; } mip::AssignmentMethod GetNewLabelAssignmentMethod() const override { return mOptions.assignmentMethod; } std::shared_ptr<mip::ProtectionDescriptor> GetProtectionDescriptor() const override { return nullptr; } std::string GetContentFormat() const override { return mOptions.contentFormat; } std::string GetContentIdentifier() const override { return mOptions.contentIdentifier; } mip::ActionType GetSupportedActions() const override { return mOptions.supportedActions; } std::pair<bool, std::string> IsDowngradeJustified() const override { return std::make_pair(mOptions.isDowngradeJustified, mOptions.downgradeJustification); } std::vector<mip::MetadataEntry> GetContentMetadata( const std::vector<std::string>& names, const std::vector<std::string>& namePrefixes) const override { std::vector<mip::MetadataEntry> result; for (const auto& entry : mOptions.metadata) { const bool requested = (names.empty() && namePrefixes.empty()) || std::find(names.begin(), names.end(), entry.first) != names.end() || std::any_of(namePrefixes.begin(), namePrefixes.end(), [&](const std::string& prefix) { return entry.first.compare(0, prefix.size(), prefix) == 0; }); if (requested) { result.emplace_back(entry.first, entry.second); } } return result; } private: ExecutionStateOptions mOptions; };
新しいラベルのアクションを計算する
ラベル付けされていないコンテンツに新しいラベルを適用するときに必要なアクションを計算するロジックを追加します。
main()関数で、ラベルを一覧表示した後、次のコードを追加します。
// Replace with a valid label ID from your tenant.
string newLabelId = "<label-id>";
// Set up ExecutionState options for the new label.
ExecutionStateOptions options;
options.newLabel = engine->GetLabelById(newLabelId);
options.contentIdentifier = "MyDocument.docx";
// Create ExecutionState, policy handler, and compute actions.
std::unique_ptr<ExecutionStateImpl> state(new ExecutionStateImpl(options));
auto handler = engine->CreatePolicyHandler(false);
auto actions = handler->ComputeActions(*state);
cout << "\nActions for applying label:\n";
for (const auto& action : actions)
{
switch (action->GetType())
{
case mip::ActionType::METADATA:
{
auto metadataAction = static_cast<mip::MetadataAction*>(action.get());
cout << "MetadataAction:" << endl;
for (const auto& name : metadataAction->GetMetadataToRemove())
{
cout << " Remove: " << name << endl;
}
for (const auto& prop : metadataAction->GetMetadataToAdd())
{
cout << " Add: " << prop.GetKey() << " : " << prop.GetValue() << endl;
}
break;
}
case mip::ActionType::PROTECT_BY_TEMPLATE:
{
auto protectAction = static_cast<mip::ProtectByTemplateAction*>(action.get());
cout << "ProtectByTemplateAction: TemplateId = " << protectAction->GetTemplateId() << endl;
break;
}
case mip::ActionType::ADD_CONTENT_FOOTER:
{
cout << "AddContentFooterAction" << endl;
break;
}
case mip::ActionType::ADD_CONTENT_HEADER:
{
cout << "AddContentHeaderAction" << endl;
break;
}
case mip::ActionType::ADD_WATERMARK:
{
cout << "AddWatermarkAction" << endl;
break;
}
case mip::ActionType::JUSTIFY:
{
cout << "JustifyAction" << endl;
break;
}
default:
cout << "Other action type: " << static_cast<int>(action->GetType()) << endl;
break;
}
}
ラベルのダウングレード シナリオを処理する
機密性の高いラベルから低いラベルに変更する場合、ポリシーにより正当な理由の提示が求められることがあります。 両方のラベル ID プレースホルダーをテナントの異なる 2 つのラベルに置き換えます。 運用環境では、コンテンツから完全な既存のメタデータを読み取り、ユーザーから正当な理由を取得します。次のコードでは、簡略化されたメタデータと、デモンストレーションの修正された正当な理由を使用します。
// Simulate existing metadata from a "Confidential" label.
ExecutionStateOptions downgradeOptions;
downgradeOptions.newLabel = engine->GetLabelById("<lower-sensitivity-label-id>");
downgradeOptions.contentIdentifier = "MyDocument.docx";
downgradeOptions.isDowngradeJustified = true;
downgradeOptions.downgradeJustification = "Manager approved declassification";
// Populate existing label metadata (from the previously applied label).
downgradeOptions.metadata["MSIP_Label_<previous-label-id>_Enabled"] = "true";
downgradeOptions.metadata["MSIP_Label_<previous-label-id>_Method"] = "Standard";
std::unique_ptr<ExecutionStateImpl> downgradeState(new ExecutionStateImpl(downgradeOptions));
auto downgradeHandler = engine->CreatePolicyHandler(false);
auto downgradeActions = downgradeHandler->ComputeActions(*downgradeState);
cout << "\nActions for label downgrade:\n";
for (const auto& action : downgradeActions)
{
cout << " Action type: " << static_cast<int>(action->GetType()) << endl;
}
アプリケーションのビルドとテスト
クライアント アプリケーションをビルドしてテストします。
Ctrl + Shift + B (ソリューションのビルド) を使用してアプリケーションをビルドします。 ビルド エラーがない場合は、 F5 (デバッグの開始) を使用して実行します。
最初の実行時に、アプリケーションは認証を求めます。 テナント内のユーザー アカウントの資格情報を指定します。
出力には、次のような、指定したラベルの計算済みアクションが表示されます。
Actions for applying label: MetadataAction: Add: MSIP_Label_<label-id>_Enabled : true Add: MSIP_Label_<label-id>_SetDate : 2026-03-11T10:00:00-0800 Add: MSIP_Label_<label-id>_Method : Standard Add: MSIP_Label_<label-id>_Name : Confidential Add: MSIP_Label_<label-id>_SiteId : <site-id> Add: MSIP_Label_<label-id>_ActionId : <action-id> Add: MSIP_Label_<label-id>_ContentBits : 3 AddContentFooterAction AddContentHeaderAction
次のステップ
このクイック スタートでは、アクションのみが表示されます。ドキュメントのラベル付け、マーク付け、保護は行われません。 完全なアプリケーションは、 GetSupportedActions()を介してアドバタイズするすべてのアクションを実装する必要があります。 変更をコミットする前に正当な理由を処理し、アクションが適用され、コンテンツが正常にコミットされた後にのみ NotifyCommittedActions() を呼び出します。