SecurityUser
BasicSecurityUser will handle any type of data as a credential.
Synopsis
Section titled “Synopsis”class SecurityUser extends User implements ISecurityUser
| Extends | User |
| Implements | ISecurityUser |
| Since | 1.0.0 |
| Source | User/SecurityUser.php |
Constants
Section titled “Constants”| Constant | Value | Description |
|---|---|---|
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. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
addCredential(mixed $credential): void | Add a credential to this user. |
clearCredentials(): void | Clear all credentials associated with this user. |
getCredentials(): ?array<int, mixed> | Returns the list of credentials that this user possesses. |
getTokenClaims(): ?TokenClaims | The validated claims this identity was resolved from, when SecurityUser::isTokenDerived() is true. |
hasCredential(mixed $credential): bool | Indicates whether or not this user has a credential. |
hasCredentials(mixed $credentials): bool | Indicates whether or not this user has a credential or a set of credentials. |
initialize(Context $context, array<string, mixed> $parameters = []): void | Initialize this User. |
isAuthenticated(): bool | Indicates whether or not this user is authenticated. |
isTokenDerived(): bool | True when this user’s identity was (re-)established from a token rather than the session, per $tokenDerived. |
markTokenDerived(bool $tokenDerived = true): void | Mark (or clear) this user as token-derived, for this request only — the marker is not persisted (see $tokenDerived). |
removeCredential(mixed $credential): void | Remove a credential from this user. |
reset(): void | Clears the authentication state on top of the parent reset. |
restoreIdentityFromStorage(): void | Re-populate this user’s core identity attributes (see CORE_IDENTITY_KEYS) from storage. |
setAuthenticated(mixed $authenticated): void | Set the authenticated status of this user. |
setTokenClaims(?TokenClaims $claims): void | Set (or clear) the validated claims this identity was resolved from. |
shutdown(): void | Execute the shutdown procedure. |
addCredential()
Section titled “addCredential()”public function addCredential(mixed $credential): void
Add a credential to this user.
Credential data.
| Parameter | Type | Description |
|---|---|---|
$credential | mixed | Credential data. |
clearCredentials()
Section titled “clearCredentials()”public function clearCredentials(): void
Clear all credentials associated with this user.
getCredentials()
Section titled “getCredentials()”public function getCredentials(): ?array<int, mixed>
Returns the list of credentials that this user possesses.
Returns ?``array``<``int``, ``mixed``> — This user’s credentials.
getTokenClaims()
Section titled “getTokenClaims()”public function getTokenClaims(): ?TokenClaims
The validated claims this identity was resolved from, when SecurityUser::isTokenDerived() is true.
Returns ?TokenClaims
hasCredential()
Section titled “hasCredential()”public function hasCredential(mixed $credential): bool
Indicates whether or not this user has a credential.
Credential data.
| Parameter | Type | Description |
|---|---|---|
$credential | mixed | Credential data. |
Returns bool — True if this user has the credential, otherwise false.
hasCredentials()
Section titled “hasCredentials()”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.
| Parameter | Type | Description |
|---|---|---|
$credentials | mixed | 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. |
Returns bool — true, if this user has the credential, otherwise false.
initialize()
Section titled “initialize()”public function initialize(Context $context, array<string, mixed> $parameters = []): void
Initialize this User.
An associative array of initialization parameters.
| Parameter | Type | Description |
|---|---|---|
$context | Context | An Context instance. |
$parameters | array``<``string``, ``mixed``> | An associative array of initialization parameters. |
| Throws | When |
|---|---|
InitializationException | If an error occurs while initializing this User. |
isAuthenticated()
Section titled “isAuthenticated()”public function isAuthenticated(): bool
Indicates whether or not this user is authenticated.
Returns bool — true, if this user is authenticated, otherwise false.
isTokenDerived()
Section titled “isTokenDerived()”public function isTokenDerived(): bool
True when this user’s identity was (re-)established from a token rather than the session, per $tokenDerived.
Returns bool
markTokenDerived()
Section titled “markTokenDerived()”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.
| Parameter | Type | Description |
|---|---|---|
$tokenDerived | bool |
removeCredential()
Section titled “removeCredential()”public function removeCredential(mixed $credential): void
Remove a credential from this user.
Credential data.
| Parameter | Type | Description |
|---|---|---|
$credential | mixed | Credential data. |
reset()
Section titled “reset()”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.
restoreIdentityFromStorage()
Section titled “restoreIdentityFromStorage()”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.
setAuthenticated()
Section titled “setAuthenticated()”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.
| Parameter | Type | Description |
|---|---|---|
$authenticated | mixed | 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. |
setTokenClaims()
Section titled “setTokenClaims()”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.
| Parameter | Type | Description |
|---|---|---|
$claims | ?TokenClaims |
shutdown()
Section titled “shutdown()”public function shutdown(): void
Execute the shutdown procedure.
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
appendAttribute() | User | Appends a value to an array attribute and marks the user dirty. |
appendAttributeByRef() | User | Appends a value by reference to an array attribute and marks the user dirty. |
appendParameter() | ParameterHolder | Append a parameter. |
appendParameterByRef() | ParameterHolder | Append a parameter by reference. |
clearAttributes() | User | Removes every attribute in every namespace and marks the user dirty. |
clearParameters() | ParameterHolder | Clear all parameters associated with this request. |
getAttribute() | AttributeHolder | Retrieve an attribute. |
getAttributeNames() | AttributeHolder | Retrieve an array of attribute names. |
getAttributeNamespace() | AttributeHolder | Retrieve all attributes within a namespace. |
getAttributeNamespaces() | AttributeHolder | Retrieve an array of attribute namespaces. |
getAttributes() | AttributeHolder | Retrieve all attributes within a namespace. |
getContext() | User | Retrieve the current application context. |
getDefaultNamespace() | AttributeHolder | Get the default namespace name |
getFlatAttributeNames() | AttributeHolder | Retrieve an array of flattened attribute names. |
getFlatParameterNames() | ParameterHolder | Retrieve an array of flattened parameter names. |
getParameter() | ParameterHolder | Retrieve a parameter. |
getParameterNames() | ParameterHolder | Retrieve an array of parameter names. |
getParameters() | ParameterHolder | Retrieve an array of parameters. |
getStorageNamespace() | User | Retrieve the Storage namespace |
hasAttribute() | AttributeHolder | Indicates whether or not an attribute exists. |
hasAttributeNamespace() | AttributeHolder | Indicates whether or not an attribute namespace exists. |
hasParameter() | ParameterHolder | Indicates whether or not a parameter exists. |
isDirty() | User | Whether this request changed user state that still needs persisting. |
markClean() | User | Record that in-memory state now matches what is persisted. |
markDirty() | User | Force this user to be persisted at the request boundary. |
persistAttributesImmediate() | User | Immediately persist current user attributes (or a filtered subset) to storage. |
removeAttribute() | User | Removes a single attribute and marks the user dirty so the removal is persisted. |
removeAttributeNamespace() | User | Removes a whole attribute namespace and marks the user dirty. |
removeParameter() | ParameterHolder | Remove a parameter. |
restoreContext() | User | Re-bind context after unserialization without re-running full initialize logic. |
setAttribute() | User | Sets an attribute and marks the user dirty so shutdown() persists it. |
setAttributeByRef() | User | Sets an attribute by reference and marks the user dirty. |
setAttributes() | User | Merges a set of attributes into a namespace and marks the user dirty. |
setAttributesByRef() | User | Merges a set of attributes by reference into a namespace and marks the user dirty. |
setParameter() | ParameterHolder | Set a parameter. |
setParameterByRef() | ParameterHolder | Set a parameter by reference. |
setParameters() | ParameterHolder | Set an array of parameters. |
setParametersByRef() | ParameterHolder | Set an array of parameters by reference. |
startup() | User | Startup the user. |