ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSimpleSAMLphpWrapper.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'libs/composer/vendor/autoload.php';
5require_once 'Services/Saml/interfaces/interface.ilSamlAuth.php';
6
11{
15 protected $config;
16
20 protected $authSource;
21
28 public function __construct($authSourceName, $configurationPath)
29 {
30 $this->initConfigFiles($configurationPath);
31
34
35 $sessionHandler = $this->config->getString('session.handler', false);
36 $storageType = $this->config->getString('store.type', false);
37
38 if (
39 $storageType == 'phpsession' || $sessionHandler == 'phpsession' ||
40 (empty($storageType) && empty($sessionHandler))
41 ) {
42 throw new RuntimeException('Invalid SimpleSAMLphp session handler: Must not be phpsession');
43 }
44
45 $this->authSource = new SimpleSAML\Auth\Simple($authSourceName);
46 }
47
51 protected function initConfigFiles($configurationPath)
52 {
53 global $DIC;
54
55 $templateHandler = new ilSimpleSAMLphpConfigTemplateHandler($DIC->filesystem()->storage());
56 $templateHandler->copy('./Services/Saml/lib/config.php.dist', 'auth/saml/config/config.php', [
57 'DB_PATH' => rtrim($configurationPath, '/') . '/ssphp.sq3',
58 'SQL_INITIAL_PASSWORD'=> function () {
59 require_once 'Services/Password/classes/class.ilPasswordUtils.php';
60 return substr(str_replace('+', '.', base64_encode(ilPasswordUtils::getBytes(20))), 0, 10);
61 },
62 'COOKIE_PATH' => IL_COOKIE_PATH,
63 'LOG_DIRECTORY' => ilLoggingDBSettings::getInstance()->getLogDir()
64 ]);
65 $templateHandler->copy('./Services/Saml/lib/authsources.php.dist', 'auth/saml/config/authsources.php', [
66 'RELAY_STATE' => rtrim(ILIAS_HTTP_PATH, '/') . '/saml.php',
67 'SP_ENTITY_ID' => rtrim(ILIAS_HTTP_PATH, '/') . '/Services/Saml/lib/metadata.php'
68 ]);
69 }
70
74 public function getAuthId()
75 {
76 return $this->authSource->getAuthSource()->getAuthId();
77 }
78
82 public function protectResource()
83 {
84 $this->authSource->requireAuth();
85 }
86
90 public function storeParam($key, $value)
91 {
93 $session->setData('ilias', $key, $value);
94 }
95
99 public function getParam($key)
100 {
102
103 $value = $session->getData('ilias', $key);
104
105 return $value;
106 }
107
111 public function popParam($key)
112 {
114 $value = $this->getParam($key);
115 $session->deleteData('ilias', $key);
116
117 return $value;
118 }
119
123 public function isAuthenticated()
124 {
125 return $this->authSource->isAuthenticated();
126 }
127
131 public function getAttributes()
132 {
133 return $this->authSource->getAttributes();
134 }
135
139 public function logout($returnUrl = '')
140 {
141 ilSession::set('used_external_auth', false);
142
143 $params = array(
144 'ReturnStateParam' => 'LogoutState',
145 'ReturnStateStage' => 'ilLogoutState'
146 );
147
148 if (strlen($returnUrl) > 0) {
149 $params['ReturnTo']= $returnUrl;
150 }
151
152 $this->authSource->logout($params);
153 }
154
158 public function getIdpDiscovery()
159 {
160 return new ilSimpleSAMLphplIdpDiscovery();
161 }
162}
const IL_COOKIE_PATH(isset($_GET["client_id"]))
Definition: metadata.php:36
An exception for terminatinating execution or to throw for unit testing.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
static setConfigDir($path, $configSet='simplesaml')
Set the directory for configuration files for the given configuration set.
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243
static getInstance()
Get instance.
static getBytes($length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
static set($a_var, $a_val)
Set a value.
Class ilSimpleSAMLphpWrapper.
protectResource()
Protect a script resource with a SAML auth.
__construct($authSourceName, $configurationPath)
ilSimpleSAMLphpWrapper constructor.
Class ilSimpleSAMLphplIdpDiscovery.
$key
Definition: croninfo.php:18
Interface ilSamlAuth.
$session
global $DIC
Definition: saml.php:7
$params
Definition: disable.php:11