19declare(strict_types=1);
40 protected ?
int $mid =
null;
57 $this->clientIniFile =
$DIC->clientIni();
58 $this->rbacAdmin =
$DIC->rbac()->admin();
59 $this->setting =
$DIC->settings();
60 $this->
lng = $DIC->language();
61 $this->
lng->loadLanguageModule(
'ecs');
62 $this->
http = $DIC->http();
64 $this->authSession =
$DIC[
'ilAuthSession'];
65 $this->
ctrl = $DIC->ctrl();
86 public function setMID(
int $a_mid): void
121 $this->
getLogger()->debug(
'Starting ECS authentication');
123 $this->
getLogger()->warning(
'No active ecs server found. Aborting');
135 $this->
getLogger()->warning(
'Could not validate ecs hash for any active server.');
146 $is_external_account =
false;
147 if ($this->
http->wrapper()->query()->has(
'ecs_external_account')) {
148 $is_external_account = $this->
http->wrapper()->query()->retrieve(
149 'ecs_external_account',
153 $redirection_target =
'';
154 if ($this->
http->wrapper()->query()->has(
'target')) {
155 $redirection_target = $this->
http->wrapper()->query()->retrieve(
157 $this->
refinery->kindlyTo()->string()
165 $this->
getLogger()->debug(
'Continuing current user session');
171 $is_external_account &&
174 $this->
getLogger()->info(
'ILIAS login page authentication required.');
177 $this->
ctrl->redirectToURL(
'login.php?target=' . $redirection_target);
181 $is_external_account &&
184 $this->
getLogger()->info(
'Redirect to shibboleth authentication');
186 $this->
ctrl->redirectToURL(
'shib_login.php?target=' . $redirection_target);
188 if ($part_settings->areIncomingLocalAccountsSupported()) {
191 $this->
getLogger()->info(
'ECS authentication successful.');
202 $session_user_id = $this->authSession->getUserId();
204 $this->
getLogger()->debug(
'No valid session found');
209 $user =
new ilECSUser($this->
http->request()->getQueryParams());
210 $this->
getLogger()->debug(
'ECS user name: ' . $user->getLogin());
211 $this->
getLogger()->debug(
'Session external account: ' . $session_ext_account);
212 if (!$session_ext_account || strcmp($user->getLogin(), $session_ext_account) !== 0) {
213 $this->
getLogger()->debug(
'No matching session found. Terminating current user session.');
218 $this->rbacAdmin->assignUser($this->
getCurrentServer()->getGlobalRole(), $this->authSession->getUserId());
228 $user =
new ilECSUser($this->
http->request()->getQueryParams());
233 $username = $this->
updateUser($user, $usr_id);
242 $remoteUserRepository->createIfNotExisting(
249 $this->
getLogger()->info(
'Current user is: ' . $username);
256 $user =
new ilECSUser($this->
http->request()->getQueryParams());
260 $remoteUserRepository->createIfRemoteUserNotExisting(
275 if ($this->
http->wrapper()->query()->has(
'ecs_hash')) {
276 $hash = $this->
http->wrapper()->query()->retrieve(
278 $this->
refinery->kindlyTo()->string()
281 if ($this->
http->wrapper()->query()->has(
'ecs_hash_url')) {
282 $hashurl = urldecode(
283 $this->
http->wrapper()->query()->retrieve(
285 $this->refinery->kindlyTo()->string()
288 $hash = basename(parse_url($hashurl, PHP_URL_PATH));
291 $this->
getLogger()->info(
'Using ecs hash: ' . $hash);
295 $res = $connector->getAuth($hash);
296 $auths =
$res->getResult();
303 foreach ($reader->getParticipantsByPid($auths->pid) as $participant) {
305 $this->abreviation = $participant->getOrganisation()->getAbbreviation();
309 if (!$this->abreviation) {
310 $this->abreviation = $auths->abbr;
312 }
catch (Exception
$e) {
313 $this->
getLogger()->warning(
'Authentication failed with message: ' . $e->getMessage());
317 $this->abreviation = $auths->abbr;
320 $this->
getLogger()->debug(
'Got abbreviation: ' . $this->abreviation);
322 $this->
getLogger()->warning(
'Authentication failed with message: ' . $e->getMessage());
329 $details = $connector->getAuth($hash,
true);
332 $this->
getLogger()->debug(
'Token create for mid: ' . $details->getFirstSender());
334 $this->
setMID($details->getFirstSender());
336 $this->
getLogger()->warning(
'Receiving mid failed with message: ' . $e->getMessage());
362 $userObj->setLogin($local_user);
365 $userObj->setTitle($userObj->getFullname());
366 $userObj->setDescription($userObj->getEmail());
367 $userObj->setEmail($user->
getEmail());
370 $userObj->setAuthMode(
'ecs');
372 $userObj->setLanguage($this->setting->get(
"language"));
375 $userObj->setTimeLimitUnlimited(
false);
376 $userObj->setTimeLimitFrom(time() - 5);
377 $userObj->setTimeLimitUntil(time() + (
int) $this->clientIniFile->readVariable(
"session",
"expire"));
380 $userObj->setOwner(6);
384 $userObj->setActive(
true);
385 $userObj->saveAsNew();
386 $userObj->updateOwner();
387 $userObj->writePrefs();
390 $this->rbacAdmin->assignUser($this->
getCurrentServer()->getGlobalRole(), $userObj->getId());
397 #$this->sendNotification($userObj);
400 return $userObj->getLogin();
408 $user_obj =
new ilObjUser($a_local_user_id);
411 $user_obj->setEmail($user->
getEmail());
413 $user_obj->setActive(
true);
415 $until = $user_obj->getTimeLimitUntil();
417 if ($until < (time() + (
int) $this->clientIniFile->readVariable(
'session',
'expire'))) {
418 $user_obj->setTimeLimitFrom(time() - 60);
419 $user_obj->setTimeLimitUntil(time() + (
int) $this->clientIniFile->readVariable(
"session",
"expire"));
421 $user_obj->refreshLogin();
425 $this->rbacAdmin->assignUser(
433 $this->
getLogger()->debug(
'Finished update of remote user with usr_id: ' . $user->
getImportId());
434 return $user_obj->getLogin();
445 $options->updateOptions();
Auth prvider for ecs auth.
doAuthentication(\ilAuthStatus $status)
Try ecs authentication.
__construct(\ilAuthCredentials $credentials)
Constructor.
resetMailOptions(int $a_usr_id)
Reset mail options to "local only".
ilECSSetting $currentServer
getServerSettings()
Get server settings.
setCurrentServer(ilECSSetting $server)
Set current server.
getAbreviation()
get abbreviation
createUser(ilECSUser $user)
create new user
updateUser(ilECSUser $user, int $a_local_user_id)
update existing user
initECSServices()
Init ECS Services.
handleLogin()
Called from base class after successful login.
handleLoginByAuthMode(ilAuthStatus $status)
Redirects to shibboleth login; to standard login page for LDAP based authentication or authenticates/...
getCurrentServer()
Get current server.
ilAuthSession $authSession
ilECSServerSettings $servers
initRemoteUserWithRemoteId()
validateHash()
Validate ECS hash.
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
ilAuthCredentials $credentials
setAuthenticatedUserId(int $a_id)
setStatus(int $a_status)
Set auth status.
const int STATUS_AUTHENTICATED
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
@classDescription Date and time handling
Storage of ECS imported objects.
const INCOMING_AUTH_TYPE_SHIBBOLETH
const INCOMING_AUTH_TYPE_LOGIN_PAGE
Collection of ECS settings.
static getInstance()
Get singleton instance.
Stores relevant user data.
getFirstname()
get firstname
getInstitution()
get institution
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
final const int INCOMING_LOCAL
static _lookupExternalAccount(int $a_user_id)
static _lookupId(string|array $a_user_str)
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
static _writeImportId(int $obj_id, string $import_id)
write import id to db (static)
Class ilRbacAdmin Core functions for role based access control.
static set(string $a_var, $a_val)
Set a value.
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc