다음을 통해 공유


작업 2: 워크플로 서비스에서 클레임 기준 권한 부여 사용

이 작업에서는 사용자 자격 증명의 집합 하나만 연습 1: 기본 워크플로 서비스 만들기에서 만든 워크플로 서비스에서 작업을 호출할 수 있도록 합니다. 이러한 자격 증명은 ClaimSet의 형태로 서비스에 전달됩니다. ClaimSets에 대한 자세한 내용은 Managing Claims and Authorization with the Identity Model를 참조하십시오.

참고

Visual Studio Workflow Designer를 사용하여 워크플로 서비스를 만들거나 관리할 경우 의사 유효성 검사 오류가 발생할 수 있습니다. 프로젝트를 성공적으로 빌드할 수 있으면 유효성 검사 오류를 무시해도 됩니다.

ClaimSets를 통해 사용자 유효성 검사 사용

  1. WorkflowServiceTutorial 솔루션이 현재 열려 있지 않으면 Visual Studio 2008을 열고 파일을 클릭한 다음 열기를 강조 표시하고 WorkflowServiceTutorial 솔루션으로 이동합니다.

  2. 솔루션 탐색기 창의 WorkflowServiceTutorial 프로젝트 노드 아래에서 참조 하위 폴더를 마우스 오른쪽 단추로 클릭하고 참조 추가를 선택합니다. 또는 Visual Basic 솔루션을 만든 경우 WorkflowServiceTutorial 프로젝트 노드를 마우스 오른쪽 단추로 클릭하고 참조 추가를 선택합니다.

  3. 참조 추가 대화 상자의 .NET 탭에서 System.IdentityModel을 선택하고 확인을 클릭합니다.

  4. ClaimSetList 개체가 이 작업에서 사용되므로 Workflow1.cs의 맨 위에 있는 문을 사용하여 다음을 추가합니다.

    using System.IdentityModel.Claims;
    using System.Collections.Generic;
    

    Visual Basic 솔루션을 만든 경우 WorkflowServiceTutorial 프로젝트 노드를 마우스 오른쪽 단추로 클릭하고 속성을 선택합니다. 참조 탭을 선택하고 가져온 네임스페이스 아래에서 System.IdentityModel.Claims의 확인란을 클릭합니다. System.Collections.Generic 네임스페이스는 이미 지원됩니다.

  5. 워크플로 서비스의 Workflow Designer가 표시되지 않으면 Workflow1.cs(또는 Visual Basic 솔루션을 만든 경우 Workflow1.vb)를 마우스 오른쪽 단추로 클릭하여 디자이너를 열고 디자이너 보기를 선택합니다.

  6. Workflow1InitialState StateActivity 활동에서 WaitToStartService EventDrivenActivity 활동을 두 번 클릭하여 해당 복합 활동을 확장합니다.

  7. StartupService 작업과 연결된 ReceiveActivity 활동을 강조 표시합니다.

  8. 속성 창의 OperationValidation 아래에서 ValidateUser를 입력하고 Enter 키를 눌러 OperationValidation 이벤트에 대한 이벤트 처리기를 생성합니다.

  9. ValidateUser 이벤트 처리기로 이동합니다.

    ValidateUser의 본문에서 사용자가 이전에 서비스에서 인식되었는지 확인하고, 그렇지 않으면 해당 사용자가 작업을 호출할 수 없도록 합니다. 예를 들어, 이는 영업 직원이 구매 주문을 시작하고 며칠 후까지 완료하지 않은 경우에 유용합니다. 사용자가 서비스에서 작업을 더 호출할 수 있도록 허용하기 전에 해당 사용자가 동일한 사용자인지 확인해야 합니다. 대화 및 컨텍스트 ID는 악의적인 사용자가 가장할 수 있기 때문에 사용할 수 없습니다.

        Private Sub ValidateUser(ByVal sender As System.Object, ByVal e As System.Workflow.Activities.OperationValidationEventArgs)
            For Each claims As ClaimSet In e.ClaimSets
                ' Find the claim that contains the name of the operation caller.
                Dim opCaller As List(Of Claim) = claims.FindClaims(ClaimTypes.Name, Rights.PossessProperty).ToList()
    
                ' Retrieve the name of the caller from the claim.
                Dim opCallerName As String = opCaller(0).Resource.ToString()
    
                ' If this is the caller's first time through the ValidationUser method, set 
                ' the operation caller's name to a global variable named "owner." Every subsequent
                ' operation that uses this method will verify that the caller of
                ' the operation is the same as the caller of the initial operation before
                ' either validating or invalidating the caller.
                If [String].IsNullOrEmpty(owner) Then
                    owner = opCallerName
                ElseIf Not owner.Equals(opCallerName) Then
                    e.IsValid = False
                End If
            Next
        End Sub
    
    private void ValidateUser(object sender, OperationValidationEventArgs e)
    {
        foreach (ClaimSet claims in e.ClaimSets)
        {     
            // Find the claim that contains the name of the operation caller.
            List<Claim> opCaller = claims.FindClaims(ClaimTypes.Name, Rights.PossessProperty).ToList<Claim>();
    
            // Retrieve the name of the caller from the claim.
            string opCallerName = opCaller[0].Resource.ToString();
    
            // If this is the caller's first time through the ValidationUser method, set 
            // the operation caller's name to a global variable named "owner." Every subsequent
            // operation that uses this method will verify that the caller of
            // the operation is the same as the caller of the initial operation before
            // either validating or invalidating the caller.
            if(String.IsNullOrEmpty(owner))
            {
                owner = opCallerName;
            }
            else if (!owner.Equals(opCallerName))
            {
                e.IsValid = false;
            }
        }
    }
    
  10. 다음 코드와 같이 이후의 작업 호출을 받을 때 유효성 검사로 사용할 "owner"라는 변수를 선언합니다.

    Public class ServerWorkflow
        Inherits StateMachineWorkflowActivity
    
        ' These variables are bound to the input and output parameters of the ReceiveActivity.
        Public returnValue As Int32 = Nothing
        Public inputValue As Int32 = Nothing
    
        'This variable contains the user name for the NT account used in operation validation.
        Public owner As String = Nothing
    ...
    End Class
    
    public sealed partial class ServerWorkflow : StateMachineWorkflowActivity
    {
        public ServerWorkflow()
        {
            InitializeComponent();
        }
    
        // These variables are bound to the input and output parameters of the ReceiveActivity.
        public int returnValue = default(int);
        public int inputValue = default(int);
    
        // This variable contains the user name for the NT account used 
        // in operation validation.
        public string owner = default(string);
        ...
    }
    
  11. 나머지 각 작업에 대해 OperationValidation 이벤트를 ValidateUser 메서드와 연결합니다.

  12. 솔루션을 빌드하고 권한 부여 검사가 작동하는지 확인합니다.

    owner 변수가 이미 설정된 후 사용자 이름이 다른 사용자가 서비스에서 작업을 호출하려고 하면 다음과 같은 오류 메시지가 클라이언트에 반환됩니다.

    Security check failed.
    

    참고

    ClaimSetPrincipalPermissionRole 또는 PrincipalPermissionName보다 먼저 처리되므로 NT 계정 그룹에 대해 ClaimSet을 사용하는 권한 부여 검사와 PrincipalPermissionRole을 사용하는 권한 부여 검사를 수행하는 경우 ClaimSet 권한 부여 검사가 먼저 발생합니다.

참고 항목

작업

작업 1: 워크플로 서비스에서 역할 기준 권한 부여 사용

기타 리소스

연습 2: 워크플로 서비스에 보안 기능 구현

Copyright © 2007 by Microsoft Corporation. All rights reserved.