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\AdviceInterface; |
22
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyAdministration\EvaluationEnum; |
23
|
|
|
use function assert; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @package Limoncello\Auth |
27
|
|
|
*/ |
28
|
|
|
class Advice extends Method implements AdviceInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
private $appliesTo; |
34
|
|
|
|
35
|
|
|
/** |
36
|
20 |
|
* @param int $appliesTo |
37
|
|
|
* @param callable $callable |
38
|
|
|
*/ |
39
|
|
|
public function __construct(int $appliesTo, 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
|
20 |
|
// or if the decision resulting from evaluating the rule, policy, |
47
|
|
|
// or policy set does not match the decision resulting from evaluating |
48
|
20 |
|
// an enclosing policy set. |
49
|
20 |
|
assert($appliesTo === EvaluationEnum::PERMIT || $appliesTo === EvaluationEnum::DENY); |
50
|
|
|
|
51
|
|
|
$this->appliesTo = $appliesTo; |
52
|
|
|
parent::__construct($callable); |
53
|
|
|
} |
54
|
|
|
|
55
|
20 |
|
/** |
56
|
|
|
* @inheritdoc |
57
|
20 |
|
*/ |
58
|
|
|
public function getAppliesTo(): int |
59
|
|
|
{ |
60
|
|
|
return $this->appliesTo; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|