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) |