ServiceAuthorizationManager.CheckAccessCore(OperationContext) Método
Definição
Verifica a autorização para um determinado contexto de operação com base na avaliação de política padrão.Checks authorization for the given operation context based on default policy evaluation.
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
O OperationContext para a solicitação de autorização atual.The OperationContext for the current authorization request.
Retornos
true se o acesso for concedido; caso contrário, false.true if access is granted; otherwise, false. O padrão é true.The default is true.
Exemplos
O exemplo a seguir mostra uma substituição do CheckAccessCore método.The following example shows an override of the CheckAccessCore method.
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 obter outro exemplo, consulte como criar um Gerenciador de autorização personalizado para um serviço.For another example, see How to: Create a Custom Authorization Manager for a Service.
Comentários
ServiceSecurityContext geralmente é o resultado da avaliação de política padrão.ServiceSecurityContext is generally the result from the default policy evaluation.
Substitua esse método para fornecer decisões de autorização personalizadas.Override this method to provide custom authorization decisions.
Esse método pode ser usado para tomar decisões de autorização com base em conjuntos de declarações que são inferidos com base em tokens de entrada ou adicionados por meio de políticas de autorização externa.This method can be used to make authorization decisions based on claim sets that are inferred based on incoming tokens, or added through external authorization policies. Ele também pode tomar decisões de autorização com base nas propriedades da mensagem de entrada: por exemplo, o cabeçalho de ação.It can also make authorization decisions based on properties of the incoming message: for example, the action header.
Nesse método, o aplicativo pode usar o operationContext parâmetro para acessar a identidade do chamador ( ServiceSecurityContext ).In this method, the application can use the operationContext parameter to access the caller identity (ServiceSecurityContext). Ao retornar o RequestContext objeto da RequestContext propriedade, o aplicativo pode acessar toda a mensagem de solicitação ( RequestMessage ).By returning the RequestContext object from the RequestContext property, the application can access the entire request message (RequestMessage). Ao retornar o MessageHeaders objeto da IncomingMessageHeaders propriedade, o aplicativo pode acessar a URL do serviço ( To ) e a operação ( Action ).By returning the MessageHeaders object from the IncomingMessageHeaders property, the application can access the service URL (To) and the operation (Action). Com essas informações, o aplicativo pode executar a decisão de autorização de forma adequada.With this information, the application can perform the authorization decision accordingly.
As declarações feitas por um usuário são encontradas no ClaimSet retornado pela ClaimSets Propriedade do AuthorizationContext .The claims made by a user are found in the ClaimSet returned by the ClaimSets property of the AuthorizationContext. O atual AuthorizationContext é retornado pela ServiceSecurityContext propriedade da OperationContext classe.The current AuthorizationContext is returned by the ServiceSecurityContext property of the OperationContext class.