Table of Contents

Class Grant

Namespace
Excalibur.A3.Authorization.Grants
Assembly
Excalibur.A3.Core.dll

Represents a user permission or access grant with a specific scope and expiration.

public sealed class Grant : AggregateRoot, IAggregateSnapshotSupport, IAggregateRoot<Grant, string>, IAggregateRoot<string>, IAggregateRoot
Inheritance
Grant
Implements
Inherited Members

Remarks

The Grant aggregate uses a composite key in the format "{UserId}:{Scope}" where Scope is "{TenantId}:{GrantType}:{Qualifier}".

This aggregate implements IAggregateRoot<TAggregate, TKey> to support static factory methods for repository integration with event-sourced repositories.

Constructors

Grant(string, string, GrantScope, DateTimeOffset?, string)

Initializes a new instance of the Grant class with a specified GrantScope.

public Grant(string userId, string fullName, GrantScope scope, DateTimeOffset? expiresOn, string grantedBy)

Parameters

userId string

The ID of the user to whom the grant is issued.

fullName string

The full name of the user.

scope GrantScope

The scope of the grant.

expiresOn DateTimeOffset?

The optional expiration date of the grant.

grantedBy string

The identifier of the entity or user who issued the grant.

Grant(string, string, string, string, string, DateTimeOffset?, string)

Initializes a new instance of the Grant class.

public Grant(string userId, string fullName, string tenantId, string grantType, string qualifier, DateTimeOffset? expiresOn, string grantedBy)

Parameters

userId string

The ID of the user to whom the grant is issued.

fullName string

The full name of the user.

tenantId string

The tenant ID associated with the grant.

grantType string

The type of grant issued.

qualifier string

Additional qualifier for the grant type.

expiresOn DateTimeOffset?

The optional expiration date of the grant.

grantedBy string

The identifier of the entity or user who issued the grant.

Grant(string, string, string, string, string, DateTimeOffset?, string, DateTimeOffset)

Initializes a new instance of the Grant class with additional information about the grant date.

public Grant(string userId, string fullName, string tenantId, string grantType, string qualifier, DateTimeOffset? expiresOn, string grantedBy, DateTimeOffset grantedOn)

Parameters

userId string

The ID of the user to whom the grant is issued.

fullName string

The full name of the user.

tenantId string

The tenant ID associated with the grant.

grantType string

The type of grant issued.

qualifier string

Additional qualifier for the grant type.

expiresOn DateTimeOffset?

The optional expiration date of the grant.

grantedBy string

The identifier of the entity or user who issued the grant.

grantedOn DateTimeOffset

The date and time when the grant was issued.

Properties

ExpiresOn

Gets the optional expiration date of the grant.

public DateTimeOffset? ExpiresOn { get; }

Property Value

DateTimeOffset?

The expiration date, or null if the grant does not expire.

FullName

Gets the full name of the user to whom the grant was issued.

public string? FullName { get; }

Property Value

string

The full name of the user, or null if not available.

GrantedBy

Gets the identifier of the entity or user who issued the grant.

public string? GrantedBy { get; }

Property Value

string

The identifier of the entity or user, or null if not available.

GrantedOn

Gets the date and time when the grant was issued.

public DateTimeOffset GrantedOn { get; }

Property Value

DateTimeOffset

The date and time when the grant was issued.

RevokedBy

Gets the identifier of the entity or user who revoked the grant.

public string? RevokedBy { get; }

Property Value

string

The identifier of the entity or user, or null if the grant has not been revoked.

RevokedOn

Gets the date and time when the grant was revoked.

public DateTimeOffset? RevokedOn { get; }

Property Value

DateTimeOffset?

The date and time when the grant was revoked, or null if not revoked.

Scope

Gets the scope of the grant.

public GrantScope? Scope { get; }

Property Value

GrantScope

The scope of the grant, or null if not available.

UserId

Gets the ID of the user to whom the grant was issued.

public string? UserId { get; }

Property Value

string

The ID of the user, or null if not available.

Methods

ApplyEventInternal(IDomainEvent)

Applies the event's changes to the aggregate's state using pattern matching.

protected override bool ApplyEventInternal(IDomainEvent @event)

Parameters

event IDomainEvent

The domain event to apply.

Returns

bool

true if the aggregate recognized and applied the event type; otherwise false. Returning false (a missing switch arm) causes the caller to throw UnhandledDomainEventException — an unrecognized event is refused, never silently ignored.

Remarks

Implement this method using a switch expression for optimal performance. The default arm returns false so an unhandled event fails loud:

protected override bool ApplyEventInternal(IDomainEvent @event) => @event switch
{
    OrderCreated e => Apply(e),
    OrderConfirmed e => Apply(e),
    _ => false
};

Each Apply overload returns true.

Create(string)

Creates a new Grant instance with the specified identifier.

public static Grant Create(string id)

Parameters

id string

The composite key in format "{UserId}:{Scope}".

Returns

Grant

A new Grant instance.

FromEvents(string, IEnumerable<HistoricEvent>)

Rebuilds a Grant from a stream of historical events.

public static Grant FromEvents(string id, IEnumerable<HistoricEvent> events)

Parameters

id string

The composite key in format "{UserId}:{Scope}".

events IEnumerable<HistoricEvent>

The stream of events to apply.

Returns

Grant

The Grant rebuilt from the events.

IsActive()

Determines whether the grant is currently active.

public bool IsActive()

Returns

bool

true if the grant is active; otherwise, false .

IsExpired()

Determines whether the grant has expired.

public bool IsExpired()

Returns

bool

true if the grant has expired; otherwise, false .

IsRevoked()

Determines whether the grant has been revoked.

public bool IsRevoked()

Returns

bool

true if the grant has been revoked; otherwise, false .

Revoke(string)

Revokes the grant.

public void Revoke(string revokedBy)

Parameters

revokedBy string

The identifier of the entity or user who revoked the grant.