다음을 통해 공유


Microsoft Information Protection 파일 SDK - 파일의 민감도 레이블을 낮추기 위한 작업 근거(C#)

이 빠른 시작에서는 레이블 정책에 근거가 필요한 경우 다운그레이드 레이블 작업의 처리를 다룹니다. 여기서는 파일의 레이블을 변경하는 데 인터페이스를 사용합니다 IFileHandler . 자세한 내용은 API 참조를 참조하세요.

필수 조건

아직 완료하지 않은 경우 계속하기 전에 다음 필수 조건을 완료해야 합니다.

보호된 파일에 하위 레이블을 설정하는 논리 추가

파일 처리기 개체를 사용하여 파일에 민감도 레이블을 설정하는 논리를 추가합니다.

  1. 이전 "빠른 시작: 민감도 레이블 설정/가져오기(C#)"에서 만든 Visual Studio 솔루션을 엽니다.

  2. 솔루션 탐색기를 사용하여 메서드 구현 Main() 이 포함된 프로젝트에서 .cs 파일을 엽니다. 기본값은 프로젝트를 만드는 동안 지정한 이름을 포함하는 프로젝트와 동일합니다.

  3. 이전 빠른 시작의 <label-id> 값을 낮추기 위해 정당성이 필요한 민감도 레이블로 업데이트합니다. 이 빠른 시작 실행 중에 먼저 이 레이블을 설정한 다음, 추가 단계에서 코드 조각을 통해 레이블을 낮추려고 합니다.

  4. 본문 끝의 Main() 애플리케이션 종료 블록(이전 빠른 시작에서 중단한 위치) 아래 Console.ReadKey() 와 위에 다음 코드를 삽입합니다.

    //Set paths and label ID
    string lowerInput = actualOutputFilePath;
    string lowerActualInput = lowerInput;
    string newLabelId = "<new-label-id>";
    string lowerOutput = "<downgraded-labled-output>";
    string lowerActualOutput = lowerOutput;
    
    //Create a file handler for that file
    var downgradeHandler = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(lowerInput, lowerActualInput, true)).Result;
    
    //Set Labeling Options
    LabelingOptions options = new LabelingOptions()
    {
        AssignmentMethod = AssignmentMethod.Standard
    };
    
    try
    {
        //Try to set new label
        downgradeHandler.SetLabel(fileEngine.GetLabelById(newLabelId), options, new ProtectionSettings());
    }
    
    catch (Microsoft.InformationProtection.Exceptions.JustificationRequiredException)
    {
        //Request justification from user
        Console.Write("Please provide justification for downgrading a label: ");
        string justification = Console.ReadLine();
    
        options.IsDowngradeJustified = true;
        options.JustificationMessage = justification;
    
        //Set new label
        downgradeHandler.SetLabel(fileEngine.GetLabelById(newLabelId), options, new ProtectionSettings());
    }
    
    // Commit changes, save as outputFilePath
    var downgradedResult = Task.Run(async () => await downgradeHandler.CommitAsync(lowerActualOutput)).Result;
    
    // Create a new handler to read the labeled file metadata
    var commitHandler = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(lowerOutput, lowerActualOutput, true)).Result;
    
    // Get the label from output file
    var newContentLabel = commitHandler.Label;
    Console.WriteLine(string.Format("Getting the new label committed to file: {0}", lowerOutput));
    Console.WriteLine(string.Format("File Label: {0} \r\nIsProtected: {1}", newContentLabel.Label.Name, newContentLabel.IsProtectionAppliedFromLabel.ToString()));
    Console.WriteLine("Press a key to continue.");
    Console.ReadKey();
    
    
  5. Main()의 끝 부분에 이전 빠른 시작 가이드에서 만든 애플리케이션 종료 블록을 찾고, 다음과 같은 핸들러 줄을 추가하여 리소스를 해제합니다.

    downgradeHandler = null;
    commitHandler = null;
    
  6. 다음 값을 사용하여 소스 코드의 자리 표시자 값을 바꿉합니다.

    자리 표시자 가치
    <강등된 레이블 출력> 수정된 파일을 저장할 출력 파일 경로입니다.
    <새 라벨 ID> 이전 빠른 시작의 콘솔 출력에서 복사한 템플릿 ID입니다. 예를 들면 다음과 bb7ed207-046a-4caf-9826-647cff56b990같습니다. 이전에 보호된 파일 레이블보다 민감도가 낮은지 확인합니다.

애플리케이션 빌드 및 테스트

클라이언트 애플리케이션을 빌드하고 테스트합니다.

  1. Ctrl-SHIFT-B(솔루션 빌드)를 사용하여 클라이언트 애플리케이션을 빌드합니다. 빌드 오류가 없는 경우 F5(디버깅 시작)를 사용하여 애플리케이션을 실행합니다.

  2. 프로젝트가 성공적으로 빌드되고 실행되는 경우 애플리케이션은 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_labeled.docx
  Name: Confidential
  IsProtected: True
  Press any key to continue . . .

  Please provide justification for downgrading a label: Lower label approved.
  Getting the new label committed to file: c:\Test\Test_downgraded.docx
  File Label: General
  IsProtected: False
  Press a key to continue.

주의하십시오, 파일에서 삭제되는 레이블에 레이블 정책에 따른 근거가 필요한 경우, 유사한 방법이 DeleteLabel() 작업에도 적용됩니다. DeleteLabel() 함수는 예외를 JustificationRequiredException throw하고 IsDowngradeJustified 레이블을 성공적으로 삭제하기 전에 예외 처리에서 플래그를 true로 설정해야 합니다.