1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\controller_annotations\Configuration; |
4
|
|
|
|
5
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation; |
6
|
|
|
use Symfony\Component\Routing\Route as RoutingRoute; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @Annotation |
10
|
|
|
*/ |
11
|
|
|
class Security extends ConfigurationAnnotation implements RouteModifierInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $permission; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $role; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
protected $access; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $entity; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
protected $csrf; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $custom; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
6 |
|
public function hasPermission() |
47
|
|
|
{ |
48
|
6 |
|
return !empty($this->permission); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
6 |
|
public function getPermission() |
55
|
|
|
{ |
56
|
6 |
|
return $this->permission; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $permission |
61
|
|
|
* @return Security |
62
|
|
|
*/ |
63
|
6 |
|
public function setPermission($permission) |
64
|
|
|
{ |
65
|
6 |
|
$this->permission = $permission; |
66
|
|
|
|
67
|
6 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
6 |
|
public function hasRole() |
74
|
|
|
{ |
75
|
6 |
|
return !empty($this->role); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
6 |
|
public function getRole() |
82
|
|
|
{ |
83
|
6 |
|
return $this->role; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $role |
88
|
|
|
* @return Security |
89
|
|
|
*/ |
90
|
6 |
|
public function setRole($role) |
91
|
|
|
{ |
92
|
6 |
|
$this->role = $role; |
93
|
|
|
|
94
|
6 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
6 |
|
public function isAccess() |
101
|
|
|
{ |
102
|
6 |
|
return $this->access; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param bool $access |
107
|
|
|
* @return Security |
108
|
|
|
*/ |
109
|
6 |
|
public function setAccess($access) |
110
|
|
|
{ |
111
|
6 |
|
$this->access = $access; |
112
|
|
|
|
113
|
6 |
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
6 |
|
public function hasEntity() |
120
|
|
|
{ |
121
|
6 |
|
return !empty($this->entity); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
6 |
|
public function getEntity() |
128
|
|
|
{ |
129
|
6 |
|
return $this->entity; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $entity |
134
|
|
|
* @return Security |
135
|
|
|
*/ |
136
|
6 |
|
public function setEntity($entity) |
137
|
|
|
{ |
138
|
6 |
|
$this->entity = $entity; |
139
|
|
|
|
140
|
6 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return bool |
145
|
|
|
*/ |
146
|
6 |
|
public function hasCustom() |
147
|
|
|
{ |
148
|
6 |
|
return !empty($this->custom); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
6 |
|
public function getCustom() |
155
|
|
|
{ |
156
|
6 |
|
return $this->custom; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string $custom |
161
|
|
|
* @return Security |
162
|
|
|
*/ |
163
|
6 |
|
public function setCustom($custom) |
164
|
|
|
{ |
165
|
6 |
|
$this->custom = $custom; |
166
|
|
|
|
167
|
6 |
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return bool |
172
|
|
|
*/ |
173
|
6 |
|
public function hasCsrf() |
174
|
|
|
{ |
175
|
6 |
|
return !empty($this->csrf); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param bool $csrf |
180
|
|
|
* @return Security |
181
|
|
|
*/ |
182
|
6 |
|
public function setCsrf($csrf) |
183
|
|
|
{ |
184
|
6 |
|
$this->csrf = $csrf; |
185
|
|
|
|
186
|
6 |
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
5 |
|
public function getAliasName() |
190
|
|
|
{ |
191
|
5 |
|
return 'security'; |
192
|
|
|
} |
193
|
|
|
|
194
|
5 |
|
public function allowArray() |
195
|
|
|
{ |
196
|
5 |
|
return false; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param RoutingRoute $route |
201
|
|
|
*/ |
202
|
6 |
|
public function modifyRoute(RoutingRoute $route) |
203
|
|
|
{ |
204
|
6 |
|
if ($this->isAccess()) { |
205
|
6 |
|
$route->setRequirement('_access', 'TRUE'); |
206
|
|
|
} |
207
|
6 |
|
if ($this->hasPermission()) { |
208
|
6 |
|
$route->setRequirement('_permission', $this->getPermission()); |
209
|
|
|
} |
210
|
6 |
|
if ($this->hasRole()) { |
211
|
6 |
|
$route->setRequirement('_role', $this->getRole()); |
212
|
|
|
} |
213
|
6 |
|
if ($this->hasEntity()) { |
214
|
6 |
|
$route->setRequirement('_entity_access', $this->getEntity()); |
215
|
|
|
} |
216
|
6 |
|
if ($this->hasCsrf()) { |
217
|
6 |
|
$route->setRequirement('_csrf_token', 'TRUE'); |
218
|
|
|
} |
219
|
6 |
|
if ($this->hasCustom()) { |
220
|
6 |
|
$route->setRequirement('_custom_access', $this->getCustom()); |
221
|
|
|
} |
222
|
6 |
|
} |
223
|
|
|
} |
224
|
|
|
|