|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Voter deciding, if the provided object is |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace Graviton\SecurityBundle\Voter; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter; |
|
8
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
12
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
13
|
|
|
* @link http://swisscom.ch |
|
14
|
|
|
*/ |
|
15
|
|
|
class ServiceAllowedVoter extends AbstractVoter |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
/** @var array List of services always allowed to be called. */ |
|
18
|
|
|
private $whitelist = array(); |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param array $whiteList Set of services to be allowed to be called. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct($whiteList = array()) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->whitelist = $whiteList; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Return an array of supported classes. This will be called by supportsClass |
|
31
|
|
|
* |
|
32
|
|
|
* @return array an array of supported classes, i.e. array('Acme\DemoBundle\Model\Product') |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function getSupportedClasses() |
|
35
|
|
|
{ |
|
36
|
|
|
return array( |
|
37
|
|
|
'Symfony\Component\HttpFoundation\Request' |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Return an array of supported attributes. This will be called by supportsAttribute |
|
43
|
|
|
* |
|
44
|
|
|
* @return array an array of supported attributes, i.e. array('CREATE', 'READ') |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function getSupportedAttributes() |
|
47
|
|
|
{ |
|
48
|
|
|
return array( |
|
49
|
|
|
'VIEW' |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Perform a single access check operation on a given attribute, object and (optionally) user |
|
55
|
|
|
* It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass |
|
56
|
|
|
* $user can be one of the following: |
|
57
|
|
|
* a UserInterface object (fully authenticated user) |
|
58
|
|
|
* a string (anonymously authenticated user) |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $attribute The attribute to be checked against. |
|
61
|
|
|
* @param object $object The object the access shall be granted for. |
|
62
|
|
|
* @param UserInterface|string $user The user asking for permission. |
|
63
|
|
|
* |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function isGranted($attribute, $object, $user = null) |
|
67
|
|
|
{ |
|
68
|
|
|
return in_array($object->getPathInfo(), $this->whitelist); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.