AuthorizationContext 類別

定義

評估所有授權原則的結果可從已傳送訊息中的語彙基元或呼叫 GetAuthorizationPolicies(OperationContext) 方法取得。The result of evaluating all authorization policies available from the tokens in the sent message and by calling the GetAuthorizationPolicies(OperationContext) method.

public ref class AuthorizationContext abstract : System::IdentityModel::Policy::IAuthorizationComponent
public abstract class AuthorizationContext : System.IdentityModel.Policy.IAuthorizationComponent
type AuthorizationContext = class
    interface IAuthorizationComponent
Public MustInherit Class AuthorizationContext
Implements IAuthorizationComponent
繼承
AuthorizationContext
實作

範例

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 claim sets 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;
}
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 claim sets 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 

備註

評估授權管理員中的所有授權原則會產生一組 ClaimSet 物件。Evaluating all of the authorization policies in an authorization manager results in a set of ClaimSet objects. 這些物件會組成授權內容。These objects make up an authorization context.

授權內容包含一組宣告集物件:指定評估授權內容有效之期間範圍的到期時間,以及唯一的識別項。An authorization context contains a set of claim set objects, an expiration time that specifies the span of time during which the authorization context is valid, and a unique identifier.

目前作業的 AuthorizationContext 可以透過 AuthorizationContext 屬性存取。The AuthorizationContext for the current operation can be accessed via the AuthorizationContext property.

建構函式

AuthorizationContext()

初始化 AuthorizationContext 類別的新執行個體。Initializes a new instance of the AuthorizationContext class.

屬性

ClaimSets

取得與授權原則相關聯的宣告集。Gets the set of claims associated with an authorization policy.

ExpirationTime

取得此 AuthorizationContext 物件不再是有效的日期和時間。Gets the date and time at which this AuthorizationContext object is no longer valid.

Id

取得此 AuthorizationContext 物件的唯一識別項。Gets a unique identifier for this AuthorizationContext object.

Properties

取得與此 AuthorizationContext 物件相關聯的非宣告屬性集合。Gets a collection of non-claim properties associated with this AuthorizationContext object.

方法

CreateDefaultAuthorizationContext(IList<IAuthorizationPolicy>)

評估所有指定的授權原則並建立 AuthorizationContextEvaluate all of the specified authorization policies and create an AuthorizationContext.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於