Skip to content

SecurityUser

BasicSecurityUser will handle any type of data as a credential.

class SecurityUser extends User implements ISecurityUser

ExtendsUser
ImplementsISecurityUser
Since1.0.0
SourceUser/SecurityUser.php
ConstantValueDescription
AUTH_NAMESPACE'org.quiote.user.BasicSecurityUser.authenticated'The namespace under which authenticated status will be stored.
CREDENTIAL_NAMESPACE'org.quiote.user.BasicSecurityUser.credentials'The namespace under which credentials will be stored.
MethodDescription
addCredential(mixed $credential): voidAdd a credential to this user.
clearCredentials(): voidClear all credentials associated with this user.
getCredentials(): ?array<int, mixed>Returns the list of credentials that this user possesses.
getTokenClaims(): ?TokenClaimsThe validated claims this identity was resolved from, when SecurityUser::isTokenDerived() is true.
hasCredential(mixed $credential): boolIndicates whether or not this user has a credential.
hasCredentials(mixed $credentials): boolIndicates whether or not this user has a credential or a set of credentials.
initialize(Context $context, array<string, mixed> $parameters = []): voidInitialize this User.
isAuthenticated(): boolIndicates whether or not this user is authenticated.
isTokenDerived(): boolTrue when this user’s identity was (re-)established from a token rather than the session, per $tokenDerived.
markTokenDerived(bool $tokenDerived = true): voidMark (or clear) this user as token-derived, for this request only — the marker is not persisted (see $tokenDerived).
removeCredential(mixed $credential): voidRemove a credential from this user.
reset(): voidClears the authentication state on top of the parent reset.
restoreIdentityFromStorage(): voidRe-populate this user’s core identity attributes (see CORE_IDENTITY_KEYS) from storage.
setAuthenticated(mixed $authenticated): voidSet the authenticated status of this user.
setTokenClaims(?TokenClaims $claims): voidSet (or clear) the validated claims this identity was resolved from.
shutdown(): voidExecute the shutdown procedure.

public function addCredential(mixed $credential): void

Add a credential to this user.

Credential data.

ParameterTypeDescription
$credentialmixedCredential data.

public function clearCredentials(): void

Clear all credentials associated with this user.

public function getCredentials(): ?array<int, mixed>

Returns the list of credentials that this user possesses.

Returns ?``array``<``int``, ``mixed``> — This user’s credentials.

public function getTokenClaims(): ?TokenClaims

The validated claims this identity was resolved from, when SecurityUser::isTokenDerived() is true.

Returns ?TokenClaims

public function hasCredential(mixed $credential): bool

Indicates whether or not this user has a credential.

Credential data.

ParameterTypeDescription
$credentialmixedCredential data.

Returns bool — True if this user has the credential, otherwise false.

public function hasCredentials(mixed $credentials): bool

Indicates whether or not this user has a credential or a set of credentials.

Credential data. Either a string or an array of credentials which are all required. If these individual credentials are again an array of credentials, one or more of these sub-credentials will be required.

ParameterTypeDescription
$credentialsmixedCredential data. Either a string or an array of credentials which are all required. If these individual credentials are again an array of credentials, one or more of these sub-credentials will be required.

Returns bool — true, if this user has the credential, otherwise false.

public function initialize(Context $context, array<string, mixed> $parameters = []): void

Initialize this User.

An associative array of initialization parameters.

ParameterTypeDescription
$contextContextAn Context instance.
$parametersarray``<``string``, ``mixed``>An associative array of initialization parameters.
ThrowsWhen
InitializationExceptionIf an error occurs while initializing this User.

public function isAuthenticated(): bool

Indicates whether or not this user is authenticated.

Returns bool — true, if this user is authenticated, otherwise false.

public function isTokenDerived(): bool

True when this user’s identity was (re-)established from a token rather than the session, per $tokenDerived.

Returns bool

public function markTokenDerived(bool $tokenDerived = true): void

Mark (or clear) this user as token-derived, for this request only — the marker is not persisted (see $tokenDerived).

