@@ -6,7 +6,6 @@ |
||
6 | 6 | use PhpAbac\Manager\PolicyRuleManager; |
7 | 7 | use PhpAbac\Manager\ConfigurationManager; |
8 | 8 | use PhpAbac\Manager\CacheManager; |
9 | - |
|
10 | 9 | use Symfony\Component\Config\FileLocator; |
11 | 10 | |
12 | 11 | class Abac |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function enforce($ruleName, $user, $object = null, $options = []) { |
65 | 65 | // Retrieve cache value for the current rule and values if cache item is valid |
66 | - if(($cacheResult = isset($options['cache_result']) && $options['cache_result'] === true) === true) { |
|
66 | + if (($cacheResult = isset($options['cache_result']) && $options['cache_result'] === true) === true) { |
|
67 | 67 | $cacheItem = $this->cacheManager->getItem( |
68 | - "$ruleName-{$user->getId()}-" . (($object !== null) ? $object->getId() : ''), |
|
68 | + "$ruleName-{$user->getId()}-".(($object !== null) ? $object->getId() : ''), |
|
69 | 69 | (isset($options['cache_driver'])) ? $options['cache_driver'] : null, |
70 | 70 | (isset($options['cache_ttl'])) ? $options['cache_ttl'] : null |
71 | 71 | ); |
72 | 72 | // We check if the cache value s valid before returning it |
73 | - if(($cacheValue = $cacheItem->get()) !== null) { |
|
73 | + if (($cacheValue = $cacheItem->get()) !== null) { |
|
74 | 74 | return $cacheValue; |
75 | 75 | } |
76 | 76 | } |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | $rejectedAttributes[] = $attribute->getSlug(); |
93 | 93 | } |
94 | 94 | } |
95 | - $result = (count($rejectedAttributes) === 0) ? : $rejectedAttributes; |
|
96 | - if($cacheResult) { |
|
95 | + $result = (count($rejectedAttributes) === 0) ?: $rejectedAttributes; |
|
96 | + if ($cacheResult) { |
|
97 | 97 | $cacheItem->set($result); |
98 | 98 | $this->cacheManager->save($cacheItem); |
99 | 99 | } |
@@ -69,7 +69,6 @@ discard block |
||
69 | 69 | |
70 | 70 | /** |
71 | 71 | * @param AbstractAttribute $attribute |
72 | - * @param string $attributeType |
|
73 | 72 | * @param object $user |
74 | 73 | * @param object $object |
75 | 74 | * @return mixed |
@@ -108,7 +107,7 @@ discard block |
||
108 | 107 | /** |
109 | 108 | * |
110 | 109 | * @param \PhpAbac\Model\EnvironmentAttribute $attribute |
111 | - * @return mixed |
|
110 | + * @return string |
|
112 | 111 | */ |
113 | 112 | private function retrieveEnvironmentAttribute(EnvironmentAttribute $attribute) { |
114 | 113 | return getenv($attribute->getVariableName()); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function retrieveAttribute(AbstractAttribute $attribute, $user, $object = null) |
78 | 78 | { |
79 | - switch($attribute->getType()) { |
|
79 | + switch ($attribute->getType()) { |
|
80 | 80 | case 'user': |
81 | 81 | return $this->retrieveClassicAttribute($attribute, $user); |
82 | 82 | case 'resource': |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | { |
96 | 96 | $propertyPath = explode('.', $attribute->getProperty()); |
97 | 97 | $propertyValue = $object; |
98 | - foreach($propertyPath as $property) { |
|
98 | + foreach ($propertyPath as $property) { |
|
99 | 99 | $getter = 'get'.ucfirst($property); |
100 | - if(!method_exists($propertyValue, $getter)) { |
|
100 | + if (!method_exists($propertyValue, $getter)) { |
|
101 | 101 | throw new \InvalidArgumentException('There is no getter for the "'.$attribute->getProperty().'" attribute for object "'.get_class($propertyValue).'"'); |
102 | 102 | } |
103 | 103 | $propertyValue = $propertyValue->{$getter}(); |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function getRule($ruleName) |
34 | 34 | { |
35 | - if(!isset($this->rules[$ruleName])) { |
|
36 | - throw new \InvalidArgumentException('The given rule "' . $ruleName . '" is not configured'); |
|
35 | + if (!isset($this->rules[$ruleName])) { |
|
36 | + throw new \InvalidArgumentException('The given rule "'.$ruleName.'" is not configured'); |
|
37 | 37 | } |
38 | 38 | $rule = |
39 | 39 | (new PolicyRule()) |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param PolicyRule $rule |
48 | 48 | */ |
49 | 49 | private function processRuleAttributes(PolicyRule $rule) { |
50 | - foreach($this->rules[$rule->getName()]['attributes'] as $attributeName => $attribute) { |
|
50 | + foreach ($this->rules[$rule->getName()]['attributes'] as $attributeName => $attribute) { |
|
51 | 51 | $rule->addPolicyRuleAttribute( |
52 | 52 | (new PolicyRuleAttribute()) |
53 | 53 | ->setAttribute($this->attributeManager->getAttribute($attributeName)) |
@@ -34,12 +34,12 @@ |
||
34 | 34 | * @param array $configurationFiles |
35 | 35 | */ |
36 | 36 | public function parseConfigurationFile($configurationFiles) { |
37 | - foreach($configurationFiles as $configurationFile) { |
|
37 | + foreach ($configurationFiles as $configurationFile) { |
|
38 | 38 | $config = $this->loaders[$this->format]->load($configurationFile); |
39 | - if(isset($config['attributes'])) { |
|
39 | + if (isset($config['attributes'])) { |
|
40 | 40 | $this->attributes = array_merge($this->attributes, $config['attributes']); |
41 | 41 | } |
42 | - if(isset($config['rules'])) { |
|
42 | + if (isset($config['rules'])) { |
|
43 | 43 | $this->rules = array_merge($this->rules, $config['rules']); |
44 | 44 | } |
45 | 45 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $user1Vehicle = $abac->enforce('vehicle-homologation', $users[0], $vehicles[0], [ |
34 | 34 | 'dynamic_attributes' => ['proprietaire' => 1] |
35 | 35 | ]); |
36 | - if($user1Vehicle === true) { |
|
36 | + if ($user1Vehicle === true) { |
|
37 | 37 | echo("GRANTED : The vehicle 1 is able to be approved for the user 1\n"); |
38 | 38 | } else { |
39 | 39 | echo("FAIL : The system didn't grant access\n"); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $user3Vehicle = $abac->enforce('vehicle-homologation', $users[2], $vehicles[1], [ |
42 | 42 | 'dynamic_attributes' => ['proprietaire' => 3] |
43 | 43 | ]); |
44 | - if(!$user3Vehicle !== true) { |
|
44 | + if (!$user3Vehicle !== true) { |
|
45 | 45 | echo("DENIED : The vehicle 2 is not approved for the user 3 because its last technical review is too old\n"); |
46 | 46 | } else { |
47 | 47 | echo("FAIL : The system didn't deny access\n"); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $user4Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
50 | 50 | 'dynamic_attributes' => ['proprietaire' => 4] |
51 | 51 | ]); |
52 | - if($user4Vehicle !== true) { |
|
52 | + if ($user4Vehicle !== true) { |
|
53 | 53 | echo("DENIED : The vehicle 4 is not able to be approved for the user 4 because he has no driving license\n"); |
54 | 54 | } else { |
55 | 55 | echo("FAIL : The system didn't deny access\n"); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $user5Vehicle = $abac->enforce('vehicle-homologation', $users[3], $vehicles[3], [ |
58 | 58 | 'dynamic_attributes' => ['proprietaire' => 1] |
59 | 59 | ]); |
60 | - if($user5Vehicle !== true) { |
|
60 | + if ($user5Vehicle !== true) { |
|
61 | 61 | echo("DENIED : The vehicle 4 is not able to be approved for the user 2 because he doesn't own the vehicle\n"); |
62 | 62 | } else { |
63 | 63 | echo("FAIL : The system didn't deny access\n"); |