AbstractUserAuthentication

abstract class \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication

Implements
LoggerAwareInterface
Uses
LoggerAwareTrait, CookieHeaderTrait

Authentication of users in TYPO3

This class is used to authenticate a login user. The class is used by both the frontend and backend. In both cases this class is a parent class to BackendUserAuthentication and FrontendUserAuthentication

Table of Contents

Interfaces

LoggerAwareInterface

Properties

$checkPid  : bool
If set, the user-record must be stored at the page defined by $checkPid_value
$checkPid_value  : int|string|null
The page id the user record must be stored at, can also hold a comma separated list of pids
$enablecolumns  : array
Enable field columns of user table
$loginType  : string
Login type, used for services.
$name  : string
Session/Cookie name
$uc  : array
User Settings (= preferences)
$user  : array|null
$user_table  : string
Table in database with user data
$usergroup_column  : string
Column for user group information
$usergroup_table  : string
Table in database with user groups
$userGroups  : array
This array will hold the groups that the user is a member of
$userid_column  : string
Column for user-id
$userident_column  : string
Column for password
$username_column  : string
Column for login-name
$writeAttemptLog  : bool
Log failed login attempts
$writeStdLog  : bool
Decides if the writelog() function is called at login and logout
$dontSetCookie  : bool
Will prevent the setting of the session cookie
$formfield_status  : string
Form field with status: *'login', 'logout'. If empty login is not verified.
$formfield_uident  : string
Form field with password
$formfield_uname  : string
Form field with login-name
$lastLogin_column  : string
Column name for last login timestamp
$loginSessionStarted  : bool
Will be set to TRUE if the login session is actually written during auth-check.
$setCookie  : SetCookieBehavior
If set, this cookie will be set to the response.
$userSession  : UserSession|null
$userSessionManager  : UserSessionManager

Methods

