-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathAclManager.php
More file actions
108 lines (88 loc) · 2.85 KB
/
Copy pathAclManager.php
File metadata and controls
108 lines (88 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Oneup\AclBundle\Security\Acl\Manager;
use Symfony\Component\Security\Acl\Domain\AclCollectionCache;
use Symfony\Component\Security\Acl\Model\MutableAclProviderInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface;
use Oneup\AclBundle\Security\Acl\Model\AbstractAclManager;
class AclManager extends AbstractAclManager
{
protected $cache;
protected $provider;
protected $token_storage;
protected $authorization_checker;
protected $objectIdentityStrategy;
protected $permissionStrategy;
public function __construct(
MutableAclProviderInterface $provider,
$token_storage,
$authorization_checker,
ObjectIdentityRetrievalStrategyInterface $objectIdentityStrategy,
AclCollectionCache $cache,
$permissionStrategy
) {
$this->provider = $provider;
$this->token_storage = $token_storage;
$this->authorization_checker = $authorization_checker;
$this->objectIdentityStrategy = $objectIdentityStrategy;
$this->cache = $cache;
$this->permissionStrategy = $permissionStrategy;
}
public function preload($objects, $token = null)
{
if (is_null($token)) {
$token = $this->getCurrentAuthenticationToken();
}
$objects = is_array($objects) ? $objects : array($objects);
$token = is_array($token) ? $token : array($token);
return $this->cache->cache($objects, $token);
}
protected function getProvider()
{
return $this->provider;
}
protected function getTokenStorage()
{
return $this->token_storage;
}
protected function getAuthorizationChecker()
{
return $this->authorization_checker;
}
protected function getObjectIdentityStrategy()
{
return $this->objectIdentityStrategy;
}
protected function getPermissionStrategy()
{
return $this->permissionStrategy;
}
public function grant($identity)
{
$object = new AclPermission($identity);
$object->grant($identity);
return $object;
}
public function revoke($identity)
{
$object = new AclPermission($identity);
$object->revoke($identity);
return $object;
}
public function compile(AclPermission $permission)
{
list($grant, $type, $identity, $object, $mask) = $permission->compile();
if (is_null($identity)) {
$identity = $this->getCurrentAuthenticationToken();
}
if (!is_null($mask)) {
$grant ?
$this->addPermission($object, $identity, $mask, $type) :
$this->revokePermission($object, $identity, $mask, $type)
;
} else {
if (!$grant) {
$this->revokePermissions($object, $identity);
}
}
}
}