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
|
|
|
$attributeIsSupported = false; |
41
|
|
|
foreach ($attributes as $attribute) { |
42
|
|
|
if ($this->supportsAttribute($attribute)) { |
43
|
|
|
$attributeIsSupported = true; |
44
|
|
|
|
45
|
|
|
break; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (!$this->permissionsEnabled && $attributeIsSupported) { |
50
|
|
|
return self::ACCESS_GRANTED; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (!$this->permissionsEnabled) { |
54
|
|
|
return self::ACCESS_ABSTAIN; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return parent::vote($token, $object, $attributes); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|