AuthorizationContext Klass

Definition

Resultatet av utvärderingen av alla auktoriseringsprinciper som är tillgängliga från token i det skickade meddelandet och genom att anropa GetAuthorizationPolicies(OperationContext) metoden.

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
Arv
AuthorizationContext
Implementeringar

Exempel

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

Kommentarer

Utvärdering av alla auktoriseringsprinciper i en auktoriseringshanterare resulterar i en uppsättning ClaimSet objekt. Dessa objekt utgör en auktoriseringskontext.

En auktoriseringskontext innehåller en uppsättning anspråksuppsättningsobjekt, en förfallotid som anger hur länge auktoriseringskontexten är giltig och en unik identifierare.

För AuthorizationContext den aktuella åtgärden kan nås via egenskapen AuthorizationContext .

Konstruktorer

Name Description
AuthorizationContext()

Initierar en ny instans av AuthorizationContext klassen.

Egenskaper

Name Description
ClaimSets

Hämtar den uppsättning anspråk som är associerade med en auktoriseringsprincip.

ExpirationTime

Hämtar datum och tid då det här AuthorizationContext objektet inte längre är giltigt.

Id

Hämtar en unik identifierare för det här AuthorizationContext objektet.

Properties

Hämtar en samling icke-anspråksegenskaper som är associerade med det här AuthorizationContext objektet.

Metoder

Name Description
CreateDefaultAuthorizationContext(IList<IAuthorizationPolicy>)

Utvärdera alla angivna auktoriseringsprinciper och skapa en AuthorizationContext.

Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Gäller för