ServiceSecurityContext 클래스

정의

원격 상대방의 보안 컨텍스트를 나타냅니다. 클라이언트에서는 서비스 ID를 나타내고 서비스에서는 클라이언트 ID를 나타냅니다.

public ref class ServiceSecurityContext
public class ServiceSecurityContext
type ServiceSecurityContext = class
Public Class ServiceSecurityContext
상속
ServiceSecurityContext

예제

다음 예제에서는 ServiceSecurityContext 클래스를 사용하여 현재 보안 컨텍스트에 대한 정보를 제공합니다. 이 코드는 StreamWriter 클래스의 인스턴스를 만들어 파일에 정보를 씁니다.

// When this method runs, the caller must be an authenticated user
// and the ServiceSecurityContext is not a null instance.
public double Add(double n1, double n2)
{
    // Write data from the ServiceSecurityContext to a file using the StreamWriter class.
    using (StreamWriter sw = new StreamWriter(@"c:\ServiceSecurityContextInfo.txt"))
    {
        // Write the primary identity and Windows identity. The primary identity is derived from
        // the credentials used to authenticate the user. The Windows identity may be a null string.
        sw.WriteLine("PrimaryIdentity: {0}", ServiceSecurityContext.Current.PrimaryIdentity.Name);
        sw.WriteLine("WindowsIdentity: {0}", ServiceSecurityContext.Current.WindowsIdentity.Name);

        // Write the claimsets in the authorization context. By default, there is only one claimset
        // provided by the system.
        foreach (ClaimSet claimset in ServiceSecurityContext.Current.AuthorizationContext.ClaimSets)
        {
            foreach (Claim claim in claimset)
            {
                // Write out each claim type, claim value, and the right. There are two
                // possible values for the right: "identity" and "possessproperty".
                sw.WriteLine("Claim Type: {0}, Resource: {1} Right: {2}",
                    claim.ClaimType,
                    claim.Resource.ToString(),
                    claim.Right);
                sw.WriteLine();
            }
        }
    }
    return n1 + n2;
}
' When this method runs, the caller must be an authenticated user and the ServiceSecurityContext 
' is not a null instance. 
Public Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Add
    ' Write data from the ServiceSecurityContext to a file using the StreamWriter class.
    Dim sw As New StreamWriter("c:\ServiceSecurityContextInfo.txt")
    Try
        ' Write the primary identity and Windows identity. The primary identity is derived from 
        ' the credentials used to authenticate the user. The Windows identity may be a null string.
        sw.WriteLine("PrimaryIdentity: {0}", ServiceSecurityContext.Current.PrimaryIdentity.Name)
        sw.WriteLine("WindowsIdentity: {0}", ServiceSecurityContext.Current.WindowsIdentity.Name)

        ' Write the claimsets in the authorization context. By default, there is only one claimset
        ' provided by the system. 
        Dim claimset As ClaimSet
        For Each claimset In ServiceSecurityContext.Current.AuthorizationContext.ClaimSets
            Dim claim As Claim
            For Each claim In claimset
                ' Write out each claim type, claim value, and the right. There are two
                ' possible values for the right: "identity" and "possessproperty". 
                sw.WriteLine("Claim Type: {0}, Resource: {1} Right: {2}", _
                claim.ClaimType, _
                claim.Resource.ToString(), _
                claim.Right)
                sw.WriteLine()
            Next claim
        Next claimset
    Finally
        sw.Dispose()
    End Try
    Return n1 + n2
End Function

다음 예제에서는 클레임 집합을 구문 분석하는 데 CheckAccessCore를 사용하는 ServiceSecurityContext 메서드의 구현을 보여 줍니다.

public class MyServiceAuthorizationManager : ServiceAuthorizationManager
{
    protected override bool CheckAccessCore(OperationContext operationContext)
    {
        // Extract the action URI from the OperationContext. Match this against the claims
        // in the AuthorizationContext.
        string action = operationContext.RequestContext.RequestMessage.Headers.Action;
        Console.WriteLine("action: {0}", action);

        // Iterate through the various claimsets in the AuthorizationContext.
        foreach(ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets)
        {
            // Examine only those claim sets issued by System.
            if (cs.Issuer == ClaimSet.System)
            {
                // Iterate through claims of type "http://example.org/claims/allowedoperation".
                foreach (Claim c in cs.FindClaims("http://example.org/claims/allowedoperation",
                    Rights.PossessProperty))
                {
                    // Write the Claim resource to the console.
                    Console.WriteLine("resource: {0}", c.Resource.ToString());

                    // If the Claim resource matches the action URI then return true to allow access.
                    if (action == c.Resource.ToString())
                        return true;
                }
            }
        }

        // If this point is reached, return false to deny access.
         return false;
    }
}
Public Class MyServiceAuthorizationManager
    Inherits ServiceAuthorizationManager
    
    Protected Overrides Function CheckAccessCore(ByVal operationContext As OperationContext) As Boolean 
        ' Extract the action URI from the OperationContext. Match this against the claims
        ' in the AuthorizationContext.
        Dim action As String = operationContext.RequestContext.RequestMessage.Headers.Action
        Console.WriteLine("action: {0}", action)
        
        ' Iterate through the various claimsets in the authorizationcontext.
        Dim cs As ClaimSet
        For Each cs In  operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets
            ' Examine only those claim sets issued by System.
            If cs.Issuer Is ClaimSet.System Then
                ' Iterate through claims of type "http://example.org/claims/allowedoperation".
                Dim c As Claim
                For Each c In  cs.FindClaims("http://example.org/claims/allowedoperation", _
                        Rights.PossessProperty)
                    ' Write the Claim resource to the console.
                    Console.WriteLine("resource: {0}", c.Resource.ToString())
                    
                    ' If the Claim resource matches the action URI then return true to allow access.
                    If action = c.Resource.ToString() Then
                        Return True
                    End If
                Next c
            End If
        Next cs 
        ' If we get here, return false, denying access.
        Return False
    
    End Function 
