//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IdentityModel; namespace System.Security.Claims { /// /// This class is used to specify the context of the authorization event. /// public class AuthorizationContext { Collection _action = new Collection(); Collection _resource = new Collection(); ClaimsPrincipal _principal; /// /// Creates an AuthorizationContext with the specified principal, resource, and action. /// /// The principal to be authorized. /// The resource to be authorized for. /// The action to be performed on the resource. /// /// or is set to null. /// public AuthorizationContext( ClaimsPrincipal principal, string resource, string action ) { if ( principal == null ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "principal" ); } if ( string.IsNullOrEmpty( resource ) ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "resource" ); } _principal = principal; _resource.Add( new System.Security.Claims.Claim( ClaimTypes.Name, resource ) ); if ( action != null ) { _action.Add( new System.Security.Claims.Claim( ClaimTypes.Name, action ) ); } } /// /// Creates an AuthorizationContext with the specified principal, resource, and action. /// /// The principal to check authorization for /// The resource for checking authorization to /// The action to be performed on the resource /// When or or is null public AuthorizationContext( ClaimsPrincipal principal, Collection resource, Collection action ) { if ( principal == null ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "principal" ); } if ( resource == null ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "resource" ); } if ( action == null ) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "action" ); } _principal = principal; _resource = resource; _action = action; } /// /// Gets the authorization action /// public Collection Action { get { return _action; } } /// /// Gets the authorization resource /// public Collection Resource { get { return _resource; } } /// /// Gets the authorization principal /// public ClaimsPrincipal Principal { get { return _principal; } } } }