19 declare(strict_types=1);
23 private const string ILIAS =
'ilias';
28 public function __construct(
string $authSourceName,
string $configurationPath)
32 SimpleSAML\Configuration::setConfigDir($configurationPath);
33 $this->config = SimpleSAML\Configuration::getInstance();
35 $storageType = $this->config->getString(
'store.type');
37 if (in_array($storageType, [
'phpsession',
''],
true)) {
38 throw new RuntimeException(
'Invalid SimpleSAMLphp session handler: Must not be phpsession or empty');
41 $this->authSource =
new SimpleSAML\Auth\Simple($authSourceName);
49 $templateHandler->
copy(
'../components/ILIAS/Saml/resources/config.php.dist',
'auth/saml/config/config.php', [
50 'DB_PATH' => rtrim($configurationPath,
'/') .
'/ssphp.sq3',
51 'SQL_INITIAL_PASSWORD' =>
static function ():
string {
57 $templateHandler->copy(
'../components/ILIAS/Saml/resources/authsources.php.dist',
'auth/saml/config/authsources.php', [
58 'RELAY_STATE' => rtrim(ILIAS_HTTP_PATH,
'/') .
'/saml.php',
59 'SP_ENTITY_ID' => rtrim(ILIAS_HTTP_PATH,
'/') .
'/metadata.php' 65 return $this->authSource->getAuthSource()->getAuthId();
70 $this->authSource->requireAuth();
73 public function storeParam(
string $key, mixed $value): void
75 $session = SimpleSAML\Session::getSessionFromRequest();
76 $session->setData(self::ILIAS, $key, $value);
81 $session = SimpleSAML\Session::getSessionFromRequest();
83 return $session->getData(self::ILIAS, $key);
88 $session = SimpleSAML\Session::getSessionFromRequest();
90 $session->deleteData(self::ILIAS, $key);
97 return $this->authSource->isAuthenticated();
102 return $this->authSource->getAttributes();
105 public function logout(
string $returnUrl =
''): void
110 'ReturnStateParam' =>
'LogoutState',
111 'ReturnStateStage' =>
'ilLogoutState' 114 if ($returnUrl !==
'') {
115 $params[
'ReturnTo'] = $returnUrl;
118 $this->authSource->logout(
$params);
128 return $this->authSource->getAuthDataArray();
storeParam(string $key, mixed $value)
SimpleSAML Configuration $config
copy(string $sourcePath, string $destinationPath, array $placeholders=[])
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
protectResource()
Protect a script resource with a SAML auth.
Interface Observer Contains several chained tasks and infos about them.
__construct(string $authSourceName, string $configurationPath)
SimpleSAML Auth Simple $authSource
static getBytes(int $length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
initConfigFiles(string $configurationPath)
static clear(string $a_var)
const IL_COOKIE_PATH(isset($_GET['client_id']))
logout(string $returnUrl='')