19declare(strict_types=1);
55 $this->
logger = $DIC->logger()->auth();
57 $this->
lng = $DIC->language();
116 $this->
logger->warning(
'Desired user account is not authenticated');
122 $this->
logger->info(
'Cannot instantiate user account for account migration: ' . $session->
getUserId());
130 $user->setExternalAccount(
ilSession::get(static::MIG_EXTERNAL_ACCOUNT));
135 $this->
logger->warning(
'Provider: ' . get_class(
$provider) .
' does not support account migration.');
136 throw new InvalidArgumentException(
'Invalid auth provider given.');
152 foreach ($this->providers as
$provider) {
154 $this->
logger->warning(
'Provider: ' . get_class(
$provider) .
' does not support account migration.');
155 throw new InvalidArgumentException(
'Invalid auth provider given.');
177 $this->
logger->debug(
'Trying authentication against: ' . get_class(
$provider));
181 $this->
logger->debug(
'Authentication user id: ' . $this->
getStatus()->getAuthenticatedUserId());
188 $this->
logger->notice(
"Account migration required.");
193 $this->
logger->error(
'Authentication migratittion required but provider does not support interface' . get_class(
$provider));
197 $this->
logger->debug(
'Authentication failed against: ' . get_class(
$provider));
215 #$this->getStatus()->setStatus(ilAuthStatus::STATUS_AUTHENTICATED);
237 $this->
logger->error(
'Cannot instantiate user account with id: ' . $this->
getStatus()->getAuthenticatedUserId());
240 $this->
getStatus()->setReason(
'auth_err_invalid_user_account');
245 $this->
logger->info(
'Authentication failed for inactive user with id and too may login attempts: ' . $this->
getStatus()->getAuthenticatedUserId());
248 $this->
getStatus()->setReason(
'auth_err_login_attempts_deactivation');
253 $this->
logger->info(
'Authentication failed for inactive user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
256 $this->
getStatus()->setReason(
'err_inactive');
262 $this->
logger->info(
'Authentication failed (time limit restriction) for user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
264 if ($this->
settings->get(
'user_reactivate_code')) {
265 $this->
logger->debug(
'Accout reactivation codes are active');
268 $this->
logger->debug(
'Accout reactivation codes are inactive');
272 $this->
getStatus()->setReason(
'time_limit_reached');
278 $this->
logger->info(
'Authentication failed (wrong ip) for user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
284 $this->
lng->txt(
'wrong_ip_detected'),
292 $this->
logger->debug(
'Check simutaneous login');
294 $this->
logger->info(
'Authentication failed: simultaneous logins forbidden for user: ' . $this->
getStatus()->getAuthenticatedUserId());
297 $this->
getStatus()->setReason(
'simultaneous_login_detected');
308 $user->setProfileIncomplete(
true);
328 $security_settings->isPasswordChangeOnFirstLoginEnabled() &&
329 $user->getLastLogin() ===
''
331 $user->resetLastPasswordChange();
333 $user->refreshLogin();
335 if ($user->getLoginAttempts() > 0) {
336 $user->setLoginAttempts(0);
347 $user->hasToAcceptTermsOfServiceInSession(
true);
351 if (PHP_SAPI !==
"cli") {
353 'logged in as ' . $user->getLogin() .
359 'logged in as ' . $user->getLogin() .
' from CLI'
365 'Services/Authentication',
368 'username' => $user->getLogin())
394 $maxLoginAttempts = $security->getLoginMaxAttempts();
396 if (!$maxLoginAttempts) {
402 return $numLoginAttempts < $maxLoginAttempts;
419 if (trim($clientip) !==
"") {
420 $clientip = preg_replace(
"/[^0-9.?*,:]+/",
"", $clientip);
421 $clientip = str_replace([
".",
"?",
"*",
","], [
"\\.",
"[0-9]",
"[0-9]*",
"|"], $clientip);
425 if (!preg_match(
"/^" . $clientip .
"$/",
$_SERVER[
"REMOTE_ADDR"])) {
437 $this->
logger->debug(
'Setting prevent simultaneous session is: ' . $this->
settings->get(
'ps_prevent_simultaneous_logins'));
438 return !($this->
settings->get(
'ps_prevent_simultaneous_logins') &&
447 $this->
logger->debug(
'Authentication failed for all authentication methods.');
454 $this->
logger->notice(
'Increased login attempts for user: ' . $this->
getCredentials()->getUsername());
457 $max_attempts = $security->getLoginMaxAttempts();
459 if ($max_attempts && $login_attempts >= $max_attempts) {
460 $this->
getStatus()->setReason(
'auth_err_login_attempts_deactivation');
461 $this->
logger->warning(
'User account set to inactive due to exceeded login attempts.');
raise(string $a_component, string $a_event, array $a_parameter=[])
Raise an event.
const CONTEXT_ECS
Calendar authentication with auth token.
const MIG_DESIRED_AUTHMODE
ilAppEventHandler $ilAppEventHandler
resetStatus()
Reset status.
checkActivation(ilObjUser $user)
Check activation.
checkIp(ilObjUser $user)
Check ip.
handleAuthenticationFail()
Handle failed authenication.
checkExceededLoginAttempts(ilObjUser $user)
authenticate()
Try to authenticate user.
checkTimeLimit(ilObjUser $user)
Check time limit.
handleAccountMigration(ilAuthProviderAccountMigrationInterface $provider)
Handle account migration.
migrateAccountNew()
Create new user account.
ilAuthSession $auth_session
const MIG_EXTERNAL_ACCOUNT
__construct(ilAuthSession $session, ilAuthStatus $status, ilAuthCredentials $credentials, array $providers)
checkSimultaneousLogins(ilObjUser $user)
Check simultaneous logins.
ilAuthCredentials $credentials
migrateAccount(ilAuthSession $session)
Migrate Account to existing user account.
getAuthSession()
Get auth session.
getCredentials()
Get auth credentials.
getProviders()
Get providers.
handleAuthenticationSuccess(ilAuthProviderInterface $provider)
Handle successful authentication.
const MIG_TRIGGER_AUTHMODE
getUserId()
Get authenticated user id.
Auth status implementation.
const STATUS_CODE_ACTIVATION_REQUIRED
const STATUS_AUTHENTICATED
const STATUS_AUTHENTICATION_FAILED
const STATUS_ACCOUNT_MIGRATION_REQUIRED
static getType()
Get context type.
const CONTEXT_LTI_PROVIDER
static initUserAccount()
Init user with current account id.
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static _updateOldAccess(int $a_usr_id)
static _getLoginAttempts(int $a_usr_id)
static _lookupId($a_user_str)
static _incrementLoginAttempts(int $a_usr_id)
static hasActiveSession(int $a_user_id, string $a_session_id)
static _lookupLogin(int $a_user_id)
static _setUserInactive(int $a_usr_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static addUser(int $a_user_id)
static _getInstance()
Get instance of ilSecuritySettings.
static handleLoginEvent(string $a_login, ilAuthSession $auth_session)
when current session is allowed to be created it marks it with type regarding to the sessions user co...
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isProfileIncomplete(ilObjUser $a_user, bool $a_include_udf=true, bool $a_personal_data_only=true)
Check if all required personal data fields are set.
Interface of auth credentials.
getExternalAccountName()
Get external account name.
getTriggerAuthMode()
Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 1...
getUserAuthModeName()
Get user auth mode name ldap_1 for ldap account migration with server id 1 apache for apache auth.
Standard interface for auth provider implementations.