Microsoft Information Protection File SDK - Giustificazione dell'azione per ridurre un'etichetta di riservatezza in un file (C++)

Questo argomento di avvio rapido illustra la gestione di un'operazione di downgrade dell'etichetta quando i criteri di etichetta richiedono una giustificazione. In questo caso si userà mip::FileHandler la classe per modificare le etichette di un file. Per altri dettagli, vedere Informazioni di riferimento sulle API.

Prerequisiti

Se non è già stato fatto, assicurarsi di completare i prerequisiti seguenti prima di continuare:

Aggiungere la logica per impostare un'etichetta inferiore su un file protetto

Aggiungere la logica per impostare un'etichetta di riservatezza in un file usando l'oggetto mip::FileHandler .

  1. Aprire la soluzione di Visual Studio creata nell'argomento di avvio rapido precedente: Impostare/ottenere etichette di riservatezza (C++).

  2. Usando Esplora soluzioni, aprire il file con estensione cpp nel progetto che contiene l'implementazione del main() metodo . Per impostazione predefinita, il nome del progetto che lo contiene è stato specificato durante la creazione del progetto.

  3. Aggiungere i #include e le direttive using seguenti, sotto le direttive esistenti corrispondenti, all'inizio del file:

    
        #include "mip/file/file_error.h"
    
        using mip::JustificationRequiredError;
        using std::cin;
    
    
  4. Aggiornare il valore dell'argomento <label-id> di avvio rapido precedente a un'etichetta di riservatezza che richiede una giustificazione per l'abbassamento. Durante questa esecuzione di avvio rapido, questa etichetta verrà prima impostata e quindi si proverà a ridurla tramite frammenti di codice in altri passaggi.

  5. Verso la fine del corpo, sotto system("pause"); e sopra il main() blocco di arresto (dove è stato interrotto nell'avvio rapido precedente), inserire il codice seguente:


// Downgrade label
// Set paths and lower label ID
// Set a new label on input file.

string lowerlabelId = "<lower-label-id>";
cout << "\nApplying new Label ID " << lowerlabelId << " to " << filePathOut << endl;
mip::LabelingOptions labelingOptions(mip::AssignmentMethod::PRIVILEGED);

// Try to apply a label with lower sensitivity.
try
{
    handler->SetLabel(engine->GetLabelById(lowerlabelId), labelingOptions, mip::ProtectionSettings());
}

catch (const mip::JustificationRequiredError& e)
{
    // Request justification from user.
    cout<<"Please provide justification for downgrading a label: "<<endl;
    string justification;
    cin >> justification;

    // Set Justification provided flag
    bool isDowngradeJustified = true;
    mip::LabelingOptions labelingOptions(mip::AssignmentMethod::PRIVILEGED);
    labelingOptions.SetDowngradeJustification(isDowngradeJustified,justification);

    //Set new label.
    handler->SetLabel(engine->GetLabelById(lowerlabelId), labelingOptions, mip::ProtectionSettings());
}

catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid label ID?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}

// Commit changes, save as a different output file
string lowerFilePathOut = "<lower-output-file-path>";
try
{
    cout << "Committing changes" << endl;
    auto commitPromise = std::make_shared<std::promise<bool>>();
    auto commitFuture = commitPromise->get_future();
    handler->CommitAsync(lowerFilePathOut, commitPromise);
    if (commitFuture.get()) {
        cout << "\nLabel committed to file: " << lowerFilePathOut << endl;
    }
    else {
        cout << "Failed to label: " + lowerFilePathOut << endl;
        return 1;
    }
}
catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid commit file path?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}
system("pause");

// Set up async FileHandler for output file operations
string lowerActualFilePath = "<lower-content-identifier>";
try
{
    auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
    auto handlerFuture = handlerPromise->get_future();
    engine->CreateFileHandlerAsync(
        lowerFilePathOut,
        lowerActualFilePath,
        true,
        std::make_shared<FileHandlerObserver>(),
        handlerPromise);

    handler = handlerFuture.get();
}
catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid output file path?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}

