VuFind API Documentation

Database extends AbstractBase
in package

Database authentication class

Tags
category

VuFind

author

Chris Hallberg challber@villanova.edu

author

Franck Borel franck.borel@gbv.de

author

Demian Katz demian.katz@villanova.edu

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Wiki

Table of Contents

$config  : Config
Configuration settings
$configValidated  : bool
Has the configuration been validated?
$dbServiceManager  : PluginManager
Database service plugin manager
$password  : string
Password
$translator  : TranslatorInterface
Translator
$username  : string
Username
$userSetterMap  : mixed
Map of database column name to setter method for UserEntityInterface objects.
authenticate()  : UserEntityInterface
Attempt to authenticate the current user. Throws exception if login fails.
create()  : UserEntityInterface
Create a new user account from the request.
getConfig()  : Config
Get configuration (load automatically if not previously set). Throw an exception if the configuration is invalid.
getDbService()  : T
Get a database service object.
getDbServiceManager()  : PluginManager
Get the service plugin manager. Throw an exception if it is missing.
getDelegateAuthMethod()  : string|bool
Returns any authentication method this request should be delegated to.
getPasswordPolicy()  : array<string|int, mixed>
Password policy for a new password (e.g. minLength, maxLength)
getPolicyConfig()  : array<string|int, mixed>
Get a policy configuration
getSessionInitiator()  : bool|string
Get the URL to establish a session (needed when the internal VuFind login form is inadequate). Returns false when no session initiator is needed.
getTranslator()  : TranslatorInterface
Get translator object.
getTranslatorLocale()  : string
Get the locale from the translator.
getUsernamePolicy()  : array<string|int, mixed>
Username policy for a new account (e.g. minLength, maxLength)
getUserService()  : UserServiceInterface
Get access to the user table.
isExpired()  : bool
Has the user's login expired?
logout()  : string
Perform cleanup at logout time.
needsCsrfCheck()  : bool
Whether this authentication method needs CSRF checking for the request.
preLoginCheck()  : void
Inspect the user's request prior to processing a login request; this is essentially an event hook which most auth modules can ignore. See ChoiceAuth for a use case example.
resetState()  : void
Reset any internal status; this is essentially an event hook which most auth modules can ignore. See ChoiceAuth for a use case example.
setConfig()  : void
Set configuration.
setDbServiceManager()  : void
Set the service plugin manager.
setTranslator()  : TranslatorAwareInterface
Set a translator
supportsConnectingLibraryCard()  : bool
Does this authentication method support connecting library card of currently authenticated user?
supportsCreation()  : bool
Does this authentication method support account creation?
supportsPasswordChange()  : bool
Does this authentication method support password changing
supportsPasswordRecovery()  : bool
Does this authentication method support password recovery
translate()  : string
Translate a string (or string-castable object)
translateWithPrefix()  : string
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
updatePassword()  : UserEntityInterface
Update a user's password from the request.
validateCredentials()  : bool
Validate the credentials in the provided request, but do not change the state of the current logged-in user. Return true for valid credentials, false otherwise.
checkEmailVerified()  : void
Check if the user's email address has been verified (if necessary) and throws exception if not.
checkPassword()  : bool
Check that the user's password matches the provided value.
collectParamsFromRequest()  : array<string|int, string>
Collect parameters from request and populate them.
createUserFromParams()  : UserEntityInterface
Create a user entity object from given parameters.
debug()  : void
Log a debug message.
emailAllowed()  : bool
Check that an email address is legal based on inclusion list (if configured).
exceptionIndicatesDuplicateKey()  : bool
Does the provided exception indicate that a duplicate key value has been created?
extractTextDomain()  : array<string|int, mixed>
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
getCannedPolicyHint()  : string|null
Return a canned username or password policy hint when available
getDebugTranslation()  : string
Build a debug-mode translation
getOrCreateUserByUsername()  : UserEntityInterface
Look up a user by username; create a new entity if no match is found.
log()  : void
Send a message to the logger.
logError()  : void
Log an error message.
logWarning()  : void
Log a warning message.
passwordHashingEnabled()  : bool
Is password hashing enabled?
sanitizeTranslationKey()  : string
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
setUserPassword()  : void
Set the password in a UserEntityInterface object.
setUserValueByField()  : void
Set a value in a UserEntityObject using a field name.
translateString()  : string
Get translation for a string
validateConfig()  : void
Validate configuration parameters. This is a support method for getConfig(), so the configuration MUST be accessed using $this->config; do not call $this->getConfig() from within this method!
validateParams()  : void
Validate parameters.
validatePassword()  : void
Make sure password isn't blank, matches the policy and passwords match.
validatePasswordAgainstPolicy()  : void
Verify that a password fulfills the password policy. Throws exception if the password is invalid.
validateStringAgainstPolicy()  : void
Verify that a username or password fulfills the given policy. Throws exception if the string is invalid.
validateUsername()  : void
Make sure username isn't blank and matches the policy.
validateUsernameAgainstPolicy()  : void
Verify that a username fulfills the username policy. Throws exception if the username is invalid.

Properties

$config

Configuration settings

protected Config $config = null

$configValidated

Has the configuration been validated?

protected bool $configValidated = false

$password

Password

protected string $password

$username

Username

protected string $username

$userSetterMap

Map of database column name to setter method for UserEntityInterface objects.

protected mixed $userSetterMap = ['cat_username' => 'setCatUsername', 'college' => 'setCollege', 'email' => 'setEmail', 'firstname' => 'setFirstname', 'lastname' => 'setLastname', 'home_library' => 'setHomeLibrary', 'major' => 'setMajor']

Methods

authenticate()

Attempt to authenticate the current user. Throws exception if login fails.

public authenticate(Request $request) : UserEntityInterface
Parameters
$request : Request

Request object containing account credentials.

Tags
throws
Auth
Return values
UserEntityInterface

Object representing logged-in user.

create()

Create a new user account from the request.

public create(Request $request) : UserEntityInterface
Parameters
$request : Request

Request object containing new account details.

Tags
throws
Auth
Return values
UserEntityInterface

New user entity.

getConfig()

Get configuration (load automatically if not previously set). Throw an exception if the configuration is invalid.

public getConfig() : Config
Tags
throws
Auth
Return values
Config

getDbService()

Get a database service object.

public getDbService(class-string<\VuFind\Db\Service\T> $name) : T
Parameters
$name : class-string<\VuFind\Db\Service\T>

Name of service to retrieve

Tags
template

T

Return values
T

getDelegateAuthMethod()

Returns any authentication method this request should be delegated to.

public getDelegateAuthMethod(Request $request) : string|bool
Parameters
$request : Request

Request object.

Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
string|bool

getPasswordPolicy()

Password policy for a new password (e.g. minLength, maxLength)

public getPasswordPolicy() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPolicyConfig()

Get a policy configuration

public getPolicyConfig(string $type) : array<string|int, mixed>
Parameters
$type : string

Policy type (password or username)

Return values
array<string|int, mixed>

getSessionInitiator()

Get the URL to establish a session (needed when the internal VuFind login form is inadequate). Returns false when no session initiator is needed.

public getSessionInitiator(string $target) : bool|string
Parameters
$target : string

Full URL where external authentication method should send user after login (some drivers may override this).

Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
bool|string

getTranslator()

Get translator object.

public getTranslator() : TranslatorInterface
Return values
TranslatorInterface

getTranslatorLocale()

Get the locale from the translator.

public getTranslatorLocale([string $default = 'en' ]) : string
Parameters
$default : string = 'en'

Default to use if translator absent.

Return values
string

getUsernamePolicy()

Username policy for a new account (e.g. minLength, maxLength)

public getUsernamePolicy() : array<string|int, mixed>
Return values
array<string|int, mixed>

isExpired()

Has the user's login expired?

public isExpired() : bool
Return values
bool

logout()

Perform cleanup at logout time.

public logout(string $url) : string
Parameters
$url : string

URL to redirect user to after logging out.

Return values
string

Redirect URL (usually same as $url, but modified in some authentication modules).

needsCsrfCheck()

Whether this authentication method needs CSRF checking for the request.

public needsCsrfCheck(Request $request) : bool
Parameters
$request : Request

Request object.

Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
bool

preLoginCheck()

Inspect the user's request prior to processing a login request; this is essentially an event hook which most auth modules can ignore. See ChoiceAuth for a use case example.

public preLoginCheck(Request $request) : void
Parameters
$request : Request

Request object.

Tags
throws
Auth
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
void

resetState()

Reset any internal status; this is essentially an event hook which most auth modules can ignore. See ChoiceAuth for a use case example.

public resetState() : void
Return values
void

setConfig()

Set configuration.

public setConfig(Config $config) : void
Parameters
$config : Config

Configuration to set

Return values
void

supportsConnectingLibraryCard()

Does this authentication method support connecting library card of currently authenticated user?

public supportsConnectingLibraryCard() : bool
Return values
bool

supportsCreation()

Does this authentication method support account creation?

public supportsCreation() : bool
Return values
bool

supportsPasswordChange()

Does this authentication method support password changing

public supportsPasswordChange() : bool
Return values
bool

supportsPasswordRecovery()

Does this authentication method support password recovery

public supportsPasswordRecovery() : bool
Return values
bool

translate()

Translate a string (or string-castable object)

public translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

translateWithPrefix()

Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.

public translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$prefix : string

Translation key prefix

$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

updatePassword()

Update a user's password from the request.

public updatePassword(Request $request) : UserEntityInterface
Parameters
$request : Request

Request object containing new account details.

Tags
throws
Auth
Return values
UserEntityInterface

Updated user entity.

validateCredentials()

Validate the credentials in the provided request, but do not change the state of the current logged-in user. Return true for valid credentials, false otherwise.

public validateCredentials(Request $request) : bool
Parameters
$request : Request

Request object containing account credentials.

Tags
throws
Auth
Return values
bool

checkPassword()

Check that the user's password matches the provided value.

