19 declare(strict_types=1);
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) {
304 if ($participant->getOrganisation() instanceof \ilECSOrganisation) {
305 $this->abreviation = $participant->getOrganisation()->getAbbreviation();
309 if (!$this->abreviation) {
310 $this->abreviation = $auths->abbr;
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());
361 $newUser[
"login"] = $local_user;
364 $newUser[
'email'] = $user->
getEmail();
368 $newUser[
"passwd"] =
"";
371 $newUser[
"auth_mode"] =
"ecs";
372 $newUser[
"profile_incomplete"] = 0;
375 $userObj->assignData($newUser);
376 $userObj->setTitle($userObj->getFullname());
377 $userObj->setDescription($userObj->getEmail());
380 $userObj->setLanguage($this->setting->get(
"language"));
383 $userObj->setTimeLimitOwner(7);
384 $userObj->setTimeLimitUnlimited(
false);
385 $userObj->setTimeLimitFrom(time() - 5);
386 $userObj->setTimeLimitUntil(time() + (
int) $this->clientIniFile->readVariable(
"session",
"expire"));
389 $userObj->setOwner(6);
393 $userObj->setActive(
true);
394 $userObj->saveAsNew();
395 $userObj->updateOwner();
396 $userObj->writePrefs();
399 $this->rbacAdmin->assignUser($this->
getCurrentServer()->getGlobalRole(), $userObj->getId());
406 #$this->sendNotification($userObj); 409 return $userObj->getLogin();
417 $user_obj =
new ilObjUser($a_local_user_id);
420 $user_obj->setEmail($user->
getEmail());
422 $user_obj->setActive(
true);
424 $until = $user_obj->getTimeLimitUntil();
426 if ($until < (time() + (
int) $this->clientIniFile->readVariable(
'session',
'expire'))) {
427 $user_obj->setTimeLimitFrom(time() - 60);
428 $user_obj->setTimeLimitUntil(time() + (
int) $this->clientIniFile->readVariable(
"session",
"expire"));
431 $user_obj->refreshLogin();
434 $this->rbacAdmin->assignUser(
442 $this->
getLogger()->debug(
'Finished update of remote user with usr_id: ' . $user->
getImportId());
443 return $user_obj->getLogin();
454 $options->updateOptions();
initRemoteUserWithRemoteId()
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
handleLogin()
Called from base class after successful login.
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
Interface of auth credentials.
getFirstname()
get firstname
static _writeImportId(int $obj_id, string $import_id)
write import id to db (static)
getServerSettings()
Get server settings.
handleLoginByAuthMode(ilAuthStatus $status)
Redirects to shibboleth login; to standard login page for LDAP based authentication or authenticates/...
updateUser(ilECSUser $user, int $a_local_user_id)
update existing user
const INCOMING_AUTH_TYPE_LOGIN_PAGE
resetMailOptions(int $a_usr_id)
Reset mail options to "local only".
getCurrentServer()
Get current server.
static getInstance()
Get singleton instance.
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
static _lookupId($a_user_str)
static _lookupExternalAccount(int $a_user_id)
doAuthentication(\ilAuthStatus $status)
Try ecs authentication.
ilECSSetting $currentServer
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
createUser(ilECSUser $user)
create new user
getAbreviation()
get abbreviation
ilAuthSession $authSession
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
Handle failed authentication.
final const INCOMING_LOCAL
Base class for authentication providers (ldap, apache, ...)
ilECSServerSettings $servers
Auth prvider for ecs auth.
static http()
Fetches the global http state from ILIAS.
__construct(\ilAuthCredentials $credentials)
Constructor.
Collection of ECS settings.
setStatus(int $a_status)
Set auth status.
setCurrentServer(ilECSSetting $server)
Set current server.
Storage of ECS imported objects.
ilAuthCredentials $credentials
const INCOMING_AUTH_TYPE_SHIBBOLETH
initECSServices()
Init ECS Services.
const STATUS_AUTHENTICATED
__construct(Container $dic, ilPlugin $plugin)
setAuthenticatedUserId(int $a_id)
Class ilRbacAdmin Core functions for role based access control.
getInstitution()
get institution
validateHash()
Validate ECS hash.
Auth status implementation.
static set(string $a_var, $a_val)
Set a value.
Stores relevant user data.