diff --git a/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilAuthFrontendCredentialsLTI.php b/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilAuthFrontendCredentialsLTI.php index fbe2fc263deb..55828a4a3776 100644 --- a/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilAuthFrontendCredentialsLTI.php +++ b/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilAuthFrontendCredentialsLTI.php @@ -1,7 +1,5 @@ @@ -264,7 +264,13 @@ public function doAuthentication(\ilAuthStatus $status): bool return false; } - $this->ref_id = $this->provider->platform->getRefId(); + $platformId = $this->messageParameters['platform_id']; + $clientId = $this->provider->platform->clientId; + $deploymentId = $this->messageParameters['deployment_id']; + + $platform = ilLTIPlatform::fromPlatformId($platformId, $clientId, $deploymentId, $this->dataConnector); + + $this->ref_id = $platform->getRefId(); // stores ref_ids of all lti consumer within active LTI User Session $lti_context_ids = ilSession::get('lti_context_ids'); // if session object exists only add ref_id if not already exists @@ -298,41 +304,44 @@ public function doAuthentication(\ilAuthStatus $status): bool ilSession::set('lti_init_target', ilObject::_lookupType($this->ref_id, true) . '_' . $this->ref_id); // lti service activation - if (!$this->provider->platform->enabled) { + if (!$platform->enabled) { $this->getLogger()->warning('Consumer is not enabled'); $status->setReason('lti_consumer_inactive'); $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED); return false; } // global activation status - if (!$this->provider->platform->getActive()) { + if (!$platform->getActive()) { $this->getLogger()->warning('Consumer is not active'); $status->setReason('lti_consumer_inactive'); $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED); return false; } - $lti_id = $this->provider->platform->getExtConsumerId(); + $lti_id = $platform->getExtConsumerId(); if (!$lti_id) { $status->setReason('lti_auth_failed_invalid_key'); $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATION_FAILED); return false; } - $this->getLogger()->debug('Using prefix:' . $this->provider->platform->getPrefix()); + $this->getLogger()->debug('Using prefix:' . $platform->getPrefix()); + + // Use user_id as username instead of user email to avoid problems with uniqueness of the lti user. + $this->getCredentials()->setUsername($this->messageParameters['user_id']); $internal_account = $this->findUserId( $this->getCredentials()->getUsername(), (string) $lti_id, - $this->provider->platform->getPrefix() + $platform->getPrefix() ); if ($internal_account) { - $this->updateUser($internal_account, $this->provider->platform); + $this->updateUser($internal_account, $platform); } else { - $internal_account = $this->createUser($this->provider->platform); + $internal_account = $this->createUser($platform); } - $this->handleLocalRoleAssignments($internal_account, $this->provider->platform); + $this->handleLocalRoleAssignments($internal_account, $platform); $status->setStatus(ilAuthStatus::STATUS_AUTHENTICATED); $status->setAuthenticatedUserId($internal_account); @@ -427,12 +436,12 @@ protected function createUser(ilLTIPlatform $consumer): int $local_user = ilAuthUtils::_generateLogin($consumer->getPrefix() . '_' . $this->getCredentials()->getUsername()); $newUser["login"] = $local_user; - if(isset($this->messageParameters['lis_person_name_given'])) { + if (isset($this->messageParameters['lis_person_name_given'])) { $newUser["firstname"] = $this->messageParameters['lis_person_name_given']; } else { $newUser["firstname"] = '-'; } - if(isset($this->messageParameters['lis_person_name_family'])) { + if (isset($this->messageParameters['lis_person_name_family'])) { $newUser["lastname"] = $this->messageParameters['lis_person_name_family']; } else { $newUser["lastname"] = '-'; @@ -552,6 +561,11 @@ protected function handleLocalRoleAssignments(int $user_id, ilLTIPlatform $consu $role_arr = explode(',', $roles); foreach ($role_arr as $role_name) { $role_name = trim($role_name); + $role_name = str_replace('http://purl.imsglobal.org/vocab/lis/v2/membership#', '', $role_name); + $role_name = str_replace('http://purl.imsglobal.org/vocab/lis/v2/person#', '', $role_name); + $role_name = str_replace('http://purl.imsglobal.org/vocab/lis/v2/institution/person#', '', $role_name); + $role_name = str_replace('http://purl.imsglobal.org/vocab/lis/v2/system/person#', '', $role_name); + switch ($role_name) { case 'Administrator': $this->getLogger()->info('Administrator role handling'); diff --git a/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTIProviderObjectSetting.php b/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTIProviderObjectSetting.php index 1372cdf29d37..085524e9f7d1 100644 --- a/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTIProviderObjectSetting.php +++ b/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTIProviderObjectSetting.php @@ -1,7 +1,5 @@ initObjectSettingsForm(); + $form->setValuesByPost(); if (!$form->checkInput()) { - $form->setValuesByPost(); $this->settings($form); return; } diff --git a/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTITool.php b/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTITool.php index e10b59e909d6..63fb783298c4 100644 --- a/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTITool.php +++ b/components/ILIAS/LTIProvider/classes/InternalProvider/class.ilLTITool.php @@ -41,14 +41,13 @@ class ilLTITool extends Tool */ public function __construct(ilLTIDataConnector $dataConnector) { - global $DIC; $this->logger = ilLoggerFactory::getLogger('ltis'); // $this->initialize(); if (empty($dataConnector)) { $dataConnector = ilLTIDataConnector::getDataConnector(); } $this->dataConnector = $dataConnector; - // parent::__construct($dataConnector); + //parent::__construct($dataConnector); $this->setParameterConstraint('resource_link_id', true, 50, array('basic-lti-launch-request')); $this->setParameterConstraint('user_id', true, 64, array('basic-lti-launch-request')); $this->setParameterConstraint('roles', true, null, array('basic-lti-launch-request')); @@ -76,4 +75,13 @@ protected function onLaunch(): void $this->resourceLink->save(); } } + + public function handleRequest(bool $strictMode = null, bool $disableCookieCheck = false, bool $generateWarnings = false): void + { + global $DIC; + + $_POST = $DIC->http()->request()->getParsedBody(); + $_GET = $DIC->http()->request()->getQueryParams(); + parent::handleRequest($strictMode, $disableCookieCheck, $generateWarnings); + } } diff --git a/components/ILIAS/LTIProvider/classes/Setup/class.ilLTIDatabaseUpdateSteps.php b/components/ILIAS/LTIProvider/classes/Setup/class.ilLTIDatabaseUpdateSteps.php index ac114259c4ae..68043d834343 100644 --- a/components/ILIAS/LTIProvider/classes/Setup/class.ilLTIDatabaseUpdateSteps.php +++ b/components/ILIAS/LTIProvider/classes/Setup/class.ilLTIDatabaseUpdateSteps.php @@ -1,7 +1,5 @@ getRecordId(); @@ -146,8 +147,12 @@ public function loadPlatform(Platform $platform): bool $platform->created = strtotime($row->created); $platform->updated = strtotime($row->updated); //ILIAS specific - $platform->setExtConsumerId(intval($row->ext_consumer_id)); - $platform->setRefId((int) $row->ref_id); + // Fix for ILIAS: Change method param type to union type Platform | ilLTIPlatform + // Then check if $platform is ilLTIPlatform + if ($platform instanceof ilLTIPlatform) { + $platform->setExtConsumerId(intval($row->ext_consumer_id)); + $platform->setRefId((int) $row->ref_id); + } // if ($platform->setTitle) $platform->setTitle($row->title); // if ($platform->setDescription) $platform->setDescription($row->description); // if ($platform->setPrefix) $platform->setPrefix($row->prefix); @@ -158,6 +163,7 @@ public function loadPlatform(Platform $platform): bool $this->fixPlatformSettings($platform, false); $ok = true; } + return $ok; } ####### @@ -1573,7 +1579,7 @@ public function loadUserResult(User $userresult): bool 'WHERE user_pk = ' . $ilDB->quote($id, 'integer'); } else { $rid = $userresult->getResourceLink()->getRecordId(); - $uid = $userresult->getId(ToolProvider\Tool::ID_SCOPE_ID_ONLY); + $uid = $userresult->getId(IdScope::IdOnly); $query = 'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' . 'FROM ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME . ' ' . @@ -1619,7 +1625,7 @@ public function saveUserResult(User $userresult): bool $userresult->setRecordId($ilDB->nextId($this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME)); $userresult->created = $time; $rid = $userresult->getResourceLink()->getRecordId(); - $uid = $userresult->getId(ToolProvider\Tool::ID_SCOPE_ID_ONLY); + $uid = $userresult->getId(IdScope::IdOnly); $query = 'INSERT INTO ' . $this->dbTableNamePrefix . DataConnector::USER_RESULT_TABLE_NAME . ' ' . '(user_pk,resource_link_pk,lti_user_id, lti_result_sourcedid, created, updated) ' . 'VALUES( ' . diff --git a/components/ILIAS/LTIProvider/classes/class.ilLTIRouterGUI.php b/components/ILIAS/LTIProvider/classes/class.ilLTIRouterGUI.php index e46e68d2ff90..75f42a485bae 100644 --- a/components/ILIAS/LTIProvider/classes/class.ilLTIRouterGUI.php +++ b/components/ILIAS/LTIProvider/classes/class.ilLTIRouterGUI.php @@ -1,7 +1,5 @@ log->debug("initGUI"); $baseclass = ''; + $cmdclass = ''; if ($this->wrapper->query()->has('baseClass')) { $baseclass = strtolower($this->wrapper->query()->retrieve('baseClass', $this->kindlyTo->string())); } if ($this->wrapper->query()->has('cmdClass')) { $cmdclass = strtolower($this->wrapper->query()->retrieve('cmdClass', $this->kindlyTo->string())); } + if ($baseclass == 'illtiroutergui') { return; } + + $target = ilSession::get('lti_init_target'); + if ($target) { + list($type, $ref_id) = explode('_', $target); + + ilSession::clear('lti_init_target'); + + ilUtil::redirect( + "ilias.php?baseClass=ilRepositoryGUI&ref_id=" . $ref_id + . "&cmd=view" + . "&cmdClass=ilobj" . strtolower($type) . "gui" + ); + } } /** @@ -203,7 +218,7 @@ protected function getContextId(): ?int } } - $referrer = (int) $this->effectiveRefId; + $referer = (int) $this->effectiveRefId; if ($referer > 0) { if (ilSession::has('lti_' . $referer . '_post_data')) { diff --git a/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministration.php b/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministration.php index c6a484e5683c..614de5244e84 100644 --- a/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministration.php +++ b/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministration.php @@ -1,6 +1,5 @@ diff --git a/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministrationAccess.php b/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministrationAccess.php index 22552b70c452..2000f5849c80 100644 --- a/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministrationAccess.php +++ b/components/ILIAS/LTIProvider/classes/class.ilObjLTIAdministrationAccess.php @@ -1,6 +1,5 @@ - */ + * If this is not the case or you just want to try ILIAS, you'll find + * us at: + * https://www.ilias.de + * https://github.com/ILIAS-eLearning + * + *********************************************************************/ + +declare(strict_types=1); + +require_once("../vendor/composer/vendor/autoload.php"); + ilContext::init(ilContext::CONTEXT_LTI_PROVIDER); +// This is done to replace the deprecated method $DIC->ctrl()->setCmd +$_GET['cmd'] = 'post'; +$_POST['cmd'] = 'doLTIAuthentication'; + ilInitialisation::initILIAS(); -// authentication is done here -> global $DIC; -// @todo: removed deprecated ilCtrl methods, this needs inspection by a maintainer. -// $DIC->ctrl()->setCmd('doLTIAuthentication'); + $DIC->ctrl()->setTargetScript('ilias.php'); $DIC->ctrl()->callBaseClass('ilStartUpGUI'); diff --git a/components/ILIAS/LTIProvider/tests/bootstrap.php b/components/ILIAS/LTIProvider/tests/bootstrap.php index 174d7fd709f4..8502d9fbcea2 100644 --- a/components/ILIAS/LTIProvider/tests/bootstrap.php +++ b/components/ILIAS/LTIProvider/tests/bootstrap.php @@ -1,3 +1,19 @@ markTestSkipped('Test skipped while integrating the new dependencies in LTI components.'); - $ltiToolConsumer = new ilLTIPlatform( $this->createMock(ilLTIDataConnector::class) );