protected checkPassword(string $password, UserEntityInterface $userRow) : bool
Parameters
$password : string

Password to check.

$userRow : UserEntityInterface

The user row. We pass this instead of the password because we may need to check different values depending on the password hashing configuration.

Return values
bool

collectParamsFromRequest()

Collect parameters from request and populate them.

protected collectParamsFromRequest(Request $request) : array<string|int, string>
Parameters
$request : Request

Request object containing new account details.

Return values
array<string|int, string>

debug()

Log a debug message.

protected debug(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

emailAllowed()

Check that an email address is legal based on inclusion list (if configured).

protected emailAllowed(string $email) : bool
Parameters
$email : string

Email address to check (assumed to be valid/well-formed)

Return values
bool

exceptionIndicatesDuplicateKey()

Does the provided exception indicate that a duplicate key value has been created?

protected exceptionIndicatesDuplicateKey(Exception $e) : bool
Parameters
$e : Exception

Exception to check

Return values
bool

extractTextDomain()

Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.

protected extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

Return values
array<string|int, mixed>

getCannedPolicyHint()

Return a canned username or password policy hint when available

protected getCannedPolicyHint(string $type, string|null $pattern) : string|null
Parameters
$type : string

Policy type (password or username)

$pattern : string|null

Current policy pattern

Return values
string|null

getDebugTranslation()

Build a debug-mode translation

protected getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
$domain : string

Text domain

$str : string

String to translate

$tokens : array<string|int, mixed>

Tokens to inject into the translated string

Return values
string

getOrCreateUserByUsername()

Look up a user by username; create a new entity if no match is found.

protected getOrCreateUserByUsername(string $username) : UserEntityInterface
Parameters
$username : string

Username

Tags
throws
Exception
Return values
UserEntityInterface

log()

Send a message to the logger.

protected log(string $level, string $message[, array<string|int, mixed> $context = [] ][, bool $prependClass = false ]) : void
Parameters
$level : string

Log level

$message : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = false

Prepend class name to message?

Return values
void

logError()

Log an error message.

protected logError(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

logWarning()

Log a warning message.

protected logWarning(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

passwordHashingEnabled()

Is password hashing enabled?

protected passwordHashingEnabled() : bool
Return values
bool

sanitizeTranslationKey()

Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.

protected sanitizeTranslationKey(string $key) : string
Parameters
$key : string

Key to sanitize

Return values
string

Sanitized key

setUserPassword()

Set the password in a UserEntityInterface object.

protected setUserPassword(UserEntityInterface $user, string $pass) : void
Parameters
$user : UserEntityInterface

User to update

$pass : string

Password to store

Return values
void

setUserValueByField()

Set a value in a UserEntityObject using a field name.

protected setUserValueByField(UserEntityInterface $user, string $field, mixed $value) : void
Parameters
$user : UserEntityInterface

User to update

$field : string

Field name being updated

$value : mixed

New value to set

Tags
throws
Exception
Return values
void

translateString()

Get translation for a string

protected translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
$rawStr : string

String to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$domain : string = 'default'

Text domain (omit for default)

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

Return values
string

validateConfig()

Validate configuration parameters. This is a support method for getConfig(), so the configuration MUST be accessed using $this->config; do not call $this->getConfig() from within this method!

protected validateConfig() : void
Tags
throws
Auth
Return values
void

validateParams()

Validate parameters.

protected validateParams(array<string|int, string> $params, UserServiceInterface $userService) : void
Parameters
$params : array<string|int, string>

Parameters returned from collectParamsFromRequest()

$userService : UserServiceInterface

User service

Tags
throws
Auth
Return values
void

validatePassword()

Make sure password isn't blank, matches the policy and passwords match.

protected validatePassword(array<string|int, mixed> $params) : void
Parameters
$params : array<string|int, mixed>

Request parameters

Return values
void

validatePasswordAgainstPolicy()

Verify that a password fulfills the password policy. Throws exception if the password is invalid.

protected validatePasswordAgainstPolicy(string $password) : void
Parameters
$password : string

Password to verify

Tags
throws
Auth
Return values
void

validateStringAgainstPolicy()

Verify that a username or password fulfills the given policy. Throws exception if the string is invalid.

protected validateStringAgainstPolicy(string $type, array<string|int, mixed> $policy, string $string) : void
Parameters
$type : string

Policy type (password or username)

$policy : array<string|int, mixed>

Policy configuration

$string : string

String to verify

Tags
throws
Auth
Return values
void

validateUsername()

Make sure username isn't blank and matches the policy.

protected validateUsername(array<string|int, mixed> $params[, bool $checkPolicy = true ]) : void
Parameters
$params : array<string|int, mixed>

Request parameters

$checkPolicy : bool = true

Whether to check the policy as well (default is true)

Return values
void

validateUsernameAgainstPolicy()

Verify that a username fulfills the username policy. Throws exception if the username is invalid.

protected validateUsernameAgainstPolicy(string $username) : void
Parameters
$username : string

Password to verify

Tags
throws
Auth
Return values
void

Search results