Auth\Casuser: fix handling user attributes type & multivalued properties

This commit is contained in:
Benjamin Renard 2024-12-03 10:46:03 +01:00
parent f16bfb5278
commit b2566f90e3
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -10,6 +10,7 @@ use EesyPHP\Check;
use EesyPHP\Config; use EesyPHP\Config;
use EesyPHP\I18n; use EesyPHP\I18n;
use EesyPHP\Log; use EesyPHP\Log;
use function EesyPHP\ensure_is_array;
use function EesyPHP\format_callable; use function EesyPHP\format_callable;
use function EesyPHP\vardump; use function EesyPHP\vardump;
@ -33,12 +34,19 @@ class Casuser extends Backend {
foreach(App::get('auth.cas.user_attributes') as $name => $attr_config) { foreach(App::get('auth.cas.user_attributes') as $name => $attr_config) {
$cas_name = Config::get("cas_name", null, 'string', false, $attr_config); $cas_name = Config::get("cas_name", null, 'string', false, $attr_config);
$alt_cas_name = Config::get("alt_cas_name", $name, 'string', false, $attr_config); $alt_cas_name = Config::get("alt_cas_name", $name, 'string', false, $attr_config);
if (!$cas_name || is_null(Cas :: get_attr($cas_name))) $type = Config::get("type", "string", "string", false, $attr_config);
if (!$cas_name || is_null(Cas :: get_attr($cas_name, null, $type)))
$cas_name = $alt_cas_name; $cas_name = $alt_cas_name;
$info[$name] = Cas :: get_attr( $info[$name] = Cas :: get_attr(
$cas_name?$cas_name:$name, $cas_name?$cas_name:$name,
default: Config::get("default", null, null, false, $attr_config) Config::get("default", null, null, false, $attr_config),
$type
); );
$multivalued = Config::get("multivalued", false, "bool", false, $attr_config);
if ($multivalued)
$info[$name] = ensure_is_array($info[$name]);
elseif (is_array($info[$name]))
$info[$name] = $info[$name][0];
} }
Log::debug('User "%s" info computed from CAS attributes:\n%s', $username, vardump($info)); Log::debug('User "%s" info computed from CAS attributes:\n%s', $username, vardump($info));
return new User($username, '\\EesyPHP\\Auth\\Casuser', $info); return new User($username, '\\EesyPHP\\Auth\\Casuser', $info);