Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Overzicht
Voor een overzicht van dit scenario en waar het kan worden gebruikt, raadpleegt u Opnieuw publiceren in MIP SDK.
Vereiste voorwaarden
Als u dat nog niet hebt gedaan, moet u de volgende vereisten voltooien voordat u doorgaat:
- Eerst Quickstart: Stel/haal vertrouwelijkheidslabels (C++) op voltooi, waarmee een startoplossing in Visual Studio wordt gebouwd, om de vertrouwelijkheidslabels van een organisatie op te sommen, om vertrouwelijkheidslabels in te stellen en te lezen naar/van een bestand. Deze startgids 'How to - Downgrade/Remove a label that needs a justification C++' is gebaseerd op de vorige.
- Optioneel: Bekijk de bestandshandlers binnen de MIP SDK-concepten.
- Optioneel: Beoordeel beveiligingshandlers in de MIP SDK-concepten.
Logica toevoegen aan de klasse FileHandler Observer
Als u een beveiligd bestand wilt ontsleutelen met behulp van GetDecryptedTemporaryFileAsync() de methode die wordt weergegeven door mip::FileHandler, moeten callbacks voor de asynchrone methode voor succes en mislukking worden gedefinieerd zoals hieronder wordt beschreven.
Open de Visual Studio-oplossing die u hebt gemaakt in de vorige 'Quickstart: Vertrouwelijkheidslabels instellen/ophalen(C++).
Open met Solution Explorer het
filehandler_observer.hbestand voor uw project. Tegen het einde van de FileHandler-definitie, vóór};, voeg onderstaande regels toe voor de methodedeclaratie.void OnGetDecryptedTemporaryFileSuccess(const std::string& decryptedFilePath, const std::shared_ptr<void>& context) override; void OnGetDecryptedTemporaryFileFailure(const std::exception_ptr& error, const std::shared_ptr<void>& context) override;Open met Solution Explorer het
filehandler_observer.cppbestand in uw project. Voeg aan het einde van het bestand onderstaande regels toe voor methodedefinities.void FileHandlerObserver::OnGetDecryptedTemporaryFileSuccess(const std::string& decryptedFilePath, const std::shared_ptr<void>& context) { auto promise = std::static_pointer_cast<std::promise<std::string>>(context); promise->set_value(decryptedFilePath); } void FileHandlerObserver::OnGetDecryptedTemporaryFileFailure(const std::exception_ptr& error, const std::shared_ptr<void>& context) { auto promise = std::static_pointer_cast<std::promise<std::string>>(context); promise->set_exception(error); }
Logica toevoegen om een beveiligd bestand te bewerken en opnieuw te publiceren
Open met Solution Explorer het .cpp-bestand in uw project dat de implementatie van de
main()methode bevat. Deze wordt standaard ingesteld op dezelfde naam als het project dat het bevat, die u hebt opgegeven tijdens het maken van het project.Tegen het einde van de main() functie, onder system("pause"); en boven return 0; (waar u in de vorige Quickstart bent gebleven), voegt u de volgende code in:
//Originally protected file's path.
std::string protectedFilePath = "<protected-file-path>";
// Create file handler for the file
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
auto handlerFuture = handlerPromise->get_future();
engine->CreateFileHandlerAsync(protectedFilePath,
protectedFilePath,
true,
std::make_shared<FileHandlerObserver>(),
handlerPromise);
auto protectedFileHandler = handlerFuture.get();
// retieve and store protection handler from file
auto protectionHandler = protectedFileHandler->GetProtection();
//Check if the user has the 'Edit' right to the file and if so decrypt the file.
if (protectionHandler->AccessCheck("Edit")) {
// Decrypt file to temp path using the same file handler
auto tempPromise = std::make_shared<std::promise<string>>();
auto tempFuture = tempPromise->get_future();
protectedFileHandler->GetDecryptedTemporaryFileAsync(tempPromise);
auto tempPath = tempFuture.get();
/// Write code here to perform further operations for edit ///
/// Follow steps below for re-protecting the edited file ///
// Create a new file handler using the temporary file path.
auto reprotectPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
auto reprotectFuture = reprotectPromise->get_future();
engine->CreateFileHandlerAsync(tempPath,
tempPath,
true,
std::make_shared<FileHandlerObserver>(),
reprotectPromise);
auto republishHandler = reprotectFuture.get();
// Set protection using the ProtectionHandler from the original consumption operation.
republishHandler->SetProtection(protectionHandler);
std::string reprotectedFilePath = "<protected-file-path>";
// Commit changes
auto republishPromise = std::make_shared<std::promise<bool>>();
auto republishFuture = republishPromise->get_future();
republishHandler->CommitAsync(reprotectedFilePath, republishPromise);
// Validate republishing
cout << "Protected File: " + protectedFilePath<<endl;
cout << "Protected Label ID: " + protectedFileHandler->GetLabel()->GetLabel()->GetId() << endl;
cout << "Protection Owner: " + protectedFileHandler->GetProtection()->GetOwner() << endl<<endl;
cout << "Republished File: " + reprotectedFilePath<<endl;
cout << "Republished Label ID: " + republishHandler->GetLabel()->GetLabel()->GetId() << endl;
cout << "Republished Owner: " + republishHandler->GetProtection()->GetOwner() << endl;
}
Zoek aan het einde van Main() het afsluitblok van de toepassing dat in de vorige snelstart is gemaakt en voeg de onderstaande handlerregels toe om bronnen vrij te geven.
protectedFileHandler = nullptr; protectionHandler = nullptr;Vervang de tijdelijke aanduidingen in de broncode met behulp van de volgende waarden:
Plaatsvervanger Waarde <beveiligd-bestandspad> Beveiligd bestand uit de vorige quickstart. <opnieuw beveiligd-bestandspad> Het pad naar het uitvoerbestand om het gewijzigde bestand opnieuw te publiceren.
De toepassing bouwen en testen
Bouw en test uw clientapplicatie.
Gebruik Ctrl-SHIFT-B (build solution) om uw clienttoepassing te bouwen. Als u geen buildfouten hebt, gebruikt u F5 (Foutopsporing starten) om uw toepassing uit te voeren.
Als uw project wordt gebouwd en uitgevoerd, vraagt de toepassing om een toegangstoken, telkens wanneer de SDK uw
AcquireOAuth2Token()methode aanroept. Zoals u eerder hebt gedaan in de quickstart 'Vertrouwelijkheidslabel instellen/ophalen', voert u uw PowerShell-script uit om het token elke keer te verkrijgen met behulp van de waarden die zijn opgegeven voor $authority en $resourceUrl.
Sensitivity labels for your organization:
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 074e457c-5848-4542-9a6f-34a182080e7z to C:\Test\Test.docx
Committing changes
Label committed to file: C:\Test\Test_labeled.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: Confidential
Id: 074e457c-5848-4542-9a6f-34a182080e7z
Press any key to continue . . .
Protected File: C:\Test\Test_labeled.docx
Protected Label ID: 074e457c-5848-4542-9a6f-34a182080e7z
Protection Owner: user1@tenant.onmicrosoft.com
Republished File: c:\Test\Test_republished.docx
Republished Label ID: 074e457c-5848-4542-9a6f-34a182080e7z
Republished Owner: user1@tenant.onmicrosoft.com
Press any key to close this window . . .