|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Limoncello\Auth\Authorization\PolicyAdministration; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2015-2019 [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\EvaluationEnum; |
|
22
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\ObligationInterface; |
|
23
|
|
|
use function assert; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @package Limoncello\Auth |
|
27
|
|
|
*/ |
|
28
|
|
|
class Obligation extends Method implements ObligationInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var int |
|
32
|
|
|
*/ |
|
33
|
|
|
private $fulfillOn; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
18 |
|
* @param int $fulfillOn |
|
37
|
|
|
* @param callable $callable |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(int $fulfillOn, callable $callable) |
|
40
|
|
|
{ |
|
41
|
|
|
// Reminder on obligations and advice (from 7.18) |
|
42
|
|
|
//--------------------------------------------------------------------- |
|
43
|
|
|
// no obligations or advice SHALL be returned to the PEP if the rule, |
|
44
|
|
|
// policies, or policy sets from which they are drawn are not evaluated, |
|
45
|
|
|
// or if their evaluated result is "Indeterminate" or "NotApplicable", |
|
46
|
18 |
|
// or if the decision resulting from evaluating the rule, policy, |
|
47
|
|
|
// or policy set does not match the decision resulting from evaluating |
|
48
|
18 |
|
// an enclosing policy set. |
|
49
|
18 |
|
assert($fulfillOn === EvaluationEnum::PERMIT || $fulfillOn === EvaluationEnum::DENY); |
|
50
|
|
|
|
|
51
|
|
|
$this->fulfillOn = $fulfillOn; |
|
52
|
|
|
parent::__construct($callable); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
18 |
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
18 |
|
*/ |
|
58
|
|
|
public function getFulfillOn(): int |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->fulfillOn; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|