AuthorizationContext Класс

Определение

Результаты оценки всех политик авторизации, получаемые из маркеров в отправленном сообщении или путем вызова метода GetAuthorizationPolicies(OperationContext).

public ref class AuthorizationContext abstract : System::IdentityModel::Policy::IAuthorizationComponent
public abstract class AuthorizationContext : System.IdentityModel.Policy.IAuthorizationComponent
type AuthorizationContext = class
    interface IAuthorizationComponent
Public MustInherit Class AuthorizationContext
Implements IAuthorizationComponent
Наследование
AuthorizationContext
Реализации

Примеры

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;
    Console.WriteLine("action: {0}", 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://example.org/claims/allowedoperation".
            foreach (Claim c in cs.FindClaims("http://example.org/claims/allowedoperation", Rights.PossessProperty))
            {
                // Write the Claim resource to the console.
                Console.WriteLine("resource: {0}", c.Resource.ToString());

                // 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
    Console.WriteLine("action: {0}", action)

    ' Iterate through the various claim sets 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://example.org/claims/allowedoperation".
            Dim c As Claim
            For Each c In cs.FindClaims("http://example.org/claims/allowedoperation", Rights.PossessProperty)
                ' Write the Claim resource to the console.
                Console.WriteLine("resource: {0}", c.Resource.ToString())

                ' 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 we get here, return false, denying access.
    Return False

End Function

Комментарии

Результатом оценки всех политик авторизации диспетчера авторизации является набор объектов ClaimSet. Эти объекты составляют контекст авторизации.

Контекст авторизации содержит набор объектов набора утверждений, срок действия, задающий продолжительность действия контекста авторизации, и уникальный идентификатор.

Доступ к объекту AuthorizationContext для текущей операции осуществляется через свойство AuthorizationContext.

Конструкторы

AuthorizationContext()

Инициализирует новый экземпляр класса AuthorizationContext.

Свойства

ClaimSets

Возвращает набор утверждений, связанных с политикой авторизации.

ExpirationTime

Возвращает дату и время окончания действия этого объекта AuthorizationContext.

Id

Возвращает уникальный идентификатор для этого объекта AuthorizationContext.

Properties

Возвращает коллекцию свойств, не являющихся утверждениями, связанных с этим объектом AuthorizationContext.

Методы

CreateDefaultAuthorizationContext(IList<IAuthorizationPolicy>)

Оценивает все указанные политики авторизации и создает объект AuthorizationContext.

Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Применяется к