-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEnforcer.php
More file actions
74 lines (66 loc) · 1.62 KB
/
Enforcer.php
File metadata and controls
74 lines (66 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Xacmlphp;
/**
* Enforces the checking of the policies at the request point
*
* @package Xacmlphp
*/
class Enforcer
{
/**
* Current decider object
*
* @var Decider
*/
private $decider = null;
/**
* Construct the object and set the decider if it's given
*
* @param Decider $decider Object
*/
public function __construct($decider = null)
{
if ($decider !== null) {
$this->setDecider($decider);
}
}
/**
* Set the Decider object
*
* @param Decider $decider Decider object
*
* @return \Xacmlphp\Enforcer
*/
public function setDecider(Decider $decider)
{
$this->decider = $decider;
return $this;
}
/**
* Get the current Decider object
*
* @return Decider object
*/
public function getDecider()
{
return $this->decider;
}
/**
* Check to see if the given Subject is authorized for the given Resource
*
* @param Subject $subject Subject making request
* @param \Xacmlphp\Resource $resource Resource being accessed (policies attached)
* @param Action $action Action instance
*
* @return bool Allowed/not allowed status
*/
public function isAuthorized(Subject $subject, Resource $resource, Action $action = null)
{
$decider = $this->getDecider();
if ($decider === null) {
throw new \InvalidArgumentException('Invalid Decider object');
}
$policies = $resource->getPolicies();
return $decider->evaluate($subject, $policies, $action);
}
}