Language

ServiceAuthorizationManager.CheckAccessCore(OperationContext) メソッド

定義

既定のポリシー評価に基づいて、指定された操作コンテキストの承認を確認します。

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

パラメーター

operationContext
OperationContext

現在の承認要求の OperationContext 。

返品

true アクセス権が付与されている場合。それ以外の場合は false。 既定値は true です。

例

次の例は、 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

別の例については、「 方法: サービスのカスタム承認マネージャーを作成する」を参照してください。

注釈

ServiceSecurityContext は通常、既定のポリシー評価の結果です。

カスタム承認の決定を行うには、このメソッドをオーバーライドします。

このメソッドを使用すると、受信トークンに基づいて推論される要求セットに基づいて承認を決定したり、外部承認ポリシーを使用して追加したりすることができます。 また、受信メッセージのプロパティ (アクション ヘッダーなど) に基づいて承認の決定を行うこともできます。

このメソッドでは、アプリケーションで operationContext パラメーターを使用して、呼び出し元 ID (ServiceSecurityContext) にアクセスできます。 RequestContext プロパティからRequestContext オブジェクトを返すことで、アプリケーションは要求メッセージ全体 (RequestMessage) にアクセスできます。 MessageHeaders プロパティからIncomingMessageHeaders オブジェクトを返すことで、アプリケーションはサービス URL (To) と操作 (Action) にアクセスできます。 この情報を使用すると、アプリケーションはそれに応じて承認決定を実行できます。

ユーザーが行った要求は、ClaimSetの ClaimSets プロパティによって返されるAuthorizationContextにあります。 現在のAuthorizationContextは、ServiceSecurityContext クラスのOperationContext プロパティによって返されます。

適用対象