19 declare(strict_types=1);
46 $this->
logger = $DIC->logger()->auth();
48 $this->
lng = $DIC->language();
51 $this->auth_session = $session;
92 $this->
logger->warning(
'Desired user account is not authenticated');
98 $this->
logger->info(
'Cannot instantiate user account for account migration: ' . $session->
getUserId());
106 $user->setExternalAccount(
ilSession::get(static::MIG_EXTERNAL_ACCOUNT));
111 $this->
logger->warning(
'Provider: ' . get_class($provider) .
' does not support account migration.');
115 $provider->migrateAccount($this->
getStatus());
125 foreach ($this->providers as
$provider) {
127 $this->
logger->warning(
'Provider: ' . get_class($provider) .
' does not support account migration.');
130 $provider->createNewAccount($this->
getStatus());
146 $this->
logger->debug(
'Trying authentication against: ' . get_class($provider));
148 $provider->doAuthentication($this->
getStatus());
150 $this->
logger->debug(
'Authentication user id: ' . $this->
getStatus()->getAuthenticatedUserId());
157 $this->
logger->notice(
'Account migration required.');
162 $this->
logger->error(
'Authentication migratittion required but provider does not support interface' . get_class($provider));
166 $this->
logger->debug(
'Authentication failed against: ' . get_class($provider));
180 #$this->getStatus()->setStatus(ilAuthStatus::STATUS_AUTHENTICATED); 195 $this->
getStatus()->setReason(
'auth_err_invalid_user_account');
200 $this->
logger->error(
'Cannot instantiate user account with id: ' . $this->
getStatus()->getAuthenticatedUserId());
207 $this->
logger->info(
'Authentication failed for inactive user with id and too may login attempts: ' . $this->
getStatus()->getAuthenticatedUserId());
214 $this->
logger->info(
'Authentication failed for inactive user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
222 $this->
logger->info(
'Authentication failed (time limit restriction) for user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
224 if ($this->
settings->get(
'user_reactivate_code')) {
225 $this->
logger->debug(
'Accout reactivation codes are active');
228 $this->
logger->debug(
'Accout reactivation codes are inactive');
237 $this->
logger->info(
'Authentication failed (wrong ip) for user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
244 $this->
logger->debug(
'Check simutaneous login');
246 $this->
logger->info(
'Authentication failed: simultaneous logins forbidden for user: ' . $this->
getStatus()->getAuthenticatedUserId());
254 $this->user_profile->isProfileIncomplete($user) &&
259 $user->setProfileIncomplete(
true);
276 $security_settings->isPasswordChangeOnFirstLoginEnabled() &&
277 $user->getLastLogin() ===
'' 279 $user->resetLastPasswordChange();
281 $user->refreshLogin();
283 if ($user->getLoginAttempts() > 0) {
284 $user->setLoginAttempts(0);
298 if (PHP_SAPI !==
'cli') {
300 'logged in as ' . $user->getLogin() .
306 'logged in as ' . $user->getLogin() .
' from CLI' 312 'components/ILIAS/Authentication',
315 'username' => $user->getLogin()
340 $maxLoginAttempts = $security->getLoginMaxAttempts();
342 if (!$maxLoginAttempts) {
348 return $numLoginAttempts < $maxLoginAttempts;
359 if (trim($clientip) !==
'') {
360 $clientip = preg_replace(
'/[^0-9.?*,:]+/',
'', $clientip);
361 $clientip = str_replace([
'.',
'?',
'*',
','], [
"\\.",
'[0-9]',
'[0-9]*',
'|'], $clientip);
365 if (!preg_match(
'/^' . $clientip .
'$/', $_SERVER[
'REMOTE_ADDR'])) {
374 $this->
logger->debug(
'Setting prevent simultaneous session is: ' . $this->
settings->get(
'ps_prevent_simultaneous_logins'));
375 return !($this->
settings->get(
'ps_prevent_simultaneous_logins') &&
381 $this->
logger->debug(
'Authentication failed for all authentication methods.');
391 $max_attempts = $security->getLoginMaxAttempts();
392 if ($max_attempts < 1) {
402 $auth_modes = $auth_determination->getAuthModeSequence($this->
getCredentials()->getUsername());
405 $usr_id_candidates = [];
406 foreach (array_filter($auth_modes) as $auth_mode) {
417 if (!is_string($login) || $login ===
'') {
424 $usr_id_candidates = array_values(array_unique(array_filter($usr_id_candidates, intval(...))));
425 $num_deacticated_accounts = 0;
426 foreach ($usr_id_candidates as $usr_id) {
433 if ($num_login_attempts <= $max_attempts) {
437 'Incremented login attempts for user %s with id %s.',
444 if ($num_login_attempts >= $max_attempts) {
447 ++$num_deacticated_accounts;
450 'User account %s with id %s set to inactive due to exceeded login attempts.',
458 if ($num_deacticated_accounts > 0) {
459 $this->
getStatus()->setReason(
'auth_err_login_attempts_deactivation');
static hasActiveSession(int $a_user_id, string $a_session_id)
const int CONTEXT_ECS
Calendar authentication with auth token.
migrateAccount(ilAuthSession $session)
static get(string $a_var)
static _getLoginAttempts(int $a_usr_id)
static getLogger(string $a_component_id)
Get component logger.
handleAuthenticationSuccess(ilAuthProviderInterface $provider)
const string MIG_DESIRED_AUTHMODE
const string MIG_TRIGGER_AUTHMODE
const int STATUS_AUTHENTICATED
checkSimultaneousLogins(ilObjUser $user)
const CONTEXT_LTI_PROVIDER
isAuthenticated()
Check if session is authenticated.
static _lookupId($a_user_str)
handleAccountMigration(ilAuthProviderAccountMigrationInterface $provider)
checkExceededLoginAttempts(ilObjUser $user)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
static _getAuthModeName($a_auth_key)
ilAuthSession $auth_session
getUserId()
Get authenticated user id.
static addUser(int $a_user_id)
checkTimeLimit(ilObjUser $user)
handleAuthenticationFail()
checkActivation(ilObjUser $user)
static _setUserInactive(int $a_usr_id)
getTriggerAuthMode()
Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 1...
const int STATUS_CODE_ACTIVATION_REQUIRED
ilUserProfile $user_profile
const int STATUS_AUTHENTICATION_FAILED
ilAuthCredentials $credentials
static handleLoginEvent(string $a_login, ilAuthSession $auth_session)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ilAppEventHandler $ilAppEventHandler
static _incrementLoginAttempts(int $a_usr_id)
__construct(ilAuthSession $session, ilAuthStatus $status, ilAuthCredentials $credentials, array $providers)
const int STATUS_UNDEFINED
static getType()
Get context type.
static initUserAccount()
Init user with current account id.
getExternalAccountName()
Get external account name.
const string MIG_EXTERNAL_ACCOUNT
static _getInstance()
Get instance of ilSecuritySettings.
static set(string $a_var, $a_val)
Set a value.
getUserAuthModeName()
Get user auth mode name ldap_1 for ldap account migration with server id 1 apache for apache auth...
raise(string $a_component, string $a_event, array $a_parameter=[])
Raise an event.
static _lookupLogin(int $a_user_id)
const int STATUS_ACCOUNT_MIGRATION_REQUIRED