Comparteix a través de


ServiceAuthorizationManager.CheckAccessCore(OperationContext) Método

Definición

Comprueba la autorización para el contexto de la operación determinado basándose en la evaluación de la directiva predeterminada.

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

Parámetros

operationContext
OperationContext

OperationContext para la solicitud de la autorización actual.

Devoluciones

Boolean

true si se permite el acceso; de lo contrario, false. De manera predeterminada, es true.

Ejemplos

En el siguiente ejemplo de código se muestra una invalidación del método CheckAccessCore.

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

Para obtener otro ejemplo, vea How to: Create a Custom Authorization Manager for a Service.

Comentarios

ServiceSecurityContext generalmente es el resultado de la evaluación de la directiva predeterminada.

Reemplace este método para proporcionar decisiones de autorización personalizadas.

Este método se puede utilizar para tomar decisiones de autorización basadas en los conjuntos de notificaciones que se deducen a partir de los tokens de entrada o se agregan a través de las directivas de autorización externas. También puede tomar decisiones de autorización basadas en las propiedades del mensaje entrante: por ejemplo, el encabezado de acción.

En este método, la aplicación puede utilizar el parámetro operationContext para tener acceso a la identidad del llamador (ServiceSecurityContext). Al devolver el objeto RequestContext de la propiedad RequestContext, la aplicación puede tener acceso al mensaje de solicitud completo (RequestMessage). Al devolver el objeto MessageHeaders de la propiedad IncomingMessageHeaders, la aplicación puede tener acceso a la dirección URL del servicio (To) y a la operación (Action). Con esta información, la aplicación puede tomar la decisión de la autorización en consecuencia.

Las demandas realizadas por un usuario se encuentran en el ClaimSet devuelto por la propiedad ClaimSets de AuthorizationContext. La propiedad AuthorizationContext de la clase ServiceSecurityContext devuelve el OperationContext actual.

Se aplica a