__construct()  : mixed
Initialize some important variables
appendCookieToResponse()  : ResponseInterface
Used to apply a cookie to a PSR-7 Response.
checkAuthentication()  : mixed
Checks if a submission of username and password is present or use other authentication by auth services
createAnonymousSession()  : void
Creates an anonymous user session.
createUserSession()  : UserSession
Creates a user session record and returns its values.
enforceNewSessionId()  : mixed
Regenerates the session ID and sets the cookie again.
getAuthInfoArray()  : array
Returns an info array which provides additional information for auth services
getCookieBehavior()  : SetCookieBehavior
The cookie behavior (send, remove or none) as evaluated during authentication, to be applied to the response by a middleware via SetCookieService::applyCookieToResponse().
getLoginFormData()  : array
Returns an info array with Login/Logout data submitted by a form or params
getModuleData()  : mixed
Gets module data for a module (from a loaded ->uc array)
getRawUserByUid()  : array
Fetching raw user record with uid=$uid
getSession()  : UserSession
getSessionData()  : mixed
Returns the session data stored for $key.
getUserId()  : int|null
getUserName()  : string|null
initializeFromPipeline()  : void
Initializes this user object from an authentication result established by the authentication pipeline, without running the authentication service chain. The session cookie behavior is evaluated the same way start() does.
initializeUserSessionManager()  : void
Currently needed for various unit tests, until start() and checkAuthentication() methods are smaller and extracted from this class.
isActiveLogin()  : bool
isMfaSetupRequired()  : bool
Whether the user is required to set up MFA
logoff()  : mixed
Log out current user! Removes the current session record, sets the internal ->user array to a blank string; Thereby the current user (if any) is effectively logged out!
processLoginData()  : array
Processes Login data submitted by a form or params
pushModuleData()  : void
Stores data for a module.
removeCookie()  : mixed
Empty / unset the cookie
setAndSaveSessionData()  : mixed
Sets the session data ($data) for $key and writes all session data (from ->user['ses_data']) to the database.
setBeUserByUid()  : mixed
Raw initialization of the be_user with uid=$uid This will circumvent all login procedures and select a be_users record from the database and set the content of ->user to the record selected.
setSessionData()  : mixed
Set session data by key.
start()  : mixed
Starts a user session Typical configurations will: a) check if session cookie was set and if not, set one, b) check if a password/username was sent and if so, try to authenticate the user c) Lookup a session attached to a user and check timeout etc.
writelog()  : mixed
DUMMY: Writes to log database table (in some extension classes)
writeUC()  : mixed
This writes $this->>uc to the user-record. This is a way of providing session-data.
evaluateMfaRequirements()  : void
This method checks if the user is authenticated but has not succeeded in passing his MFA challenge. This method can therefore only be used if a user has been authenticated against his first authentication method (username+password or any other authentication token).
fetchPossibleUsers()  : array
Loads users from various sources (= authentication services) as an array of arrays.
fetchValidUserFromSessionOrDestroySession()  : array|null
If the session is bound to a user, this method fetches the user record, and returns it.
getAuthServiceConfiguration()  : array
"auth" services configuration array from $GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']
getAuthServices()  : Traversable
Initializes authentication services to be used in a foreach loop
isCookieSet()  : bool
Returns whether this request is going to set a cookie or a cookie was already found in the system
isRefreshTimeBasedCookie()  : bool
Determine whether a non-session cookie needs to be set (lifetime>0)
isSetSessionCookie()  : bool
Determine whether a session cookie needs to be set (lifetime=0)
performLogoff()  : mixed
Perform the logoff action. Called from logoff() as a way to allow subclasses to override what happens when a user logs off, without needing to reproduce the hook calls and logging that happens in the public logoff() API method.
regenerateSessionId()  : mixed
Regenerate the session ID and transfer the session to new ID Call this method whenever a user proceeds to a higher authorization level e.g. when an anonymous session is now authenticated.
removeSensitiveLoginDataForLoggingInfo()  : mixed
Removes any sensitive data from the incoming data (either from loginData, processedLogin data or the user record from the DB).
setSessionCookie()  : mixed
Sets the setCookie directive to "Send", which will then result in appending a new cookie to the PSR-7 response, see appendCookieToResponse().
shallSetSessionCookie()  : bool
Determines whether setting the session cookie is generally enabled, or the current session is a non-session cookie (FE permalogin).
unpack_uc()  : mixed
Unserializes the user configuration from the user record into $this->>uc
updateLoginTimestamp()  : mixed
Updates the last login column in the user with the given id
userConstraints()  : QueryRestrictionContainerInterface
This returns the restrictions needed to select the user respecting enable columns and flags like deleted, hidden, starttime, endtime and rootLevel

Properties

$checkPid

If set, the user-record must be stored at the page defined by $checkPid_value

public bool $checkPid = true

$checkPid_value

The page id the user record must be stored at, can also hold a comma separated list of pids

public int|string|null $checkPid_value = 0

$enablecolumns

Enable field columns of user table

