|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Symfony package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Kunstmaan\AdminBundle\Helper\Security\Acl\Voter; |
|
13
|
|
|
|
|
14
|
|
|
use Psr\Log\LoggerInterface; |
|
15
|
|
|
use Symfony\Component\Security\Acl\Model\AclProviderInterface; |
|
16
|
|
|
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface; |
|
17
|
|
|
use Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface; |
|
18
|
|
|
use Symfony\Component\Security\Acl\Permission\PermissionMapInterface; |
|
19
|
|
|
use Symfony\Component\Security\Acl\Voter\AclVoter as BaseAclVoter; |
|
20
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* This voter can be used as a base class for implementing your own permissions. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class AclVoter extends BaseAclVoter |
|
28
|
1 |
|
{ |
|
29
|
|
|
/** @var bool */ |
|
30
|
1 |
|
private $permissionsEnabled; |
|
31
|
1 |
|
|
|
32
|
|
|
public function __construct(AclProviderInterface $aclProvider, ObjectIdentityRetrievalStrategyInterface $oidRetrievalStrategy, SecurityIdentityRetrievalStrategyInterface $sidRetrievalStrategy, PermissionMapInterface $permissionMap, LoggerInterface $logger = null, $allowIfObjectIdentityUnavailable = true, $permissionsEnabled = true) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($aclProvider, $oidRetrievalStrategy, $sidRetrievalStrategy, $permissionMap, $logger, $allowIfObjectIdentityUnavailable); |
|
35
|
|
|
$this->permissionsEnabled = $permissionsEnabled; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function vote(TokenInterface $token, $object, array $attributes) |
|
39
|
|
|
{ |
|
40
|
|
|
if (!$this->permissionsEnabled) { |
|
41
|
|
|
return self::ACCESS_GRANTED; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return parent::vote($token, $object, $attributes); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|