AuthSaml.php (mrbs-1.9.4) | : | AuthSaml.php (mrbs-1.10.0) | ||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
use MRBS\User; | use MRBS\User; | |||
class AuthSaml extends Auth | class AuthSaml extends Auth | |||
{ | { | |||
public function __construct() | public function __construct() | |||
{ | { | |||
$this->checkSessionMatchesType(); | $this->checkSessionMatchesType(); | |||
} | } | |||
/* authValidateUser($user, $pass) | /* validateUser($user, $pass) | |||
* | * | |||
* Checks if the specified username/password pair are valid | * Checks if the specified username/password pair are valid | |||
* | * | |||
* $user - The user name | * $user - The user name | |||
* $pass - The password | * $pass - The password | |||
* | * | |||
* Returns: | * Returns: | |||
* false - The pair are invalid or do not exist | * false - The pair are invalid or do not exist | |||
* string - The validated username | * string - The validated username | |||
*/ | */ | |||
public function validateUser($user, $pass) | public function validateUser(?string $user, ?string $pass) | |||
{ | { | |||
$current_username = \MRBS\session()->getUsername(); | $current_username = \MRBS\session()->getUsername(); | |||
if (isset($current_username) && $current_username === $user) | if (isset($current_username) && $current_username === $user) | |||
{ | { | |||
return $user; | return $user; | |||
} | } | |||
return false; | return false; | |||
} | } | |||
public function getUser($username) | public function getUser(string $username) : ?User | |||
{ | { | |||
$user = new User($username); | $user = new User($username); | |||
$user->level = $this->getLevel($username); | $user->level = $this->getLevel($username); | |||
$user->email = $this->getEmail($username); | $user->email = $this->getEmail($username); | |||
return $user; | return $user; | |||
} | } | |||
/* getLevel($username) | /* getLevel($username) | |||
* | * | |||
skipping to change at line 73 | skipping to change at line 73 | |||
* If the user is not logged in, or the provided username doesn't match our | * If the user is not logged in, or the provided username doesn't match our | |||
* SAML session, 0 is returned. | * SAML session, 0 is returned. | |||
* | * | |||
* Otherwise, 1 is returned. | * Otherwise, 1 is returned. | |||
* | * | |||
* $username - The user name | * $username - The user name | |||
* | * | |||
* Returns: | * Returns: | |||
* The user's access level | * The user's access level | |||
*/ | */ | |||
private function getLevel($username) | private function getLevel(string $username) : int | |||
{ | { | |||
global $auth; | global $auth; | |||
$userData = \MRBS\session()->ssp->getAttributes(); | $userData = \MRBS\session()->ssp->getAttributes(); | |||
$current_username = \MRBS\session()->getUsername(); | $current_username = \MRBS\session()->getUsername(); | |||
if (isset($current_username) && $current_username === $username) | if (isset($current_username) && $current_username === $username) | |||
{ | { | |||
foreach ($auth['saml']['admin'] as $attr => $values) | foreach ($auth['saml']['admin'] as $attr => $values) | |||
{ | { | |||
skipping to change at line 104 | skipping to change at line 104 | |||
} | } | |||
return 1; | return 1; | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
// Gets the users e-mail from the SAML attributes. | // Gets the users e-mail from the SAML attributes. | |||
// Returns an empty string if no e-mail address was found | // Returns an empty string if no e-mail address was found | |||
private function getEmail($username) | private function getEmail(string $username) : string | |||
{ | { | |||
global $auth; | global $auth; | |||
$mailAttr = $auth['saml']['attr']['mail']; | $mailAttr = $auth['saml']['attr']['mail']; | |||
$userData = \MRBS\session()->ssp->getAttributes(); | $userData = \MRBS\session()->ssp->getAttributes(); | |||
$current_username = \MRBS\session()->getUsername(); | $current_username = \MRBS\session()->getUsername(); | |||
if (isset($current_username) && $current_username === $username) | if (isset($current_username) && $current_username === $username) | |||
{ | { | |||
return array_key_exists($mailAttr, $userData) ? $userData[$mailAttr][0] : ''; | return array_key_exists($mailAttr, $userData) ? $userData[$mailAttr][0] : ''; | |||
End of changes. 5 change blocks. | ||||
5 lines changed or deleted | 5 lines changed or added |