public array $enablecolumns = [ 'rootLevel' => '', // Boolean: If TRUE, 'AND pid=0…
Show the full value[ 'rootLevel' => '', // Boolean: If TRUE, 'AND pid=0' will be a part of the query... 'disabled' => '', 'starttime' => '', 'endtime' => '', 'deleted' => '', ]

$loginType

Login type, used for services.

public string $loginType = ''

$name

Session/Cookie name

public string $name = ''

$uc

User Settings (= preferences)

public array $uc = []

$user

public array|null $user

contains user- AND session-data from database (joined tables)

$user_table

Table in database with user data

public string $user_table = ''

$usergroup_column

Column for user group information

public string $usergroup_column = ''

$usergroup_table

Table in database with user groups

public string $usergroup_table = ''

$userGroups

This array will hold the groups that the user is a member of

public array $userGroups = []

$userid_column

Column for user-id

public string $userid_column = ''

$userident_column

Column for password

public string $userident_column = ''

$username_column

Column for login-name

public string $username_column = ''

$writeAttemptLog

Log failed login attempts

public bool $writeAttemptLog = false

$writeStdLog

Decides if the writelog() function is called at login and logout

public bool $writeStdLog = false

$dontSetCookie

Will prevent the setting of the session cookie

protected bool $dontSetCookie = false

$formfield_status

Form field with status: *'login', 'logout'. If empty login is not verified.

protected string $formfield_status = ''

$formfield_uident

Form field with password

protected string $formfield_uident = ''

$formfield_uname

Form field with login-name

protected string $formfield_uname = ''

$lastLogin_column

Column name for last login timestamp

protected string $lastLogin_column = ''

$loginSessionStarted

Will be set to TRUE if the login session is actually written during auth-check.

protected bool $loginSessionStarted = false

$setCookie

If set, this cookie will be set to the response.

protected SetCookieBehavior $setCookie = \TYPO3\CMS\Core\Http\SetCookieBehavior::None

Methods

__construct()

Initialize some important variables

public __construct() : mixed

Tags

throws
Exception

appendCookieToResponse()

Used to apply a cookie to a PSR-7 Response.

public appendCookieToResponse(ResponseInterface $response, NormalizedParams $normalizedParams) : ResponseInterface

Parameters

$response : ResponseInterface
$normalizedParams : NormalizedParams

Return values

ResponseInterface

createAnonymousSession()

Creates an anonymous user session.

public createAnonymousSession() : void

This method should be avoided, as it is only a workaround due to the ugly setup of this class and the authentication / logout behavior.

createUserSession()

Creates a user session record and returns its values.

public createUserSession(array $userRecordCandidate) : UserSession

Parameters

$userRecordCandidate : array

User data array

Return values

UserSession —

The session data for the newly created session.

enforceNewSessionId()

Regenerates the session ID and sets the cookie again.

public enforceNewSessionId() : mixed

getAuthInfoArray()

Returns an info array which provides additional information for auth services

public getAuthInfoArray(ServerRequestInterface $request) : array

Parameters

$request : ServerRequestInterface

Return values

array

getCookieBehavior()

The cookie behavior (send, remove or none) as evaluated during authentication, to be applied to the response by a middleware via SetCookieService::applyCookieToResponse().

public getCookieBehavior() : SetCookieBehavior

Return values

SetCookieBehavior

getLoginFormData()

Returns an info array with Login/Logout data submitted by a form or params

public getLoginFormData(ServerRequestInterface $request) : array

Parameters

$request : ServerRequestInterface

Return values

array

getModuleData()

Gets module data for a module (from a loaded ->uc array)

public getModuleData(string $module[, string $type = '' ]) : mixed

Parameters

$module : string

Is the identifier of the module, e.g. "content_status"

$type : string = ''

If $type = 'ses' then module data is returned only if it was stored in the current session, otherwise data from a previous session will be returned (if available).

Return values

mixed —

The module data if available: $this->uc['moduleData'][$module];

getRawUserByUid()

Fetching raw user record with uid=$uid

public getRawUserByUid(int $uid) : array

Parameters

$uid : int

The UID of the backend user to set in ->user

Return values

array —

user record or FALSE

getSessionData()

Returns the session data stored for $key.

public getSessionData(string $key) : mixed

The data will last only for this login session since it is stored in the user session.

Parameters

$key : string

The key associated with the session data

getUserId()

public getUserId() : int|null

Return values

int|null

getUserName()

public getUserName() : string|null

Return values

string|null

initializeFromPipeline()

Initializes this user object from an authentication result established by the authentication pipeline, without running the authentication service chain. The session cookie behavior is evaluated the same way start() does.

public initializeFromPipeline(UserSession $userSession, array|null $userRecord[, bool $activeLogin = false ]) : void

Parameters

$userSession : UserSession
$userRecord : array|null
$activeLogin : bool = false

initializeUserSessionManager()

Currently needed for various unit tests, until start() and checkAuthentication() methods are smaller and extracted from this class.

public initializeUserSessionManager([UserSessionManager|null $userSessionManager = null ]) : void

Parameters

$userSessionManager : UserSessionManager|null = null

isActiveLogin()

public isActiveLogin(ServerRequestInterface $request) : bool

Parameters

$request : ServerRequestInterface

Return values

bool

isMfaSetupRequired()

Whether the user is required to set up MFA

public isMfaSetupRequired() : bool

Return values

bool

logoff()

Log out current user! Removes the current session record, sets the internal ->user array to a blank string; Thereby the current user (if any) is effectively logged out!

public logoff() : mixed

processLoginData()

Processes Login data submitted by a form or params

public processLoginData(array $loginData, ServerRequestInterface $request) : array

Parameters

$loginData : array

Login data array

$request : ServerRequestInterface

Return values

array

pushModuleData()

Stores data for a module.

public pushModuleData(string $module, mixed $data[, bool $dontPersistImmediately = false ]) : void

The data is stored with the session ID, so you can even check upon retrieval if the module data is from a previous session or from the current session.

Parameters

$module : string

Is the identifier of the module, e.g. "content_status"

$data : mixed

Is the data you want to store for that module (array, string, ...)

$dontPersistImmediately : bool = false

If set, then the ->uc array (which carries all kinds of user data) is NOT written immediately, but must be written by some subsequent call.

removeCookie()

Empty / unset the cookie

public removeCookie([string|null $cookieName = null ]) : mixed

Parameters

$cookieName : string|null = null

usually, this is $this->name

setAndSaveSessionData()

Sets the session data ($data) for $key and writes all session data (from ->user['ses_data']) to the database.

public setAndSaveSessionData(string $key, mixed $data) : mixed

The data will last only for this login session since it is stored in the session table.

Parameters

$key : string

Pointer to an associative key in the session data array which is stored serialized in the field "ses_data" of the session table.

$data : mixed

The data to store in index $key

setBeUserByUid()

Raw initialization of the be_user with uid=$uid This will circumvent all login procedures and select a be_users record from the database and set the content of ->user to the record selected.

public setBeUserByUid(int $uid) : mixed

Thus the BE_USER object will appear like if a user was authenticated - however without a session id and the fields from the session table of course. Will check the users for disabled, start/endtime, etc. ($this->user_where_clause())

Parameters

$uid : int

The UID of the backend user to set in ->user

setSessionData()

Set session data by key.

public setSessionData(string $key, mixed $data) : mixed

The data will last only for this login session since it is stored in the user session.

Parameters

$key : string

A non empty string to store the data under

$data : mixed

Data store store in session

start()

Starts a user session Typical configurations will: a) check if session cookie was set and if not, set one, b) check if a password/username was sent and if so, try to authenticate the user c) Lookup a session attached to a user and check timeout etc.

