nur-sery/nur_src/b/authnz/CasUserManager.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\b\authnz;
use nur\A;
use nur\str;
/**
* Class CasUserManager: un utilisateur CAS v3
*/
class CasUserManager extends SimpleUserManager {
function __construct(?string $appcode=null) {
$this->appcode = $appcode;
}
protected $appcode;
function _getUser(string $username): ?array {
return ["username" => $username];
}
function getUser(string $username, ?array $overrides, ?bool &$found=null): array {
$user = parent::getUser($username, $overrides, $found);
# support des attributs CAS
$cas_attrs = A::get($overrides, "cas_attrs");
if ($cas_attrs !== null) {
$authzs = A::get($cas_attrs, "rununivauthorization");
if ($authzs !== null) {
$authzs = explode(",", $authzs);
$appcode = $this->appcode;
$groups = [];
$perms = [];
foreach ($authzs as $authz) {
if ($authz == "*:*") {
$perms[] = "*";
} elseif ($authz == "$appcode:*") {
$perms[] = "*";
} elseif (str::del_prefix($authz, "$appcode:")) {
if (str::del_prefix($authz, "@")) {
$groups[] = $authz;
} else {
$perms[] = $authz;
}
}
}
A::merge($user["groups"], $groups);
A::merge($user["perms"], $perms);
}
}
return $user;
}
}