End Class

설명

데이터는 메시지에 대한 SecurityMessageProperty의 일부입니다.

이 클래스를 사용 하 여 원격에 대 한 정보를 가져올 보안 컨텍스트 런타임 시. 메서드에 액세스할 수 있도록 클라이언트가 인증되고 권한이 부여된 경우 보안 컨텍스트가 만들어집니다. 메시지가 인증되고 권한이 부여된 경우 이 클래스의 인스턴스에서 클라이언트 및 현재 서비스 인스턴스의 보안 정보를 가져올 수 있습니다.

ServiceSecurityContext 클래스의 Current 속성에서 OperationContext의 인스턴스를 검색하거나, 아래의 예제와 같이 서비스 작업 메서드 내에서 이 클래스를 사용할 수 있습니다.

ClaimSet 구문 분석

클래스의 일반적인 용도는 메서드에 액세스할 때 클라이언트를 식별하고 권한을 부여하기 위해 현재 클레임 집합을 검색하는 것입니다. ClaimSet 클래스는 Claim 개체의 컬렉션을 포함하며, 특정 클레임이 있는지 여부를 확인하기 위해 각 개체를 구문 분석할 수 있습니다. 지정된 클레임이 있는 경우 권한을 부여할 수 있습니다. CheckAccessCore 클래스의 ServiceAuthorizationManager 메서드를 재정의하면 이 기능을 사용할 수 있습니다. 전체 예제를 참조 하세요. 합니다 권한 부여 정책합니다.

특정 상황에서는 원격 클라이언트가 익명 사용자로 인증된 경우에도 IsAuthenticated 인터페이스의 IIdentity 속성에서 true를 반환합니다. PrimaryIdentity 속성은 IIdentity 인터페이스의 구현을 반환합니다. 그러려면 다음과 같은 경우를 충족해야 합니다.

  • 서비스에서 Windows 인증을 사용하는 경우

  • 서비스에서 익명 로그온을 허용하는 경우

  • 바인딩은 customBinding>입니다<.

  • 사용자 지정 바인딩에 <security> 요소가 있는 경우

  • 요소에는 <security> 특성이 <설정된 secureConversationBootstrap>requireSecurityContextCancellation 포함됩니다 false.

생성자

ServiceSecurityContext(AuthorizationContext)

지정된 인증 매개 변수를 사용하여 ServiceSecurityContext 클래스의 새 인스턴스를 초기화합니다.

ServiceSecurityContext(AuthorizationContext, ReadOnlyCollection<IAuthorizationPolicy>)

지정된 인증 매개 변수 및 정책 컬렉션을 사용하여 ServiceSecurityContext 클래스의 새 인스턴스를 초기화합니다.

ServiceSecurityContext(ReadOnlyCollection<IAuthorizationPolicy>)

정책 개체의 컬렉션을 사용하여 ServiceSecurityContext 클래스의 새 인스턴스를 초기화합니다.

속성

Anonymous

일반적으로 익명의 상대방을 나타내는 데 사용되는 빈 클레임 컬렉션, ID 및 기타 컨텍스트 데이터가 포함된 ServiceSecurityContext 클래스의 인스턴스를 반환합니다.

AuthorizationContext

이 클래스의 인스턴스에 대한 인증 정보를 가져옵니다. AuthorizationContext는 애플리케이션에서 상대방의 정보를 조사하고 가져올 수 있는 ClaimSet의 컬렉션을 포함합니다.

AuthorizationPolicies

이 클래스의 인스턴스와 연결된 정책의 컬렉션을 가져옵니다.

Current

현재 ServiceSecurityContext를 가져옵니다.

IsAnonymous

현재 클라이언트에서 서비스에 대한 자격 증명을 제공했는지 여부를 나타내는 값을 가져옵니다.

PrimaryIdentity

현재 설정에 연결된 기본 ID를 가져옵니다.

WindowsIdentity

현재 설정의 Windows ID를 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보