Class AuthorizationPolicy
- Namespace
- Excalibur.A3.Authorization
- Assembly
- Excalibur.A3.Core.dll
Represents an authorization policy that evaluates user permissions and grants based on activities and resources.
public sealed class AuthorizationPolicy : IAuthorizationPolicy, IPolicy
- Inheritance
-
AuthorizationPolicy
- Implements
- Inherited Members
- Extension Methods
Remarks
This policy evaluates grant data in pure C# to determine access rights.
Grants are keyed by scope string in the format {TenantId}:{GrantType}:{Qualifier}, composed
through SegmentedKey so that no two distinct triples can address one grant. Every
producer and every probe of this key MUST go through that composer: a raw interpolation here would
not match the escaped key the store wrote.
Uses a dual-index approach: exact grants are stored in a dictionary for O(1) lookup, while wildcard grants are stored in a list sorted by specificity for fallback matching.
Constructors
AuthorizationPolicy(IDictionary<string, object>, IReadOnlyDictionary<string, IReadOnlyCollection<string>>, ITenantContext, string)
Initializes a new instance of the AuthorizationPolicy class.
public AuthorizationPolicy(IDictionary<string, object> grants, IReadOnlyDictionary<string, IReadOnlyCollection<string>> activityGroups, ITenantContext tenantContext, string userId)
Parameters
grantsIDictionary<string, object>The user's grants, keyed by scope string.
activityGroupsIReadOnlyDictionary<string, IReadOnlyCollection<string>>Activity group mappings.
tenantContextITenantContextThe ambient tenant context. Required: this store partitions rows by tenant, and it resolves that partition from here, so there is no state in which the partition is undecided. A single-tenant host receives the framework default context and operates as the one canonical tenant.
userIdstringThe user identifier for the current context.
Properties
TenantId
Gets the tenant identifier associated with the authorization policy.
public string TenantId { get; }
Property Value
- string
The tenant identifier.
UserId
Gets the user identifier associated with the authorization policy.
public string UserId { get; }
Property Value
Methods
HasGrant(string)
Determines if the user has a grant for the specified activity.
public bool HasGrant(string activityName)
Parameters
activityNamestringThe name of the activity to check for a grant.
Returns
- bool
trueif the user has a grant; otherwise,false.
HasGrant(string, string)
Determines if the user has a grant for a specific resource type and resource ID.
public bool HasGrant(string resourceType, string resourceId)
Parameters
Returns
- bool
trueif the user has a grant; otherwise,false.
HasGrant<TActivity>()
Determines if the user has a grant for a specific activity type.
public bool HasGrant<TActivity>()
Returns
- bool
trueif the user has a grant; otherwise,false.
Type Parameters
TActivityThe activity type to check for a grant.
HasGrant<TResourceType>(string)
Determines if the user has a grant for a specific resource type and resource ID.
public bool HasGrant<TResourceType>(string resourceId)
Parameters
resourceIdstringThe identifier of the resource.
Returns
- bool
trueif the user has a grant; otherwise,false.
Type Parameters
TResourceTypeThe resource type to check.
IsAuthorized(string, string?)
Determines if the user is authorized to perform an activity on an optional resource.
public bool IsAuthorized(string activityName, string? resourceId)
Parameters
activityNamestringThe name of the activity to authorize.
resourceIdstringThe identifier of the resource, or null if not applicable.
Returns
- bool
trueif the user is authorized; otherwise,false.