checkTypeMatchesSession(); // Check that the config variables have been set if (!isset($auth['saml']['ssp_path'])) { throw new \Exception('$auth["saml"]["ssp_path"] must be set in the config file.'); } if (!isset($auth['saml']['attr']['username'])) { throw new \Exception('$auth["saml"]["attr"]["username"] must be set in the config file.'); } // Include the SimpleSamlPhp autoloader require_once $auth['saml']['ssp_path'] . '/lib/_autoload.php'; // Get the SimpleSamlPhp instance for the configured auth source $authSource = $auth['saml']['authsource'] ?? 'default-sp'; $this->ssp = new \SimpleSAML\Auth\Simple($authSource); $this->samesite = self::SAMESITE_LAX; parent::__construct(); } public function init(int $lifetime) : void { global $auth; if ($auth['saml']['disable_mrbs_session_init']) { // If we're using SAML then initialising sessions here can interfere with // session handling in some SAML libraries return; } parent::init($lifetime); } // No need to prompt for a name - this is done by SimpleSamlPhp public function authGet(?string $target_url=null, ?string $returl=null, ?string $error=null, bool $raw=false) : void { $this->ssp->requireAuth(); } public function getCurrentUser() : ?User { $current_username = $this->getUsername(); return (isset($current_username)) ? auth()->getUser($current_username) : parent::getCurrentUser(); } public function getUsername() : ?string { global $auth; if (!$this->ssp->isAuthenticated()) { return null; } $userData = $this->ssp->getAttributes(); $userNameAttr = $auth['saml']['attr']['username']; return array_key_exists($userNameAttr, $userData) ? $userData[$userNameAttr][0] : null; } public function getLogonFormParams() : ?array { $target_url = url_base() . this_page(true); $url = $this->ssp->getLoginURL($target_url); $baseURL = strstr($url, '?', true); parse_str(substr(strstr($url, '?'), 1), $params); $result = array( 'action' => $baseURL, 'method' => Form::METHOD_GET ); if (!empty($params)) { $result['hidden_inputs'] = $params; } return $result; } public function getLogoffFormParams() : ?array { $target_url = url_base() . this_page(true); $url = $this->ssp->getLogoutURL($target_url); $baseURL = strstr($url, '?', true); parse_str(substr(strstr($url, '?'), 1), $params); $result = array( 'action' => $baseURL, 'method' => Form::METHOD_GET ); if (!empty($params)) { $result['hidden_inputs'] = $params; } return $result; } public function processForm() : void { // No need to do anything - all handled by SAML } }