// Get the lowered label from output file
try
{
    cout << "\nGetting the label committed to file: " << lowerFilePathOut << endl;
    auto lowerLabel = handler->GetLabel();
    cout << "Name: " + lowerLabel->GetLabel()->GetName() << endl;
    cout << "Id: " + lowerLabel->GetLabel()->GetId() << endl;
}
catch (const std::exception& e)
{
    cout << "An exception occurred... did you specify a valid label ID?\n\n" << e.what() << "'\n";
    system("pause");
    return 1;
}
system("pause");

  1. Sostituire i valori segnaposto nel codice sorgente usando i valori seguenti:

    Segnaposto Valore
    <lower-label-id> ID etichetta copiato dall'output della console nell'avvio rapido precedente, ad esempio: bb7ed207-046a-4caf-9826-647cff56b990. Assicurarsi che abbia una sensibilità inferiore rispetto all'etichetta di file protetta in precedenza.
    <lower-output-file-path> Percorso del file di output in cui salvare il file modificato.
    <lower-content-identifier> Identificatore leggibile per il contenuto.

Compilare e testare l'applicazione

Compilare e testare l'applicazione client.

  1. Usare CTRL-MAIUSC-B (Compila soluzione) per compilare l'applicazione client. Se non sono presenti errori di compilazione, usare F5 (Avvia debug) per eseguire l'applicazione.

  2. Se il progetto viene compilato ed eseguito correttamente, l'applicazione richiede un token di accesso, ogni volta che l'SDK chiama il AcquireOAuth2Token() metodo.

  Non-Business : 87ba5c36-17cf-14793-bbc2-bd5b3a9f95cz
  Public : 83867195-f2b8-2ac2-b0b6-6bb73cb33afz
  General : f42a3342-8706-4288-bd31-ebb85995028z
  Confidential : 074e457c-5848-4542-9a6f-34a182080e7z
  Highly Confidential : f55c2dea-db0f-47cd-8520-a52e1590fb6z
  Press any key to continue . . .

  Applying Label ID f55c2dea-db0f-47cd-8520-a52e1590fb6z to c:\Test\Test.docx
  Committing changes


  Label committed to file: c:\Test\Test.docx
  Press any key to continue . . .

  Run the PowerShell script to generate an access token using the following values, then copy/paste it below:
  Set $authority to: https://login.windows.net/37f4583d-9985-4e7f-a1ab-71afd8b55ba0
  Set $resourceUrl to: https://aadrm.com
  Sign in with user account: user1@tenant.onmicrosoft.com
  Enter access token: <paste-access-token-here>
  Press any key to continue . . .

  Getting the label committed to file: c:\Test\Test_labeled.docx
  Name: Highly Confidential
  Id: f55c2dea-db0f-47cd-8520-a52e1590fb6z
  Press any key to continue . . . 

  Applying new Label ID f42a3342-8706-4288-bd31-ebb85995028z to c:\Test\Test_labeled.docx
  Please provide justification for downgrading a label:
  Need for sharing with wider audience.
  Committing changes

  Label committed to file: c:\Test\Test_downgraded.docx
  Press any key to continue . . .

  Getting the label committed to file: c:\Test\Test_downgraded.docx
  Name: General
  Id: f42a3342-8706-4288-bd31-ebb85995028z
  Press any key to continue . . .

Si noti che, nel caso in cui l'etichetta eliminata da un file richieda una giustificazione in base ai criteri di etichetta, è consigliabile seguire un approccio simile per DeleteLabel() l'operazione. DeleteLabel() la funzione genera un'eccezione mip::JustificationRequiredError . isDowngradeJustified flag deve essere impostato su true nella gestione delle eccezioni prima di eliminare correttamente l'etichetta.