public start(ServerRequestInterface $request) : mixed

d) Garbage collection, setting of no-cache headers. If a user is authenticated the database record of the user (array) will be set in the ->user internal variable.

Parameters

$request : ServerRequestInterface

writelog()

DUMMY: Writes to log database table (in some extension classes)

public writelog(int $type, int $action, int $error, null $_, string $details, array $data, string $tablename, int|string $recuid) : mixed

Parameters

$type : int

denotes which module that has submitted the entry. This is the current list: 1=tce_db; 2=tce_file; 3=system (eg. sys_history save); 4=modules; 254=Personal settings changed; 255=login / out action: 1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent

$action : int

denotes which specific operation that wrote the entry (eg. 'delete', 'upload', 'update' and so on...). Specific for each $type. Also used to trigger update of the interface. (see the log-module for the meaning of each number !!)

$error : int

flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)

$_ : null

unused

$details : string

Default text that follows the message

$data : array

Data that follows the log. Might be used to carry special information. If an array the first 5 entries (0-4) will be sprintf'ed the details-text...

$tablename : string

Special field used by tce_main.php. These ($tablename, $recuid) hold the reference to the record which the log-entry is about.

$recuid : int|string

Special field used by tce_main.php. These ($tablename, $recuid) hold the reference to the record which the log-entry is about.

writeUC()

