SessionSaml.php (mrbs-1.9.4) | : | SessionSaml.php (mrbs-1.10.0) | ||
---|---|---|---|---|
<?php | <?php | |||
namespace MRBS\Session; | namespace MRBS\Session; | |||
use \SimpleSAML_Auth_Simple; | use \SimpleSAML_Auth_Simple; | |||
use MRBS\User; | ||||
/* | /* | |||
* Session management scheme that delegates everything to a ready configured | * Session management scheme that delegates everything to a ready configured | |||
* SimpleSamlPhp instance. You should use this scheme, along with the | * SimpleSamlPhp instance. You should use this scheme, along with the | |||
* authentication scheme with the same name, if you want your users to | * authentication scheme with the same name, if you want your users to | |||
* authenticate using SAML Single Sign-on. | * authenticate using SAML Single Sign-on. | |||
* | * | |||
* in config.inc.php (assuming Active Directory attributes): | * in config.inc.php (assuming Active Directory attributes): | |||
* $auth['type'] = 'saml'; | * $auth['type'] = 'saml'; | |||
* $auth['session'] = 'saml'; | * $auth['session'] = 'saml'; | |||
skipping to change at line 69 | skipping to change at line 70 | |||
else | else | |||
{ | { | |||
$authSource = 'default-sp'; | $authSource = 'default-sp'; | |||
} | } | |||
$this->ssp = new SimpleSAML_Auth_Simple($authSource); | $this->ssp = new SimpleSAML_Auth_Simple($authSource); | |||
parent::__construct(); | parent::__construct(); | |||
} | } | |||
// No need to prompt for a name - this is done by SimpleSamlPhp | // No need to prompt for a name - this is done by SimpleSamlPhp | |||
public function authGet($target_url=null, $returl=null, $error=null, $raw=fals e) | public function authGet(?string $target_url=null, ?string $returl=null, ?strin g $error=null, bool $raw=false) : void | |||
{ | { | |||
$this->ssp->requireAuth(); | $this->ssp->requireAuth(); | |||
} | } | |||
public function getCurrentUser() | public function getCurrentUser() : ?User | |||
{ | { | |||
$current_username = $this->getUsername(); | $current_username = $this->getUsername(); | |||
return (isset($current_username)) ? \MRBS\auth()->getUser($current_username) : null; | return (isset($current_username)) ? \MRBS\auth()->getUser($current_username) : null; | |||
} | } | |||
public function getUsername() | public function getUsername() : ?string | |||
{ | { | |||
global $auth; | global $auth; | |||
if (!$this->ssp->isAuthenticated()) | if (!$this->ssp->isAuthenticated()) | |||
{ | { | |||
return null; | return null; | |||
} | } | |||
$userData = $this->ssp->getAttributes(); | $userData = $this->ssp->getAttributes(); | |||
$userNameAttr = $auth['saml']['attr']['username']; | $userNameAttr = $auth['saml']['attr']['username']; | |||
return array_key_exists($userNameAttr, $userData) ? $userData[$userNameAttr] [0] : null; | return array_key_exists($userNameAttr, $userData) ? $userData[$userNameAttr] [0] : null; | |||
} | } | |||
public function getLogonFormParams() | public function getLogonFormParams() : ?array | |||
{ | { | |||
$target_url = \MRBS\url_base() . \MRBS\this_page(true); | $target_url = \MRBS\url_base() . \MRBS\this_page(true); | |||
$url = $this->ssp->getLoginURL($target_url); | $url = $this->ssp->getLoginURL($target_url); | |||
$baseURL = strstr($url, '?', true); | $baseURL = strstr($url, '?', true); | |||
parse_str(substr(strstr($url, '?'), 1), $params); | parse_str(substr(strstr($url, '?'), 1), $params); | |||
$result = array( | $result = array( | |||
'action' => $baseURL, | 'action' => $baseURL, | |||
'method' => 'get' | 'method' => 'get' | |||
); | ); | |||
if (!empty($params)) | if (!empty($params)) | |||
{ | { | |||
$result['hidden_inputs'] = $params; | $result['hidden_inputs'] = $params; | |||
} | } | |||
return $result; | return $result; | |||
} | } | |||
public function getLogoffFormParams() | public function getLogoffFormParams() : ?array | |||
{ | { | |||
$target_url = \MRBS\url_base() . \MRBS\this_page(true); | $target_url = \MRBS\url_base() . \MRBS\this_page(true); | |||
$url = $this->ssp->getLogoutURL($target_url); | $url = $this->ssp->getLogoutURL($target_url); | |||
$baseURL = strstr($url, '?', true); | $baseURL = strstr($url, '?', true); | |||
parse_str(substr(strstr($url, '?'), 1), $params); | parse_str(substr(strstr($url, '?'), 1), $params); | |||
$result = array( | $result = array( | |||
'action' => $baseURL, | 'action' => $baseURL, | |||
'method' => 'get' | 'method' => 'get' | |||
); | ); | |||
if (!empty($params)) | if (!empty($params)) | |||
{ | { | |||
$result['hidden_inputs'] = $params; | $result['hidden_inputs'] = $params; | |||
} | } | |||
return $result; | return $result; | |||
} | } | |||
public function processForm() | public function processForm() : void | |||
{ | { | |||
// No need to do anything - all handled by SAML | // No need to do anything - all handled by SAML | |||
} | } | |||
} | } | |||
End of changes. 7 change blocks. | ||||
6 lines changed or deleted | 7 lines changed or added |