개요
이 시나리오 및 사용할 수 있는 위치에 대한 개요는 MIP SDK의 다시 게시를 참조하세요.
필수 조건
아직 완료하지 않은 경우 계속하기 전에 다음 필수 조건을 완료해야 합니다.
- 빠른 시작: 민감도 레이블(C#) 설정/가져오기를 먼저 완료하여, 시작용 Visual Studio 솔루션을 구축하고, 조직의 민감도 레이블을 나열하며, 파일에서 민감도 레이블을 설정하고 읽어옵니다. 이 "방법 - 보호된 파일 다시 게시 - C#" 빠른 시작은 이전 파일을 기반으로 빌드됩니다.
- 선택 사항: MIP SDK 개념에서 파일 처리기를 검토합니다.
- 선택 사항: MIP SDK 개념에서 보호 처리기를 검토합니다.
보호된 파일을 편집하고 다시 게시하는 논리 추가
이전 "빠른 시작: 민감도 레이블 설정/가져오기(C#)" 문서에서 만든 Visual Studio 솔루션을 엽니다.
솔루션 탐색기를 사용하여 메서드 구현
Main()이 포함된 프로젝트에서 .cs 파일을 엽니다. 기본 이름은 프로젝트 생성 시 지정한 이름을 포함한 프로젝트와 동일합니다.본문 끝의
Main()애플리케이션 종료 블록(이전 빠른 시작에서 중단한 위치) 아래Console.ReadKey()와 위에 다음 코드를 삽입합니다.
string protectedFilePath = "<protected-file-path>" // Originally protected file's path from previous quickstart.
//Create a fileHandler for consumption for the Protected File.
var protectedFileHandler = Task.Run(async () =>
await fileEngine.CreateFileHandlerAsync(protectedFilePath,// inputFilePath
protectedFilePath,// actualFilePath
false, //isAuditDiscoveryEnabled
null)).Result; // fileExecutionState
// Store protection handler from file
var protectionHandler = protectedFileHandler.Protection;
//Check if the user has the 'Edit' right to the file
if (protectionHandler.AccessCheck("Edit"))
{
// Decrypt file to temp path
var tempPath = Task.Run(async () => await protectedFileHandler.GetDecryptedTemporaryFileAsync()).Result;
/*
Your own application code to edit the decrypted file belongs here.
*/
/// Follow steps below for re-protecting the edited file. ///
// Create a new file handler using the temporary file path.
var republishHandler = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(tempPath, tempPath, false)).Result;
// Set protection using the ProtectionHandler from the original consumption operation.
republishHandler.SetProtection(protectionHandler);
// New file path to save the edited file
string reprotectedFilePath = "<reprotected-file-path>" // New file path for saving reprotected file.
// Write changes
var reprotectedResult = Task.Run(async () => await republishHandler.CommitAsync(reprotectedFilePath)).Result;
var protectedLabel = protectedFileHandler.Label;
Console.WriteLine(string.Format("Originally protected file: {0}", protectedFilePath));
Console.WriteLine(string.Format("File LabelID: {0} \r\nProtectionOwner: {1} \r\nIsProtected: {2}",
protectedLabel.Label.Id,
protectedFileHandler.Protection.Owner,
protectedLabel.IsProtectionAppliedFromLabel.ToString()));
var reprotectedLabel = republishHandler.Label;
Console.WriteLine(string.Format("Reprotected file: {0}", reprotectedFilePath));
Console.WriteLine(string.Format("File LabelID: {0} \r\nProtectionOwner: {1} \r\nIsProtected: {2}",
reprotectedLabel.Label.Id,
republishHandler.Protection.Owner,
reprotectedLabel.IsProtectionAppliedFromLabel.ToString()));
Console.WriteLine("Press a key to continue.");
Console.ReadKey();
}
Main()의 끝 부분에서 이전 퀵스타트에서 작성한 애플리케이션 종료 블록을 확인하고, 리소스를 해제할 수 있도록 아래 처리기 줄을 추가합니다.
protectedFileHandler = null; protectionHandler = null;다음 값을 사용하여 소스 코드의 자리 표시자 값을 바꿉합니다.
자리 표시자 가치 <보호된 파일 경로> 이전 빠른 시작에서 보호된 파일입니다. <재보호된 파일 경로> 다시 게시할 수정된 파일의 출력 파일 경로입니다.
애플리케이션 빌드 및 테스트
클라이언트 애플리케이션을 빌드하고 테스트합니다.
Ctrl-SHIFT-B(솔루션 빌드)를 사용하여 클라이언트 애플리케이션을 빌드합니다. 빌드 오류가 없는 경우 F5(디버깅 시작)를 사용하여 애플리케이션을 실행합니다.
프로젝트가 성공적으로 빌드되고 실행되는 경우 애플리케이션은 SDK가 메서드를 호출할 때마다 MSAL(Microsoft 인증 라이브러리)을 사용하여 인증을 요청하는 메시지를 표시할 수 있습니다
AcquireToken(). 캐시된 자격 증명이 이미 있는 경우 로그인하고 레이블 목록을 확인하고 적용된 레이블 및 수정된 파일에 대한 정보를 확인하라는 메시지가 표시되지 않습니다.
Personal : 73c47c6a-eb00-4a6a-8e19-efaada66dee6
Public : 73254501-3d5b-4426-979a-657881dfcb1e
General : da480625-e536-430a-9a9e-028d16a29c59
Confidential : 569af77e-61ea-4deb-b7e6-79dc73653959
Highly Confidential : 905845d6-b548-439c-9ce5-73b2e06be157
Press a key to continue.
Getting the label committed to file: C:\Test\Test_protected.docx
File Label: Confidential
IsProtected: True
Press a key to continue.
Originally protected file: C:\Test\Test_protected.docx
File LabelID: 569af77e-61ea-4deb-b7e6-79dc73653959
ProtectionOwner: User1@Contoso.OnMicrosoft.com
IsProtected: True
Reprotected file: C:\Test\Test_reprotected.docx
File LabelID: 569af77e-61ea-4deb-b7e6-79dc73653959
ProtectionOwner: User1@Contoso.OnMicrosoft.com
IsProtected: True
Press a key to continue.