This writes $this->>uc to the user-record. This is a way of providing session-data.

public writeUC() : mixed

You can fetch the data again through $this->uc in this class!

evaluateMfaRequirements()

This method checks if the user is authenticated but has not succeeded in passing his MFA challenge. This method can therefore only be used if a user has been authenticated against his first authentication method (username+password or any other authentication token).

protected evaluateMfaRequirements() : void

Tags

throws
MfaRequiredException

fetchPossibleUsers()

Loads users from various sources (= authentication services) as an array of arrays.

protected fetchPossibleUsers(array $loginData, bool $activeLogin, bool $isExistingSession, array|null $authenticatedUserFromSession, ServerRequestInterface $request) : array

Parameters

$loginData : array
$activeLogin : bool
$isExistingSession : bool
$authenticatedUserFromSession : array|null

if we have a user from an existing session, this is set here, otherwise null

$request : ServerRequestInterface

Return values

array

fetchValidUserFromSessionOrDestroySession()

If the session is bound to a user, this method fetches the user record, and returns it.

protected fetchValidUserFromSessionOrDestroySession([bool $skipSessionUpdate = false ]) : array|null

If the session has a timeout, the session date is extended if needed. Also the ìs_online flag is updated for the user.

However, if the session has expired the session is removed and the request is treated as an anonymous session.

Parameters

$skipSessionUpdate : bool = false

Return values

array|null

getAuthServiceConfiguration()

"auth" services configuration array from $GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']

protected getAuthServiceConfiguration() : array

Return values

array

getAuthServices()

Initializes authentication services to be used in a foreach loop

protected getAuthServices(string $subType, array $loginData, array|null $authenticatedUserFromSession, ServerRequestInterface $request) : Traversable

Parameters

$subType : string

e.g. getUserFE

$loginData : array
$authenticatedUserFromSession : array|null

the user which was loaded from the session, or null if none was found

$request : ServerRequestInterface

Return values

Traversable —

A generator of service objects

isCookieSet()

Returns whether this request is going to set a cookie or a cookie was already found in the system

protected isCookieSet() : bool

Return values

bool —

Returns TRUE if a cookie is set

isRefreshTimeBasedCookie()

Determine whether a non-session cookie needs to be set (lifetime>0)

protected isRefreshTimeBasedCookie() : bool

Return values

bool

isSetSessionCookie()

Determine whether a session cookie needs to be set (lifetime=0)

protected isSetSessionCookie() : bool

Return values

bool

performLogoff()

Perform the logoff action. Called from logoff() as a way to allow subclasses to override what happens when a user logs off, without needing to reproduce the hook calls and logging that happens in the public logoff() API method.

protected performLogoff() : mixed

regenerateSessionId()

Regenerate the session ID and transfer the session to new ID Call this method whenever a user proceeds to a higher authorization level e.g. when an anonymous session is now authenticated.

protected regenerateSessionId() : mixed

removeSensitiveLoginDataForLoggingInfo()

Removes any sensitive data from the incoming data (either from loginData, processedLogin data or the user record from the DB).

protected removeSensitiveLoginDataForLoggingInfo(mixed|array $data[, bool $isUserRecord = false ]) : mixed

No type hinting is added because it might be possible that the incoming data is of any other type.

Parameters

$data : mixed|array
$isUserRecord : bool = false

setSessionCookie()

Sets the setCookie directive to "Send", which will then result in appending a new cookie to the PSR-7 response, see appendCookieToResponse().

protected setSessionCookie() : mixed

In case this method is called, the cookie needs to be set later.

shallSetSessionCookie()

Determines whether setting the session cookie is generally enabled, or the current session is a non-session cookie (FE permalogin).

protected shallSetSessionCookie() : bool

Return values

bool

unpack_uc()

Unserializes the user configuration from the user record into $this->>uc

protected unpack_uc() : mixed

updateLoginTimestamp()

Updates the last login column in the user with the given id

protected updateLoginTimestamp(int $userId) : mixed

Parameters

$userId : int
On this page