ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAuthProviderDatabase.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
31  public function doAuthentication(ilAuthStatus $status): bool
32  {
36  $user = ilObjectFactory::getInstanceByObjId(ilObjUser::_loginExists($this->getCredentials()->getUsername()), false);
37 
38  $this->getLogger()->debug('Trying to authenticate user: ' . $this->getCredentials()->getUsername());
39  if ($user instanceof ilObjUser) {
40  if ($user->getId() === ANONYMOUS_USER_ID) {
41  $this->getLogger()->notice('Failed authentication for anonymous user id. ');
42  $this->handleAuthenticationFail($status, 'err_wrong_login');
43  return false;
44  }
45  if (!ilAuthUtils::isLocalPasswordEnabledForAuthMode($user->getAuthMode(true))) {
46  $this->getLogger()->debug('DB authentication failed: current user auth mode does not allow local validation.');
47  $this->getLogger()->debug('User auth mode: ' . $user->getAuthMode(true));
48  $this->handleAuthenticationFail($status, 'err_wrong_login');
49  return false;
50  }
51  if (ilUserPasswordManager::getInstance()->verifyPassword($user, $this->getCredentials()->getPassword())) {
52  $this->getLogger()->debug('Successfully authenticated user: ' . $this->getCredentials()->getUsername());
54  $status->setAuthenticatedUserId($user->getId());
55  return true;
56  }
57  }
58  $this->handleAuthenticationFail($status, 'err_wrong_login');
59  return false;
60  }
61 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
Handle failed authentication.
Base class for authentication providers (ldap, apache, ...)
setStatus(int $a_status)
Set auth status.
static _loginExists(string $a_login, int $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
getLogger()
Get logger.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static isLocalPasswordEnabledForAuthMode($a_authmode)
Check if local password validation is enabled for a specific auth_mode.
setAuthenticatedUserId(int $a_id)
doAuthentication(\ilAuthStatus $status)
Do authentication.
Auth status implementation.
static getInstance()
Singleton method to reduce footprint (included files, created instances)