This commit is contained in:
Dave M. 2023-02-01 16:43:49 +00:00
commit f33fb69150
1 changed files with 11 additions and 6 deletions

View File

@ -13,7 +13,7 @@ class SecurityHandler {
protected ResponseInterface $redirectResponse; protected ResponseInterface $redirectResponse;
protected \Closure $unauthorizeResponse; protected ? \Closure $unauthorizeResponse;
protected ? Taxus $taxus; protected ? Taxus $taxus;
@ -36,13 +36,18 @@ class SecurityHandler {
public function taxus(string $className, string $methodName, object $user = null) : ? ResponseInterface public function taxus(string $className, string $methodName, object $user = null) : ? ResponseInterface
{ {
if ($taxus = $this->getClassAnnotations(Annotation\Taxus::class, $className, $methodName)) { if ($taxus = $this->getClassAnnotations(Annotation\Taxus::class, $className, $methodName)) {
foreach($taxus as $item) { if ($this->unauthorizeResponse) {
if ( !isset($item->privilege) || $this->taxus->granted($item->privilege, $user, $item) ) { foreach ($taxus as $item) {
return null; if (!isset($item->privilege) || $this->taxus->granted($item->privilege, $user, $item)) {
return null;
}
} }
}
return call_user_func_array($this->unauthorizeResponse, [ $user, $taxus, $className, $methodName ] ); return call_user_func_array($this->unauthorizeResponse, [ $user, $taxus, $className, $methodName ]);
}
else {
throw new \ErrorException("Unauthorized response given.");
}
} }
return null; return null;