19declare(strict_types=1);
48 $this->
logger = $DIC->logger()->auth();
50 $this->
lng = $DIC->language();
53 $this->auth_session = $session;
58 $this->user_profile =
$DIC[
'user']->getProfile();
94 $this->
logger->warning(
'Desired user account is not authenticated');
100 $this->
logger->info(
'Cannot instantiate user account for account migration: ' . $session->
getUserId());
108 $user->setExternalAccount(
ilSession::get(static::MIG_EXTERNAL_ACCOUNT));
113 $this->
logger->warning(
'Provider: ' . get_class(
$provider) .
' does not support account migration.');
114 throw new InvalidArgumentException(
'Invalid auth provider given.');
127 foreach ($this->providers as
$provider) {
129 $this->
logger->warning(
'Provider: ' . get_class(
$provider) .
' does not support account migration.');
130 throw new InvalidArgumentException(
'Invalid auth provider given.');
148 $this->
logger->debug(
'Trying authentication against: ' . get_class(
$provider));
152 $this->
logger->debug(
'Authentication user id: ' . $this->
getStatus()->getAuthenticatedUserId());
159 $this->
logger->notice(
'Account migration required.');
164 $this->
logger->error(
'Authentication migratittion required but provider does not support interface' . get_class(
$provider));
168 $this->
logger->debug(
'Authentication failed against: ' . get_class(
$provider));
182 #$this->getStatus()->setStatus(ilAuthStatus::STATUS_AUTHENTICATED);
197 $this->
getStatus()->setReason(
'auth_err_invalid_user_account');
202 $this->
logger->error(
'Cannot instantiate user account with id: ' . $this->
getStatus()->getAuthenticatedUserId());
209 $this->
logger->info(
'Authentication failed for inactive user with id and too may login attempts: ' . $this->
getStatus()->getAuthenticatedUserId());
216 $this->
logger->info(
'Authentication failed for inactive user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
224 $this->
logger->info(
'Authentication failed (time limit restriction) for user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
226 if ($this->
settings->get(
'user_reactivate_code')) {
227 $this->
logger->debug(
'Accout reactivation codes are active');
230 $this->
logger->debug(
'Accout reactivation codes are inactive');
239 $this->
logger->info(
'Authentication failed (wrong ip) for user with id: ' . $this->
getStatus()->getAuthenticatedUserId());
246 $this->
logger->debug(
'Check simutaneous login');
248 $this->
logger->info(
'Authentication failed: simultaneous logins forbidden for user: ' . $this->
getStatus()->getAuthenticatedUserId());
255 if ($this->user_profile->isProfileIncomplete($user)
259 $user->setProfileIncomplete(
true);
275 $security_settings->isPasswordChangeOnFirstLoginEnabled() &&
276 $user->getLastLogin() ===
''
278 $user->resetLastPasswordChange();
281 if ($user->getLoginAttempts() > 0) {
282 $user->setLoginAttempts(0);
284 $user->refreshLogin();
296 if (PHP_SAPI !==
'cli') {
298 'logged in as ' . $user->getLogin() .
304 'logged in as ' . $user->getLogin() .
' from CLI'
310 'components/ILIAS/Authentication',
313 'username' => $user->getLogin()
338 $maxLoginAttempts = $security->getLoginMaxAttempts();
340 if (!$maxLoginAttempts) {
346 return $numLoginAttempts < $maxLoginAttempts;
357 if (trim($clientip) !==
'') {
358 $clientip = preg_replace(
'/[^0-9.?*,:]+/',
'', $clientip);
359 $clientip = str_replace([
'.',
'?',
'*',
','], [
"\\.",
'[0-9]',
'[0-9]*',
'|'], $clientip);
363 if (!preg_match(
'/^' . $clientip .
'$/',
$_SERVER[
'REMOTE_ADDR'])) {
372 $this->
logger->debug(
'Setting prevent simultaneous session is: ' . $this->
settings->get(
'ps_prevent_simultaneous_logins'));
373 return !($this->
settings->get(
'ps_prevent_simultaneous_logins') &&
379 $this->
logger->debug(
'Authentication failed for all authentication methods.');
389 $max_attempts = $security->getLoginMaxAttempts();
390 if ($max_attempts < 1) {
400 $auth_modes = $auth_determination->getAuthModeSequence($this->
getCredentials()->getUsername());
403 $usr_id_candidates = [];
404 foreach (array_filter($auth_modes) as $auth_mode) {
415 if (!is_string($login) || $login ===
'') {
422 $usr_id_candidates = array_values(array_unique(array_filter($usr_id_candidates, intval(...))));
423 $num_deacticated_accounts = 0;
424 foreach ($usr_id_candidates as $usr_id) {
431 if ($num_login_attempts <= $max_attempts) {
435 'Incremented login attempts for user %s with id %s.',
442 if ($num_login_attempts >= $max_attempts) {
445 ++$num_deacticated_accounts;
448 'User account %s with id %s set to inactive due to exceeded login attempts.',
456 if ($num_deacticated_accounts > 0) {
457 $this->
getStatus()->setReason(
'auth_err_login_attempts_deactivation');
raise(string $a_component, string $a_event, array $a_parameter=[])
Raise an event.
const int CONTEXT_ECS
Calendar authentication with auth token.
ilAppEventHandler $ilAppEventHandler
const string MIG_TRIGGER_AUTHMODE
const string MIG_DESIRED_AUTHMODE
checkActivation(ilObjUser $user)
handleAuthenticationFail()
checkExceededLoginAttempts(ilObjUser $user)
checkTimeLimit(ilObjUser $user)
handleAccountMigration(ilAuthProviderAccountMigrationInterface $provider)
ilAuthSession $auth_session
__construct(ilAuthSession $session, ilAuthStatus $status, ilAuthCredentials $credentials, array $providers)
const string MIG_EXTERNAL_ACCOUNT
checkSimultaneousLogins(ilObjUser $user)
ilAuthCredentials $credentials
migrateAccount(ilAuthSession $session)
handleAuthenticationSuccess(ilAuthProviderInterface $provider)
getUserId()
Get authenticated user id.
isAuthenticated()
Check if session is authenticated.
const int STATUS_UNDEFINED
const int STATUS_AUTHENTICATION_FAILED
const int STATUS_CODE_ACTIVATION_REQUIRED
const int STATUS_ACCOUNT_MIGRATION_REQUIRED
const int STATUS_AUTHENTICATED
static _getAuthModeName($a_auth_key)
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 _getLoginAttempts(int $a_usr_id)
static _incrementLoginAttempts(int $a_usr_id)
static _lookupId(string|array $a_user_str)
static hasActiveSession(int $a_user_id, string $a_session_id)
static _lookupLogin(int $a_user_id)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
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)
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
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.