|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oro\Bundle\SecurityBundle\Annotation; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @Annotation |
|
7
|
|
|
* @Target({"METHOD", "CLASS"}) |
|
8
|
|
|
*/ |
|
9
|
|
|
class Acl implements \Serializable |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
private $id; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var bool |
|
18
|
|
|
*/ |
|
19
|
|
|
private $ignoreClassAcl; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $type; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $class; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $permission; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
private $group; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
private $label; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
private $description; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Constructor |
|
53
|
|
|
* |
|
54
|
|
|
* @param array $data |
|
55
|
|
|
* @throws \InvalidArgumentException |
|
56
|
|
|
* |
|
57
|
|
|
* @SuppressWarnings(PHPMD.NPathComplexity) |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct(array $data = null) |
|
60
|
|
|
{ |
|
61
|
|
|
if ($data === null) { |
|
62
|
|
|
return; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->id = isset($data['id']) ? $data['id'] : null; |
|
66
|
|
View Code Duplication |
if (empty($this->id) || strpos($this->id, ' ') !== false) { |
|
67
|
|
|
throw new \InvalidArgumentException('ACL id must not be empty or contain blank spaces.'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$this->type = isset($data['type']) ? $data['type'] : null; |
|
71
|
|
|
if (empty($this->type)) { |
|
72
|
|
|
throw new \InvalidArgumentException(sprintf('ACL type must not be empty. Id: %s.', $this->id)); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->ignoreClassAcl = isset($data['ignore_class_acl']) ? (bool)$data['ignore_class_acl'] : false; |
|
76
|
|
|
$this->permission = isset($data['permission']) ? $data['permission'] : ''; |
|
77
|
|
|
$this->class = isset($data['class']) ? $data['class'] : ''; |
|
78
|
|
|
$this->group = isset($data['group_name']) ? $data['group_name'] : ''; |
|
79
|
|
|
$this->label = isset($data['label']) ? $data['label'] : ''; |
|
80
|
|
|
$this->description = isset($data['description']) ? $data['description'] : ''; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Gets id of this ACL annotation |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getId() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->id; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Indicates whether a class level ACL annotation should be ignored or not. |
|
95
|
|
|
* |
|
96
|
|
|
* This attribute can be used in ACL annotations declared on method level only. |
|
97
|
|
|
* A default value for this attribute is false. It means that both method and |
|
98
|
|
|
* class level ACLs is checked to decide whether an access is granted or not. |
|
99
|
|
|
* |
|
100
|
|
|
* @return bool |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getIgnoreClassAcl() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->ignoreClassAcl; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Gets ACL extension key |
|
109
|
|
|
* |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getType() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->type; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Gets ACL class name |
|
119
|
|
|
* |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getClass() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->class; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param string $class |
|
129
|
|
|
*/ |
|
130
|
|
|
public function setClass($class) |
|
131
|
|
|
{ |
|
132
|
|
|
$this->class = $class; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Gets ACL permission name |
|
137
|
|
|
* |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getPermission() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->permission; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Sets ACL permission name |
|
147
|
|
|
* |
|
148
|
|
|
* @param string $permission |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setPermission($permission) |
|
151
|
|
|
{ |
|
152
|
|
|
$this->permission = $permission; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Gets ACL group name |
|
157
|
|
|
* |
|
158
|
|
|
* @return string |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getGroup() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->group; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Gets ACL label name |
|
167
|
|
|
* |
|
168
|
|
|
* @return string |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getLabel() |
|
171
|
|
|
{ |
|
172
|
|
|
return $this->label; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Gets ACL description |
|
177
|
|
|
* |
|
178
|
|
|
* @return string |
|
179
|
|
|
*/ |
|
180
|
|
|
public function getDescription() |
|
181
|
|
|
{ |
|
182
|
|
|
return $this->description; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* {@inheritdoc} |
|
187
|
|
|
*/ |
|
188
|
|
|
public function serialize() |
|
189
|
|
|
{ |
|
190
|
|
|
return serialize( |
|
191
|
|
|
array( |
|
192
|
|
|
$this->id, |
|
193
|
|
|
$this->type, |
|
194
|
|
|
$this->class, |
|
195
|
|
|
$this->permission, |
|
196
|
|
|
$this->ignoreClassAcl, |
|
197
|
|
|
$this->group, |
|
198
|
|
|
$this->label, |
|
199
|
|
|
$this->description, |
|
200
|
|
|
) |
|
201
|
|
|
); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* {@inheritdoc} |
|
206
|
|
|
*/ |
|
207
|
|
|
public function unserialize($serialized) |
|
208
|
|
|
{ |
|
209
|
|
|
list( |
|
210
|
|
|
$this->id, |
|
211
|
|
|
$this->type, |
|
212
|
|
|
$this->class, |
|
213
|
|
|
$this->permission, |
|
214
|
|
|
$this->ignoreClassAcl, |
|
215
|
|
|
$this->group, |
|
216
|
|
|
$this->label, |
|
217
|
|
|
$this->description, |
|
218
|
|
|
) = unserialize($serialized); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* The __set_state handler |
|
223
|
|
|
* |
|
224
|
|
|
* @param array $data Initialization array |
|
225
|
|
|
* @return Acl A new instance of a Acl object |
|
226
|
|
|
*/ |
|
227
|
|
|
// @codingStandardsIgnoreStart |
|
228
|
|
|
public static function __set_state($data) |
|
229
|
|
|
{ |
|
230
|
|
|
$result = new Acl(); |
|
231
|
|
|
$result->id = $data['id']; |
|
232
|
|
|
$result->type = $data['type']; |
|
233
|
|
|
$result->class = $data['class']; |
|
234
|
|
|
$result->permission = $data['permission']; |
|
235
|
|
|
$result->ignoreClassAcl = $data['ignoreClassAcl']; |
|
236
|
|
|
$result->group = $data['group']; |
|
237
|
|
|
$result->label = $data['label']; |
|
238
|
|
|
$result->description = $data['description']; |
|
239
|
|
|
|
|
240
|
|
|
return $result; |
|
241
|
|
|
} |
|
242
|
|
|
// @codingStandardsIgnoreEnd |
|
243
|
|
|
} |
|
244
|
|
|
|