Table of Contents

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

grants IDictionary<string, object>

The user's grants, keyed by scope string.

activityGroups IReadOnlyDictionary<string, IReadOnlyCollection<string>>

Activity group mappings.

tenantContext ITenantContext

The 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.

userId string

The 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

string

The user identifier, or null if not available.

Methods

HasGrant(string)

Determines if the user has a grant for the specified activity.

public bool HasGrant(string activityName)

Parameters

activityName string

The name of the activity to check for a grant.

Returns

bool

true if 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

resourceType string

The type of the resource.

resourceId string

The identifier of the resource.

Returns

bool

true if 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

true if the user has a grant; otherwise, false .

Type Parameters

TActivity

The 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

resourceId string

The identifier of the resource.

Returns

bool

true if the user has a grant; otherwise, false .

Type Parameters

TResourceType

The 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

activityName string

The name of the activity to authorize.

resourceId string

The identifier of the resource, or null if not applicable.

Returns

bool

true if the user is authorized; otherwise, false .