Called by a token authenticator (e.g. BearerTokenAuthenticator) once it has resolved and granted the credentials for this request.

Clearing it is how an endpoint that deliberately turns a token into a browser session (an SPA’s session-establishing call) opts the identity back into session persistence: call markTokenDerived(false) before granting roles and authenticating, and the login is written out like any form login’s.

ParameterTypeDescription
$tokenDerivedbool

public function removeCredential(mixed $credential): void

Remove a credential from this user.

Credential data.

ParameterTypeDescription
$credentialmixedCredential data.

public function reset(): void

Clears the authentication state on top of the parent reset.

Forgets whether the user was authenticated, its credentials and credential index, and any claims derived from a stateless token, then delegates to the parent for the attribute and context state. Called between requests in a long-running worker so no identity survives into the next one.

public function restoreIdentityFromStorage(): void

Re-populate this user’s core identity attributes (see CORE_IDENTITY_KEYS) from storage.

Framework code does not call this automatically; it exists so a worker cold start (a fresh FrankenPHP worker recreating this object from scratch) can restore identity-critical attributes before a token authenticator repopulates the request-scoped identity, without every subclass re-implementing the same storage read.

public function setAuthenticated(mixed $authenticated): void

Set the authenticated status of this user.

A flag indicating the authenticated status of this user. Intentionally compared with === true below rather than typed bool: truthy-but-non-bool values (e.g. 1) must be rejected, not coerced.

ParameterTypeDescription
$authenticatedmixedA flag indicating the authenticated status of this user. Intentionally compared with === true below rather than typed bool: truthy-but-non-bool values (e.g. 1) must be rejected, not coerced.

public function setTokenClaims(?TokenClaims $claims): void

Set (or clear) the validated claims this identity was resolved from.

Called by AuthenticationManager::apply() alongside SecurityUser::markTokenDerived() once a token authenticator has produced a successful passport.

ParameterTypeDescription
$claims?TokenClaims

public function shutdown(): void

Execute the shutdown procedure.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendAttribute()UserAppends a value to an array attribute and marks the user dirty.
appendAttributeByRef()UserAppends a value by reference to an array attribute and marks the user dirty.
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearAttributes()UserRemoves every attribute in every namespace and marks the user dirty.
clearParameters()ParameterHolderClear all parameters associated with this request.
getAttribute()AttributeHolderRetrieve an attribute.
getAttributeNames()AttributeHolderRetrieve an array of attribute names.
getAttributeNamespace()AttributeHolderRetrieve all attributes within a namespace.
getAttributeNamespaces()AttributeHolderRetrieve an array of attribute namespaces.
getAttributes()AttributeHolderRetrieve all attributes within a namespace.
getContext()UserRetrieve the current application context.
getDefaultNamespace()AttributeHolderGet the default namespace name
getFlatAttributeNames()AttributeHolderRetrieve an array of flattened attribute names.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
getStorageNamespace()UserRetrieve the Storage namespace
hasAttribute()AttributeHolderIndicates whether or not an attribute exists.
hasAttributeNamespace()AttributeHolderIndicates whether or not an attribute namespace exists.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
isDirty()UserWhether this request changed user state that still needs persisting.
markClean()UserRecord that in-memory state now matches what is persisted.
markDirty()UserForce this user to be persisted at the request boundary.
persistAttributesImmediate()UserImmediately persist current user attributes (or a filtered subset) to storage.
removeAttribute()UserRemoves a single attribute and marks the user dirty so the removal is persisted.
removeAttributeNamespace()UserRemoves a whole attribute namespace and marks the user dirty.
removeParameter()ParameterHolderRemove a parameter.
restoreContext()UserRe-bind context after unserialization without re-running full initialize logic.
setAttribute()UserSets an attribute and marks the user dirty so shutdown() persists it.
setAttributeByRef()UserSets an attribute by reference and marks the user dirty.
setAttributes()UserMerges a set of attributes into a namespace and marks the user dirty.
setAttributesByRef()UserMerges a set of attributes by reference into a namespace and marks the user dirty.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.
startup()UserStartup the user.