46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace NoccyLabs\Mercureact\Broker\Security;
|
||
|
|
||
|
use NoccyLabs\SimpleJWT\JWTToken;
|
||
|
use Rize\UriTemplate\UriTemplate;
|
||
|
|
||
|
class ClaimChecker
|
||
|
{
|
||
|
private UriTemplate $uriTemplate;
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->uriTemplate = new UriTemplate();
|
||
|
}
|
||
|
|
||
|
public function matchAll(array $topics, array $claims): bool
|
||
|
{
|
||
|
$matched = 0;
|
||
|
foreach ((array)$topics as $match) {
|
||
|
foreach ($claims as $claim) {
|
||
|
if (($claim === "*")
|
||
|
|| ($claim === $match)
|
||
|
|| ($this->uriTemplate->extract($claim, $match, true))) {
|
||
|
$matched++;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return ($matched == count($topics));
|
||
|
}
|
||
|
|
||
|
public function matchOne(array $topics, array $claims): bool
|
||
|
{
|
||
|
foreach ((array)$topics as $match) {
|
||
|
foreach ($claims as $claim) {
|
||
|
if (($claim === "*")
|
||
|
|| ($claim === $match)
|
||
|
|| ($this->uriTemplate->extract($claim, $match, true))) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|