ServiceAuthorizationManager.CheckAccessCore(OperationContext) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Controleert de autorisatie voor de opgegeven bewerkingscontext op basis van de standaardbeleidsevaluatie.
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
Parameters
- operationContext
- OperationContext
De OperationContext voor de huidige autorisatieaanvraag.
Retouren
true indien toegang wordt verleend; anders, false. De standaardwaarde is true.
Voorbeelden
In het volgende voorbeeld ziet u een onderdrukking van de CheckAccessCore methode.
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
Zie Voor een ander voorbeeld : Een aangepast autorisatiebeheer maken voor een service.
Opmerkingen
ServiceSecurityContext is over het algemeen het resultaat van de standaardbeleidsevaluatie.
Overschrijf deze methode om aangepaste autorisatiebeslissingen te nemen.
Deze methode kan worden gebruikt om autorisatiebeslissingen te nemen op basis van claimsets die worden afgeleid op basis van binnenkomende tokens of worden toegevoegd via extern autorisatiebeleid. Het kan ook autorisatiebeslissingen nemen op basis van eigenschappen van het binnenkomende bericht: bijvoorbeeld de actieheader.
In deze methode kan de toepassing de operationContext parameter gebruiken om toegang te krijgen tot de aanroeperidentiteit (ServiceSecurityContext). Door het RequestContext object vanuit de RequestContext eigenschap te retourneren, heeft de toepassing toegang tot het volledige aanvraagbericht (RequestMessage). Door het MessageHeaders object vanuit de IncomingMessageHeaders eigenschap te retourneren, heeft de toepassing toegang tot de service-URL (To) en de bewerking (Action). Met deze informatie kan de toepassing de autorisatiebeslissing dienovereenkomstig uitvoeren.
De claims van een gebruiker worden gevonden in de ClaimSet geretourneerde door de ClaimSets eigenschap van de AuthorizationContext. De huidige AuthorizationContext waarde wordt geretourneerd door de ServiceSecurityContext eigenschap van de OperationContext klasse.