Class UserCredentialAdministration
- Namespace
- MailFathom.Application.Access.Credentials
- Assembly
- MailFathom.Application.dll
What an administrator does to the credentials one user is admitted by.
public sealed class UserCredentialAdministration
- Inheritance
-
UserCredentialAdministration
- Inherited Members
Remarks
Every act here names the user it is for, and that is the whole of what the user story asks: credentials are provisioned by whoever administers the deployment rather than by whoever holds one, so a user cannot mint a credential for another user because a user cannot mint one at all. The administrative principal acts for nobody's mail — RequireUser() refuses it — so the user is stated in the request and checked against the records this deployment holds instead of being carried on the principal.
One type for all four methods, because provisioning differs only in what is drawn or read before the row is written and every rule after that point is one rule: which user, which grant, which ceiling, and what is written down afterwards. A method with an administration of its own would be a second place for each of those to be decided.
Reading and writing are separately granted, because they are separately dangerous: a listing says which credentials exist and whose they are, which is AdminRead, while creating, rotating, disabling, and deleting one decides who can read a person's mail, which is AdminCredentialsWrite — the same grant that already bounds placing a mailbox user's long-lived credential, and for the same reason.
Plaintext reaches this type as a span and leaves it as a record. It is read once, inside the synchronous call that hashes it, and nothing awaited afterwards has it, so nothing this type holds outlives the call that was handed the span. What it does not do is erase the buffer behind that span, and neither boundary that supplies one can: a password arrives at the HTTP boundary as a deserialized string and at the terminal boundary as one too, and a string cannot be wiped. The bound worth stating is therefore the reading rather than the memory — the plaintext is read inside one synchronous call and is never copied, retained, awaited over, or written down here. Nothing here logs it, returns it, or puts it in a refusal — a password this deployment refused is described by the rule it broke and never by what was written. A minted key is the one value that travels back out, because it has to reach whoever asked for it and exists nowhere else once it has.
The policy and the grant are checked here as well as at the boundary, which is the second enforcement the layering rule asks for. Reaching either is a defect in an entrypoint rather than an operator's mistake, so both raise rather than answering: a boundary that means to report the rule calls FindRefusal(ReadOnlySpan<char>) or FindGrantRefusal(IReadOnlyList<MailFathomPermission>?) and answers with the sentence, and one that did not check has found a way in that this type has to close rather than describe.
Constructors
- UserCredentialAdministration(AccessAuthorization, IUserCredentialStore, IPasswordHasher, IUserApiKeyMinter, IClientPublicKeyReader, IUserCredentialAuditor, UserGrantResolver, TimeProvider)
Initializes the administration over one deployment's credential records.
Methods
- DeleteAsync(UserId, Guid, CancellationToken)
Removes one credential and frees the lookup it held.
- FindGrantRefusal(IReadOnlyList<MailFathomPermission>?)
Reports why a written narrowing cannot be kept by a user-facing credential, or that it can.
- ProvisionApiKeyAsync(UserId, IReadOnlyList<MailFathomPermission>?, UserCredentialReach, CancellationToken)
Draws a key one of a user's clients presents, and provisions the credential it resolves.
- ProvisionOAuthSubjectAsync(UserId, string?, string?, IReadOnlyList<MailFathomPermission>?, UserCredentialReach, CancellationToken)
Maps one authorization server's subject onto the user it stands for.
- ProvisionPasswordAsync(UserId, UserCredentialUsername, ReadOnlyMemory<char>, IReadOnlyList<MailFathomPermission>?, UserCredentialReach, CancellationToken)
Provisions a username and password a user signs in with.
- ProvisionPublicKeyAsync(UserId, string?, IReadOnlyList<MailFathomPermission>?, UserCredentialReach, CancellationToken)
Registers a public key whose signed assertions authenticate one user.
- ReadCredentialsAsync(UserId, CancellationToken)
Reads the credentials one user holds, of every method, beside what the user currently holds.
- ReplacePublicKeyAsync(UserId, Guid, string?, CancellationToken)
Replaces the public key one credential verifies assertions against.
- RotateApiKeyAsync(UserId, Guid, CancellationToken)
Draws a new key for one credential, which stops the previous one working at that instant.
- RotatePasswordAsync(UserId, Guid, UserCredentialUsername, ReadOnlyMemory<char>, CancellationToken)
Replaces one credential's password, which stops the previous one working at that instant.
- SetEnabledAsync(UserId, Guid, bool, CancellationToken)
Turns one credential on or off while it keeps what it is presented as.