Quickstart: List sensitivity labels - Policy SDK (C++)

This quickstart shows you how to use the MIP Policy SDK to list the sensitivity labels configured for your organization.

Prerequisites

If you haven't already, be sure to complete the following prerequisites before continuing:

Add logic to list the sensitivity labels

Add logic to list your organization's sensitivity labels by using the Policy engine object.

  1. Open the Visual Studio solution you created in the previous quickstart.

  2. In the main() function, after the engine loads successfully, add the following code:

    // List sensitivity labels
    cout << "\nSensitivity labels for your organization:\n";
    auto labels = engine->ListSensitivityLabels();
    for (const auto& label : labels)
    {
        cout << label->GetName() << " : " << label->GetId() << endl;
    
        for (const auto& child : label->GetChildren())
        {
            cout << "->  " << child->GetName() << " : " << child->GetId() << endl;
        }
    }
    
  3. Optionally, filter labels by content format (for example, "email" or "file"):

    // List labels for email content only
    std::vector<std::string> contentFormats = { "email" };
    auto emailLabels = engine->ListSensitivityLabels(contentFormats);
    

Build and test the application

Build and test your client application.

  1. Use Ctrl+Shift+B (Build Solution) to build the application. If you don't have build errors, use F5 (Start debugging) to run.

  2. On first run, the application prompts for authentication. Provide credentials for a user account in your tenant.

  3. The output displays the sensitivity labels configured for your organization, similar to:

    Sensitivity labels for your organization:
    Public : <label-id>
    General : <label-id>
    ->  Anyone (unrestricted) : <label-id>
    Confidential : <label-id>
    ->  All Employees : <label-id>
    ->  Recipients Only : <label-id>
    Highly Confidential : <label-id>
    ->  All Employees : <label-id>
    ->  Recipients Only : <label-id>
    

Checking label behavior

You can also query label protection type information to determine how each label behaves. Starting in MIP SDK 1.18, the Label class provides methods to check the protection type:

for (const auto& label : labels)
{
    cout << label->GetName();
    
    if (label->HasDoNotForwardProtection())
        cout << " [Do Not Forward]";
    else if (label->HasEncryptOnlyProtection())
        cout << " [Encrypt Only]";
    else if (label->HasAdhocProtection())
        cout << " [Custom Protection]";
    
    cout << endl;
}

Next steps