Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| InMemoryAccessPolicy | |
0.00% |
0 / 5 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| allow | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| allowEveryone | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| decide | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Server\InMemory; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Api\Permission; |
| 8 | use LambdaTwelve\OneRecord\Rdf\Iri; |
| 9 | use LambdaTwelve\OneRecord\Server\GrantAccessPolicy; |
| 10 | use LambdaTwelve\OneRecord\Server\Spi\AccessDelegationStore; |
| 11 | use LambdaTwelve\OneRecord\Server\Spi\AccessPolicy; |
| 12 | use LambdaTwelve\OneRecord\Server\Spi\Action; |
| 13 | use LambdaTwelve\OneRecord\Server\Spi\Agent; |
| 14 | use LambdaTwelve\OneRecord\Server\Spi\Decision; |
| 15 | use Psr\Clock\ClockInterface; |
| 16 | |
| 17 | /** |
| 18 | * The old name of GrantAccessPolicy, kept for one beta so wrappers written |
| 19 | * against it keep compiling. It was never only in memory: it read every grant |
| 20 | * from the AccessDelegationStore it was given. |
| 21 | * |
| 22 | * @deprecated use GrantAccessPolicy |
| 23 | */ |
| 24 | final class InMemoryAccessPolicy implements AccessPolicy |
| 25 | { |
| 26 | private readonly GrantAccessPolicy $policy; |
| 27 | |
| 28 | public function __construct(AccessDelegationStore $delegations, ClockInterface $clock, Decision $denial = Decision::Forbid) |
| 29 | { |
| 30 | $this->policy = new GrantAccessPolicy($delegations, $clock, $denial); |
| 31 | } |
| 32 | |
| 33 | public function addInternal(Iri $agent): void |
| 34 | { |
| 35 | $this->policy->addInternal($agent); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param non-empty-list<Permission> $permissions |
| 40 | */ |
| 41 | public function allow(Iri $agent, Iri $logisticsObject, array $permissions): void |
| 42 | { |
| 43 | $this->policy->allow($agent, $logisticsObject, $permissions); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @param non-empty-list<Permission> $permissions |
| 48 | */ |
| 49 | public function allowEveryone(Iri $logisticsObject, array $permissions): void |
| 50 | { |
| 51 | $this->policy->allowEveryone($logisticsObject, $permissions); |
| 52 | } |
| 53 | |
| 54 | public function decide(Agent $agent, Action $action, ?Iri $resource): Decision |
| 55 | { |
| 56 | return $this->policy->decide($agent, $action, $resource); |
| 57 | } |
| 58 | } |