DmAccessContext
Namespace: MJCZone.DapperMatic.Security
Assembly: MJCZone.DapperMatic
Summary
Who a request is, and for which tenant: what policies decide on and what their filters, checks and presets read as <c>@user.id</c>, <c>@claims.role</c>, <c>@tenant.id</c>, <c>@tenant.below</c> or <c>@values.region</c>.
sealed public
Contents
Constructors (1) | Methods (7) | Properties (7) | Fields (2)
Constructors
DmAccessContext
Initializes a new instance of the DmAccessContext class.
DmAccessContext(ClaimsPrincipal user, IServiceProvider services)Parameters
- user (ClaimsPrincipal) - The caller, or null for an anonymous one.
- services (IServiceProvider) - The services values may use, or null.
Methods
| Method | Summary |
|---|---|
| ForDatasource | Gets the context for reading values in a datasource: the same caller, tenant and values, computed on... |
| IsInRole | Tells whether the caller has a role: <c>anonymous</c> and <c>authenticated</c&g... |
| GetValueAsync | Reads a value by its path: <c>tenant.id</c>, <c>tenant.datasource</c>, <c... |
| GetType | |
| ToString | |
| Equals | |
| GetHashCode |
ForDatasource
Gets the context for reading values in a datasource: the same caller, tenant and values, computed once for that datasource. A value read with SQL reads it from the datasource it is read for, unless it names one of its own.
DmAccessContext ForDatasource(string datasourceId)Parameters
- datasourceId (string) - The datasource, or null for none.
Returns
Type: DmAccessContext
The context.
IsInRole
Tells whether the caller has a role: <c>anonymous</c> and <c>authenticated</c> as their names say, any other as the caller's role claims say.
bool IsInRole(string role)Parameters
- role (string) - The role.
Returns
Type: bool
True if the caller has it.
GetValueAsync
Reads a value by its path: <c>tenant.id</c>, <c>tenant.datasource</c>, <c>tenant.schema</c>, <c>tenant.name</c> (a value of the tenant's); <c>user.id</c> (the name identifier or <c>sub</c> claim), <c>user.name</c>; <c>claims.type</c> (the claim's value, or a list when the caller has several); <c>values.name</c>.
ValueTask<object?> GetValueAsync(
string path,
CancellationToken cancellationToken)Parameters
- path (string) - .
- cancellationToken (CancellationToken) - The cancellation token.
Returns
Type: ValueTask<object?>
The value, or null when there is none.
GetType
GetType()ToString
ToString()Equals
Equals()GetHashCode
GetHashCode()Properties
User
Gets the caller.
Type: ClaimsPrincipal
Services
Gets the services values may use, or null.
Type: IServiceProvider?
IsAuthenticated
Gets a value indicating whether the caller is signed in.
Type: bool?
Tenant
Gets the tenant the caller acts for, or null for none.
Type: DmTenant?
Limits
Gets the most the caller may do, whatever their policies allow, or null for no limits: an API key's. These are policies of no roles; what the caller may do is what both their policies and these allow (see DmAction)).
Type: IReadOnlyList<DmPolicy>?
DatasourceId
Gets the datasource the context's values are read for (see String)), or null for none.
Type: string?
Values
Gets named values for policies, read as <c>@values.name</c>. A value may be a DmValueProvider, computed once when first read.
Type: Dictionary<string, object?>
Fields
AnonymousRole
The role every caller who is not signed in has.
Type: object
AuthenticatedRole
The role every signed-in caller has.
Type: object