1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Rik van der Kemp <[email protected]> |
4
|
|
|
* @copyright Zicht Online <http://www.zicht.nl> |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Zicht\Bundle\PageBundle\Security\Voter; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
10
|
|
|
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Checks on 'vote' whether or not the current user is and admin |
14
|
|
|
* |
15
|
|
|
* @package Zicht\Bundle\PageBundle\Security\Voter |
16
|
|
|
*/ |
17
|
|
|
abstract class AbstractAdminAwareVoter extends AbstractVoter |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Returns the vote for the given parameters. |
21
|
|
|
* |
22
|
|
|
* This method must return one of the following constants: |
23
|
|
|
* ACCESS_GRANTED, ACCESS_DENIED, or ACCESS_ABSTAIN. |
24
|
|
|
* |
25
|
|
|
* @param TokenInterface $token A TokenInterface instance |
26
|
|
|
* @param object $object The object to secure |
27
|
|
|
* @param array $attributes An array of attributes associated with the method being invoked |
28
|
|
|
* |
29
|
|
|
* @return integer either ACCESS_GRANTED, ACCESS_ABSTAIN, or ACCESS_DENIED |
30
|
|
|
*/ |
31
|
7 |
|
public function vote(TokenInterface $token, $object, array $attributes) |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Admin users should see content no matter the scheduled dates |
35
|
|
|
* Since you can set the decision strategy to unanimous, you want to grant this explicitly |
36
|
|
|
*/ |
37
|
7 |
|
if ($this->supportsClass(get_class($object)) && sizeof($token->getRoles())) { |
|
|
|
|
38
|
|
|
/** @var \Symfony\Component\Security\Core\Role\Role $role */ |
39
|
|
|
foreach ($token->getRoles() as $role) { |
40
|
|
|
if (in_array($role->getRole(), array('ROLE_ADMIN', 'ROLE_SUPER_ADMIN'))) { |
41
|
|
|
return VoterInterface::ACCESS_GRANTED; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
7 |
|
return VoterInterface::ACCESS_ABSTAIN; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.