標籤保護類型查詢

本文說明如何使用 MIP SDK API 來識別標籤上所設定的保護類型,讓您的應用程式能在套用保護前做出行為與使用者介面決策。 它也總結了每種保護類型的關鍵 API 與預期行為。

概觀

從 MIP SDK 1.18 開始,該 Label 類別會公開方法來判斷標籤適用的保護類型。 過去,申請只能檢查 HasRightsManagementPolicy() 標籤是否具備任何保護。 新方法使應用能區分以下保護類型:

  • 請勿轉寄:防止收件人轉寄、列印或複製內容的保護措施。
  • 僅加密:保護內容加密,但不限制接收者除解密外的行動。
  • 臨時保護:使用者在申請時定義自訂權限(使用者自訂權利)。

這些方法使應用程式能更智慧地決定如何處理標籤。 例如,電子郵件應用程式可能會根據標籤是否適用「請勿轉發」或「僅加密」保護,提供不同的使用者介面選項。

查詢標籤保護類型

C++

該 mip::Label 類別提供以下方法:

// Returns true if the label applies any protection.
bool HasRightsManagementPolicy() const;

// Returns true if the label applies Do Not Forward protection.
bool HasDoNotForwardProtection() const;

// Returns true if the label applies Encrypt Only protection.
bool HasEncryptOnlyProtection() const;

// Returns true if the label applies ad-hoc (user-defined) protection.
bool HasAdhocProtection() const;

範例:檢查標籤保護類型

for (const auto& label : engine->ListSensitivityLabels()) {
    std::cout << "Label: " << label->GetName() << std::endl;

    if (label->HasRightsManagementPolicy()) {
        if (label->HasDoNotForwardProtection()) {
            std::cout << "  Protection type: Do Not Forward" << std::endl;
        } else if (label->HasEncryptOnlyProtection()) {
            std::cout << "  Protection type: Encrypt Only" << std::endl;
        } else if (label->HasAdhocProtection()) {
            std::cout << "  Protection type: Ad-hoc (user-defined permissions)" << std::endl;
        } else {
            std::cout << "  Protection type: Template-based" << std::endl;
        }
    } else {
        std::cout << "  No protection" << std::endl;
    }
}

C#(.NET)

在 .NET 包裝器中,該 Label 類別會暴露匹配的屬性:

label.HasRightsManagementPolicy  // bool
label.HasDoNotForwardProtection  // bool
label.HasEncryptOnlyProtection   // bool
label.HasAdhocProtection         // bool

範例:檢查標籤保護類型

foreach (var label in engine.SensitivityLabels)
{
    Console.WriteLine($"Label: {label.Name}");

    if (label.HasRightsManagementPolicy)
    {
        if (label.HasDoNotForwardProtection)
            Console.WriteLine("  Protection type: Do Not Forward");
        else if (label.HasEncryptOnlyProtection)
            Console.WriteLine("  Protection type: Encrypt Only");
        else if (label.HasAdhocProtection)
            Console.WriteLine("  Protection type: Ad-hoc (user-defined permissions)");
        else
            Console.WriteLine("  Protection type: Template-based");
    }
    else
    {
        Console.WriteLine("  No protection");
    }
}

與現有 API 的關係

這些新方法擴充了現有 HasRightsManagementPolicy() 方法。 關係如下:

  • 如果 HasRightsManagementPolicy() 返回 false,那麼所有這三種新方法也會返回 false。
  • 若HasRightsManagementPolicy()返回true,至少有一個新方法會返回true,否則若標籤使用基於模板的保護,則不會返回true。
  • 標籤可以結合臨時權限(使用者自訂權限)與「請勿轉發」或「僅加密」。 在這些綜合案例中:
    • HasDoNotForwardProtection() 當標籤套用「請勿轉發」保護時,無論是否包含臨時行為,都會回傳 true 。
    • HasEncryptOnlyProtection() 在標籤僅限加密保護時,無論是否包含臨時行為,均會返回 true。
    • HasAdhocProtection() 只有當標籤套用獨立臨時保護(不含「請勿轉發」或「僅加密」)時,才會回傳 true 。

下一步