ServiceAuthorizationManager.CheckAccessCore(OperationContext) Metod

Definition

Kontrollerar auktoriseringen för den angivna åtgärdskontexten baserat på standardprinciputvärdering.

protected:
 virtual bool CheckAccessCore(System::ServiceModel::OperationContext ^ operationContext);
protected virtual bool CheckAccessCore(System.ServiceModel.OperationContext operationContext);
abstract member CheckAccessCore : System.ServiceModel.OperationContext -> bool
override this.CheckAccessCore : System.ServiceModel.OperationContext -> bool
Protected Overridable Function CheckAccessCore (operationContext As OperationContext) As Boolean

Parametrar

operationContext
OperationContext

OperationContext För den aktuella auktoriseringsbegäran.

Returer

trueom åtkomst beviljas. annars . false Standardvärdet är true.

Exempel

I följande exempel visas en åsidosättning av CheckAccessCore metoden.

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;

  // 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://www.contoso.com/claims/allowedoperation".
        foreach (Claim c in cs.FindClaims("http://www.contoso.com/claims/allowedoperation", Rights.PossessProperty))
      {
        // 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
    
    ' 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://www.contoso.com/claims/allowedoperation".
            Dim c As Claim
            For Each c In  cs.FindClaims("http://www.contoso.com/claims/allowedoperation", _
                 Rights.PossessProperty)
                ' 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 this point is reached, return false to deny access.
    Return False

End Function

Ett annat exempel finns i How to: Create a Custom Authorization Manager for a Service (Så här skapar du en anpassad auktoriseringshanterare för en tjänst).

Kommentarer

ServiceSecurityContext är vanligtvis resultatet från standardprinciputvärderingen.

Åsidosätt den här metoden för att tillhandahålla anpassade auktoriseringsbeslut.

Den här metoden kan användas för att fatta auktoriseringsbeslut baserat på anspråksuppsättningar som härleds baserat på inkommande token eller läggs till via externa auktoriseringsprinciper. Den kan också fatta auktoriseringsbeslut baserat på egenskaperna för det inkommande meddelandet: till exempel åtgärdsrubriken.

I den här metoden kan programmet använda parametern operationContext för att komma åt anroparidentiteten (ServiceSecurityContext). Genom att RequestContext returnera objektet från RequestContext egenskapen kan programmet komma åt hela begärandemeddelandet (RequestMessage). Genom att MessageHeaders returnera objektet från IncomingMessageHeaders egenskapen kan programmet komma åt tjänstens URL (To) och åtgärden (Action). Med den här informationen kan programmet utföra auktoriseringsbeslutet i enlighet med detta.

Anspråken som görs av en användare finns i den ClaimSet som returneras av ClaimSets egenskapen för AuthorizationContext. AuthorizationContext Strömmen returneras av ServiceSecurityContext egenskapen för OperationContext klassen.

Gäller för