@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | $this->consumers = []; |
115 | - foreach($this->consumersClosures as $consumer) { |
|
115 | + foreach ($this->consumersClosures as $consumer) { |
|
116 | 116 | $c = $consumer(); |
117 | 117 | if ($c instanceof IConsumer) { |
118 | 118 | $this->consumers[] = $c; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | $this->extensions = []; |
136 | - foreach($this->extensionsClosures as $extension) { |
|
136 | + foreach ($this->extensionsClosures as $extension) { |
|
137 | 137 | $e = $extension(); |
138 | 138 | if ($e instanceof IExtension) { |
139 | 139 | $this->extensions[] = $e; |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | return array(null, null); |
670 | 670 | } |
671 | 671 | |
672 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
672 | + return array(' and (('.implode(') or (', $conditions).'))', $parameters); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -40,688 +40,688 @@ |
||
40 | 40 | use OCP\RichObjectStrings\IValidator; |
41 | 41 | |
42 | 42 | class Manager implements IManager { |
43 | - /** @var IRequest */ |
|
44 | - protected $request; |
|
45 | - |
|
46 | - /** @var IUserSession */ |
|
47 | - protected $session; |
|
48 | - |
|
49 | - /** @var IConfig */ |
|
50 | - protected $config; |
|
51 | - |
|
52 | - /** @var IValidator */ |
|
53 | - protected $validator; |
|
54 | - |
|
55 | - /** @var string */ |
|
56 | - protected $formattingObjectType; |
|
57 | - |
|
58 | - /** @var int */ |
|
59 | - protected $formattingObjectId; |
|
60 | - |
|
61 | - /** @var bool */ |
|
62 | - protected $requirePNG; |
|
63 | - |
|
64 | - /** @var string */ |
|
65 | - protected $currentUserId; |
|
66 | - |
|
67 | - /** |
|
68 | - * constructor of the controller |
|
69 | - * |
|
70 | - * @param IRequest $request |
|
71 | - * @param IUserSession $session |
|
72 | - * @param IConfig $config |
|
73 | - * @param IValidator $validator |
|
74 | - */ |
|
75 | - public function __construct(IRequest $request, |
|
76 | - IUserSession $session, |
|
77 | - IConfig $config, |
|
78 | - IValidator $validator) { |
|
79 | - $this->request = $request; |
|
80 | - $this->session = $session; |
|
81 | - $this->config = $config; |
|
82 | - $this->validator = $validator; |
|
83 | - } |
|
84 | - |
|
85 | - /** @var \Closure[] */ |
|
86 | - private $consumersClosures = array(); |
|
87 | - |
|
88 | - /** @var IConsumer[] */ |
|
89 | - private $consumers = array(); |
|
90 | - |
|
91 | - /** @var \Closure[] */ |
|
92 | - private $extensionsClosures = array(); |
|
93 | - |
|
94 | - /** @var IExtension[] */ |
|
95 | - private $extensions = array(); |
|
96 | - |
|
97 | - /** @var array list of filters "name" => "is valid" */ |
|
98 | - protected $validFilters = array( |
|
99 | - 'all' => true, |
|
100 | - 'by' => true, |
|
101 | - 'self' => true, |
|
102 | - ); |
|
103 | - |
|
104 | - /** @var array list of type icons "type" => "css class" */ |
|
105 | - protected $typeIcons = array(); |
|
106 | - |
|
107 | - /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
108 | - protected $specialParameters = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * @return \OCP\Activity\IConsumer[] |
|
112 | - */ |
|
113 | - protected function getConsumers() { |
|
114 | - if (!empty($this->consumers)) { |
|
115 | - return $this->consumers; |
|
116 | - } |
|
117 | - |
|
118 | - $this->consumers = []; |
|
119 | - foreach($this->consumersClosures as $consumer) { |
|
120 | - $c = $consumer(); |
|
121 | - if ($c instanceof IConsumer) { |
|
122 | - $this->consumers[] = $c; |
|
123 | - } else { |
|
124 | - throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - return $this->consumers; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return \OCP\Activity\IExtension[] |
|
133 | - */ |
|
134 | - protected function getExtensions() { |
|
135 | - if (!empty($this->extensions)) { |
|
136 | - return $this->extensions; |
|
137 | - } |
|
138 | - |
|
139 | - $this->extensions = []; |
|
140 | - foreach($this->extensionsClosures as $extension) { |
|
141 | - $e = $extension(); |
|
142 | - if ($e instanceof IExtension) { |
|
143 | - $this->extensions[] = $e; |
|
144 | - } else { |
|
145 | - throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - return $this->extensions; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Generates a new IEvent object |
|
154 | - * |
|
155 | - * Make sure to call at least the following methods before sending it to the |
|
156 | - * app with via the publish() method: |
|
157 | - * - setApp() |
|
158 | - * - setType() |
|
159 | - * - setAffectedUser() |
|
160 | - * - setSubject() |
|
161 | - * |
|
162 | - * @return IEvent |
|
163 | - */ |
|
164 | - public function generateEvent() { |
|
165 | - return new Event($this->validator); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Publish an event to the activity consumers |
|
170 | - * |
|
171 | - * Make sure to call at least the following methods before sending an Event: |
|
172 | - * - setApp() |
|
173 | - * - setType() |
|
174 | - * - setAffectedUser() |
|
175 | - * - setSubject() |
|
176 | - * |
|
177 | - * @param IEvent $event |
|
178 | - * @throws \BadMethodCallException if required values have not been set |
|
179 | - */ |
|
180 | - public function publish(IEvent $event) { |
|
181 | - if ($event->getAuthor() === '') { |
|
182 | - if ($this->session->getUser() instanceof IUser) { |
|
183 | - $event->setAuthor($this->session->getUser()->getUID()); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - if (!$event->getTimestamp()) { |
|
188 | - $event->setTimestamp(time()); |
|
189 | - } |
|
190 | - |
|
191 | - if (!$event->isValid()) { |
|
192 | - throw new \BadMethodCallException('The given event is invalid'); |
|
193 | - } |
|
194 | - |
|
195 | - foreach ($this->getConsumers() as $c) { |
|
196 | - $c->receive($event); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $app The app where this event is associated with |
|
202 | - * @param string $subject A short description of the event |
|
203 | - * @param array $subjectParams Array with parameters that are filled in the subject |
|
204 | - * @param string $message A longer description of the event |
|
205 | - * @param array $messageParams Array with parameters that are filled in the message |
|
206 | - * @param string $file The file including path where this event is associated with |
|
207 | - * @param string $link A link where this event is associated with |
|
208 | - * @param string $affectedUser Recipient of the activity |
|
209 | - * @param string $type Type of the notification |
|
210 | - * @param int $priority Priority of the notification |
|
211 | - */ |
|
212 | - public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
213 | - $event = $this->generateEvent(); |
|
214 | - $event->setApp($app) |
|
215 | - ->setType($type) |
|
216 | - ->setAffectedUser($affectedUser) |
|
217 | - ->setSubject($subject, $subjectParams) |
|
218 | - ->setMessage($message, $messageParams) |
|
219 | - ->setObject('', 0, $file) |
|
220 | - ->setLink($link); |
|
221 | - |
|
222 | - $this->publish($event); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
227 | - * activity consumers are actually requested |
|
228 | - * |
|
229 | - * $callable has to return an instance of OCA\Activity\IConsumer |
|
230 | - * |
|
231 | - * @param \Closure $callable |
|
232 | - */ |
|
233 | - public function registerConsumer(\Closure $callable) { |
|
234 | - $this->consumersClosures[] = $callable; |
|
235 | - $this->consumers = []; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
240 | - * activity consumers are actually requested |
|
241 | - * |
|
242 | - * $callable has to return an instance of OCA\Activity\IExtension |
|
243 | - * |
|
244 | - * @param \Closure $callable |
|
245 | - */ |
|
246 | - public function registerExtension(\Closure $callable) { |
|
247 | - $this->extensionsClosures[] = $callable; |
|
248 | - $this->extensions = []; |
|
249 | - } |
|
250 | - |
|
251 | - /** @var string[] */ |
|
252 | - protected $filterClasses = []; |
|
253 | - |
|
254 | - /** @var IFilter[] */ |
|
255 | - protected $filters = []; |
|
256 | - |
|
257 | - /** @var bool */ |
|
258 | - protected $loadedLegacyFilters = false; |
|
259 | - |
|
260 | - /** |
|
261 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
262 | - * @return void |
|
263 | - */ |
|
264 | - public function registerFilter($filter) { |
|
265 | - $this->filterClasses[$filter] = false; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return IFilter[] |
|
270 | - * @throws \InvalidArgumentException |
|
271 | - */ |
|
272 | - public function getFilters() { |
|
273 | - if (!$this->loadedLegacyFilters) { |
|
274 | - $legacyFilters = $this->getNavigation(); |
|
275 | - |
|
276 | - foreach ($legacyFilters['top'] as $filter => $data) { |
|
277 | - $this->filters[$filter] = new LegacyFilter( |
|
278 | - $this, $filter, $data['name'], true |
|
279 | - ); |
|
280 | - } |
|
281 | - |
|
282 | - foreach ($legacyFilters['apps'] as $filter => $data) { |
|
283 | - $this->filters[$filter] = new LegacyFilter( |
|
284 | - $this, $filter, $data['name'], false |
|
285 | - ); |
|
286 | - } |
|
287 | - $this->loadedLegacyFilters = true; |
|
288 | - } |
|
289 | - |
|
290 | - foreach ($this->filterClasses as $class => $false) { |
|
291 | - /** @var IFilter $filter */ |
|
292 | - $filter = \OC::$server->query($class); |
|
293 | - |
|
294 | - if (!$filter instanceof IFilter) { |
|
295 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
296 | - } |
|
297 | - |
|
298 | - $this->filters[$filter->getIdentifier()] = $filter; |
|
299 | - |
|
300 | - unset($this->filterClasses[$class]); |
|
301 | - } |
|
302 | - return $this->filters; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * @param string $id |
|
307 | - * @return IFilter |
|
308 | - * @throws \InvalidArgumentException when the filter was not found |
|
309 | - * @since 11.0.0 |
|
310 | - */ |
|
311 | - public function getFilterById($id) { |
|
312 | - $filters = $this->getFilters(); |
|
313 | - |
|
314 | - if (isset($filters[$id])) { |
|
315 | - return $filters[$id]; |
|
316 | - } |
|
317 | - |
|
318 | - throw new \InvalidArgumentException('Requested filter does not exist'); |
|
319 | - } |
|
320 | - |
|
321 | - /** @var string[] */ |
|
322 | - protected $providerClasses = []; |
|
323 | - |
|
324 | - /** @var IProvider[] */ |
|
325 | - protected $providers = []; |
|
326 | - |
|
327 | - /** |
|
328 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
329 | - * @return void |
|
330 | - */ |
|
331 | - public function registerProvider($provider) { |
|
332 | - $this->providerClasses[$provider] = false; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * @return IProvider[] |
|
337 | - * @throws \InvalidArgumentException |
|
338 | - */ |
|
339 | - public function getProviders() { |
|
340 | - foreach ($this->providerClasses as $class => $false) { |
|
341 | - /** @var IProvider $provider */ |
|
342 | - $provider = \OC::$server->query($class); |
|
343 | - |
|
344 | - if (!$provider instanceof IProvider) { |
|
345 | - throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
346 | - } |
|
347 | - |
|
348 | - $this->providers[] = $provider; |
|
349 | - |
|
350 | - unset($this->providerClasses[$class]); |
|
351 | - } |
|
352 | - return $this->providers; |
|
353 | - } |
|
354 | - |
|
355 | - /** @var string[] */ |
|
356 | - protected $settingsClasses = []; |
|
357 | - |
|
358 | - /** @var ISetting[] */ |
|
359 | - protected $settings = []; |
|
360 | - |
|
361 | - /** @var bool */ |
|
362 | - protected $loadedLegacyTypes = false; |
|
363 | - |
|
364 | - /** |
|
365 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
366 | - * @return void |
|
367 | - */ |
|
368 | - public function registerSetting($setting) { |
|
369 | - $this->settingsClasses[$setting] = false; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @return ISetting[] |
|
374 | - * @throws \InvalidArgumentException |
|
375 | - */ |
|
376 | - public function getSettings() { |
|
377 | - if (!$this->loadedLegacyTypes) { |
|
378 | - $l = \OC::$server->getL10N('core'); |
|
379 | - $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
380 | - $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
381 | - $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
382 | - foreach ($legacyTypes as $type => $data) { |
|
383 | - if (is_string($data)) { |
|
384 | - $desc = $data; |
|
385 | - $canChangeStream = true; |
|
386 | - $canChangeMail = true; |
|
387 | - } else { |
|
388 | - $desc = $data['desc']; |
|
389 | - $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
390 | - $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
391 | - } |
|
392 | - |
|
393 | - $this->settings[$type] = new LegacySetting( |
|
394 | - $type, $desc, |
|
395 | - $canChangeStream, in_array($type, $streamTypes), |
|
396 | - $canChangeMail, in_array($type, $mailTypes) |
|
397 | - ); |
|
398 | - } |
|
399 | - $this->loadedLegacyTypes = true; |
|
400 | - } |
|
401 | - |
|
402 | - foreach ($this->settingsClasses as $class => $false) { |
|
403 | - /** @var ISetting $setting */ |
|
404 | - $setting = \OC::$server->query($class); |
|
405 | - |
|
406 | - if (!$setting instanceof ISetting) { |
|
407 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
408 | - } |
|
409 | - |
|
410 | - $this->settings[$setting->getIdentifier()] = $setting; |
|
411 | - |
|
412 | - unset($this->settingsClasses[$class]); |
|
413 | - } |
|
414 | - return $this->settings; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * @param string $id |
|
419 | - * @return ISetting |
|
420 | - * @throws \InvalidArgumentException when the setting was not found |
|
421 | - * @since 11.0.0 |
|
422 | - */ |
|
423 | - public function getSettingById($id) { |
|
424 | - $settings = $this->getSettings(); |
|
425 | - |
|
426 | - if (isset($settings[$id])) { |
|
427 | - return $settings[$id]; |
|
428 | - } |
|
429 | - |
|
430 | - throw new \InvalidArgumentException('Requested setting does not exist'); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @param string $type |
|
435 | - * @return string |
|
436 | - */ |
|
437 | - public function getTypeIcon($type) { |
|
438 | - if (isset($this->typeIcons[$type])) { |
|
439 | - return $this->typeIcons[$type]; |
|
440 | - } |
|
441 | - |
|
442 | - foreach ($this->getExtensions() as $c) { |
|
443 | - $icon = $c->getTypeIcon($type); |
|
444 | - if (is_string($icon)) { |
|
445 | - $this->typeIcons[$type] = $icon; |
|
446 | - return $icon; |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - $this->typeIcons[$type] = ''; |
|
451 | - return ''; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * @param string $type |
|
456 | - * @param string $id |
|
457 | - */ |
|
458 | - public function setFormattingObject($type, $id) { |
|
459 | - $this->formattingObjectType = $type; |
|
460 | - $this->formattingObjectId = (string) $id; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * @return bool |
|
465 | - */ |
|
466 | - public function isFormattingFilteredObject() { |
|
467 | - return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
468 | - && $this->formattingObjectType === $this->request->getParam('object_type') |
|
469 | - && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
474 | - */ |
|
475 | - public function setRequirePNG($status) { |
|
476 | - $this->requirePNG = $status; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @return bool |
|
481 | - */ |
|
482 | - public function getRequirePNG() { |
|
483 | - return $this->requirePNG; |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * @param string $app |
|
488 | - * @param string $text |
|
489 | - * @param array $params |
|
490 | - * @param boolean $stripPath |
|
491 | - * @param boolean $highlightParams |
|
492 | - * @param string $languageCode |
|
493 | - * @return string|false |
|
494 | - */ |
|
495 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
496 | - foreach ($this->getExtensions() as $c) { |
|
497 | - $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
498 | - if (is_string($translation)) { |
|
499 | - return $translation; |
|
500 | - } |
|
501 | - } |
|
502 | - |
|
503 | - return false; |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * @param string $app |
|
508 | - * @param string $text |
|
509 | - * @return array|false |
|
510 | - */ |
|
511 | - public function getSpecialParameterList($app, $text) { |
|
512 | - if (isset($this->specialParameters[$app][$text])) { |
|
513 | - return $this->specialParameters[$app][$text]; |
|
514 | - } |
|
515 | - |
|
516 | - if (!isset($this->specialParameters[$app])) { |
|
517 | - $this->specialParameters[$app] = array(); |
|
518 | - } |
|
519 | - |
|
520 | - foreach ($this->getExtensions() as $c) { |
|
521 | - $specialParameter = $c->getSpecialParameterList($app, $text); |
|
522 | - if (is_array($specialParameter)) { |
|
523 | - $this->specialParameters[$app][$text] = $specialParameter; |
|
524 | - return $specialParameter; |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - $this->specialParameters[$app][$text] = false; |
|
529 | - return false; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * @param array $activity |
|
534 | - * @return integer|false |
|
535 | - */ |
|
536 | - public function getGroupParameter($activity) { |
|
537 | - foreach ($this->getExtensions() as $c) { |
|
538 | - $parameter = $c->getGroupParameter($activity); |
|
539 | - if ($parameter !== false) { |
|
540 | - return $parameter; |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - return false; |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Set the user we need to use |
|
549 | - * |
|
550 | - * @param string|null $currentUserId |
|
551 | - * @throws \UnexpectedValueException If the user is invalid |
|
552 | - */ |
|
553 | - public function setCurrentUserId($currentUserId) { |
|
554 | - if (!is_string($currentUserId) && $currentUserId !== null) { |
|
555 | - throw new \UnexpectedValueException('The given current user is invalid'); |
|
556 | - } |
|
557 | - $this->currentUserId = $currentUserId; |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Get the user we need to use |
|
562 | - * |
|
563 | - * Either the user is logged in, or we try to get it from the token |
|
564 | - * |
|
565 | - * @return string |
|
566 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
567 | - */ |
|
568 | - public function getCurrentUserId() { |
|
569 | - if ($this->currentUserId !== null) { |
|
570 | - return $this->currentUserId; |
|
571 | - } else if (!$this->session->isLoggedIn()) { |
|
572 | - return $this->getUserFromToken(); |
|
573 | - } else { |
|
574 | - return $this->session->getUser()->getUID(); |
|
575 | - } |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * Get the user for the token |
|
580 | - * |
|
581 | - * @return string |
|
582 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
583 | - */ |
|
584 | - protected function getUserFromToken() { |
|
585 | - $token = (string) $this->request->getParam('token', ''); |
|
586 | - if (strlen($token) !== 30) { |
|
587 | - throw new \UnexpectedValueException('The token is invalid'); |
|
588 | - } |
|
589 | - |
|
590 | - $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
591 | - |
|
592 | - if (count($users) !== 1) { |
|
593 | - // No unique user found |
|
594 | - throw new \UnexpectedValueException('The token is invalid'); |
|
595 | - } |
|
596 | - |
|
597 | - // Token found login as that user |
|
598 | - return array_shift($users); |
|
599 | - } |
|
600 | - |
|
601 | - /** |
|
602 | - * @return array |
|
603 | - * @deprecated 11.0.0 - Use getFilters() instead |
|
604 | - */ |
|
605 | - public function getNavigation() { |
|
606 | - $entries = array( |
|
607 | - 'apps' => array(), |
|
608 | - 'top' => array(), |
|
609 | - ); |
|
610 | - foreach ($this->getExtensions() as $c) { |
|
611 | - $additionalEntries = $c->getNavigation(); |
|
612 | - if (is_array($additionalEntries)) { |
|
613 | - $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
614 | - $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
615 | - } |
|
616 | - } |
|
617 | - |
|
618 | - return $entries; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * @param string $filterValue |
|
623 | - * @return boolean |
|
624 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
625 | - */ |
|
626 | - public function isFilterValid($filterValue) { |
|
627 | - if (isset($this->validFilters[$filterValue])) { |
|
628 | - return $this->validFilters[$filterValue]; |
|
629 | - } |
|
630 | - |
|
631 | - foreach ($this->getExtensions() as $c) { |
|
632 | - if ($c->isFilterValid($filterValue) === true) { |
|
633 | - $this->validFilters[$filterValue] = true; |
|
634 | - return true; |
|
635 | - } |
|
636 | - } |
|
637 | - |
|
638 | - $this->validFilters[$filterValue] = false; |
|
639 | - return false; |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * @param array $types |
|
644 | - * @param string $filter |
|
645 | - * @return array |
|
646 | - * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
647 | - */ |
|
648 | - public function filterNotificationTypes($types, $filter) { |
|
649 | - if (!$this->isFilterValid($filter)) { |
|
650 | - return $types; |
|
651 | - } |
|
652 | - |
|
653 | - foreach ($this->getExtensions() as $c) { |
|
654 | - $result = $c->filterNotificationTypes($types, $filter); |
|
655 | - if (is_array($result)) { |
|
656 | - $types = $result; |
|
657 | - } |
|
658 | - } |
|
659 | - return $types; |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * @param string $filter |
|
664 | - * @return array |
|
665 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
666 | - */ |
|
667 | - public function getQueryForFilter($filter) { |
|
668 | - if (!$this->isFilterValid($filter)) { |
|
669 | - return [null, null]; |
|
670 | - } |
|
671 | - |
|
672 | - $conditions = array(); |
|
673 | - $parameters = array(); |
|
674 | - |
|
675 | - foreach ($this->getExtensions() as $c) { |
|
676 | - $result = $c->getQueryForFilter($filter); |
|
677 | - if (is_array($result)) { |
|
678 | - list($condition, $parameter) = $result; |
|
679 | - if ($condition && is_array($parameter)) { |
|
680 | - $conditions[] = $condition; |
|
681 | - $parameters = array_merge($parameters, $parameter); |
|
682 | - } |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - if (empty($conditions)) { |
|
687 | - return array(null, null); |
|
688 | - } |
|
689 | - |
|
690 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Will return additional notification types as specified by other apps |
|
695 | - * |
|
696 | - * @param string $languageCode |
|
697 | - * @return array |
|
698 | - * @deprecated 11.0.0 - Use getSettings() instead |
|
699 | - */ |
|
700 | - public function getNotificationTypes($languageCode) { |
|
701 | - $notificationTypes = $sharingNotificationTypes = []; |
|
702 | - foreach ($this->getExtensions() as $c) { |
|
703 | - $result = $c->getNotificationTypes($languageCode); |
|
704 | - if (is_array($result)) { |
|
705 | - $notificationTypes = array_merge($notificationTypes, $result); |
|
706 | - } |
|
707 | - } |
|
708 | - |
|
709 | - return array_merge($sharingNotificationTypes, $notificationTypes); |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * @param string $method |
|
714 | - * @return array |
|
715 | - * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
716 | - */ |
|
717 | - public function getDefaultTypes($method) { |
|
718 | - $defaultTypes = array(); |
|
719 | - foreach ($this->getExtensions() as $c) { |
|
720 | - $types = $c->getDefaultTypes($method); |
|
721 | - if (is_array($types)) { |
|
722 | - $defaultTypes = array_merge($types, $defaultTypes); |
|
723 | - } |
|
724 | - } |
|
725 | - return $defaultTypes; |
|
726 | - } |
|
43 | + /** @var IRequest */ |
|
44 | + protected $request; |
|
45 | + |
|
46 | + /** @var IUserSession */ |
|
47 | + protected $session; |
|
48 | + |
|
49 | + /** @var IConfig */ |
|
50 | + protected $config; |
|
51 | + |
|
52 | + /** @var IValidator */ |
|
53 | + protected $validator; |
|
54 | + |
|
55 | + /** @var string */ |
|
56 | + protected $formattingObjectType; |
|
57 | + |
|
58 | + /** @var int */ |
|
59 | + protected $formattingObjectId; |
|
60 | + |
|
61 | + /** @var bool */ |
|
62 | + protected $requirePNG; |
|
63 | + |
|
64 | + /** @var string */ |
|
65 | + protected $currentUserId; |
|
66 | + |
|
67 | + /** |
|
68 | + * constructor of the controller |
|
69 | + * |
|
70 | + * @param IRequest $request |
|
71 | + * @param IUserSession $session |
|
72 | + * @param IConfig $config |
|
73 | + * @param IValidator $validator |
|
74 | + */ |
|
75 | + public function __construct(IRequest $request, |
|
76 | + IUserSession $session, |
|
77 | + IConfig $config, |
|
78 | + IValidator $validator) { |
|
79 | + $this->request = $request; |
|
80 | + $this->session = $session; |
|
81 | + $this->config = $config; |
|
82 | + $this->validator = $validator; |
|
83 | + } |
|
84 | + |
|
85 | + /** @var \Closure[] */ |
|
86 | + private $consumersClosures = array(); |
|
87 | + |
|
88 | + /** @var IConsumer[] */ |
|
89 | + private $consumers = array(); |
|
90 | + |
|
91 | + /** @var \Closure[] */ |
|
92 | + private $extensionsClosures = array(); |
|
93 | + |
|
94 | + /** @var IExtension[] */ |
|
95 | + private $extensions = array(); |
|
96 | + |
|
97 | + /** @var array list of filters "name" => "is valid" */ |
|
98 | + protected $validFilters = array( |
|
99 | + 'all' => true, |
|
100 | + 'by' => true, |
|
101 | + 'self' => true, |
|
102 | + ); |
|
103 | + |
|
104 | + /** @var array list of type icons "type" => "css class" */ |
|
105 | + protected $typeIcons = array(); |
|
106 | + |
|
107 | + /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
108 | + protected $specialParameters = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * @return \OCP\Activity\IConsumer[] |
|
112 | + */ |
|
113 | + protected function getConsumers() { |
|
114 | + if (!empty($this->consumers)) { |
|
115 | + return $this->consumers; |
|
116 | + } |
|
117 | + |
|
118 | + $this->consumers = []; |
|
119 | + foreach($this->consumersClosures as $consumer) { |
|
120 | + $c = $consumer(); |
|
121 | + if ($c instanceof IConsumer) { |
|
122 | + $this->consumers[] = $c; |
|
123 | + } else { |
|
124 | + throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + return $this->consumers; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return \OCP\Activity\IExtension[] |
|
133 | + */ |
|
134 | + protected function getExtensions() { |
|
135 | + if (!empty($this->extensions)) { |
|
136 | + return $this->extensions; |
|
137 | + } |
|
138 | + |
|
139 | + $this->extensions = []; |
|
140 | + foreach($this->extensionsClosures as $extension) { |
|
141 | + $e = $extension(); |
|
142 | + if ($e instanceof IExtension) { |
|
143 | + $this->extensions[] = $e; |
|
144 | + } else { |
|
145 | + throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + return $this->extensions; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Generates a new IEvent object |
|
154 | + * |
|
155 | + * Make sure to call at least the following methods before sending it to the |
|
156 | + * app with via the publish() method: |
|
157 | + * - setApp() |
|
158 | + * - setType() |
|
159 | + * - setAffectedUser() |
|
160 | + * - setSubject() |
|
161 | + * |
|
162 | + * @return IEvent |
|
163 | + */ |
|
164 | + public function generateEvent() { |
|
165 | + return new Event($this->validator); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Publish an event to the activity consumers |
|
170 | + * |
|
171 | + * Make sure to call at least the following methods before sending an Event: |
|
172 | + * - setApp() |
|
173 | + * - setType() |
|
174 | + * - setAffectedUser() |
|
175 | + * - setSubject() |
|
176 | + * |
|
177 | + * @param IEvent $event |
|
178 | + * @throws \BadMethodCallException if required values have not been set |
|
179 | + */ |
|
180 | + public function publish(IEvent $event) { |
|
181 | + if ($event->getAuthor() === '') { |
|
182 | + if ($this->session->getUser() instanceof IUser) { |
|
183 | + $event->setAuthor($this->session->getUser()->getUID()); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + if (!$event->getTimestamp()) { |
|
188 | + $event->setTimestamp(time()); |
|
189 | + } |
|
190 | + |
|
191 | + if (!$event->isValid()) { |
|
192 | + throw new \BadMethodCallException('The given event is invalid'); |
|
193 | + } |
|
194 | + |
|
195 | + foreach ($this->getConsumers() as $c) { |
|
196 | + $c->receive($event); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $app The app where this event is associated with |
|
202 | + * @param string $subject A short description of the event |
|
203 | + * @param array $subjectParams Array with parameters that are filled in the subject |
|
204 | + * @param string $message A longer description of the event |
|
205 | + * @param array $messageParams Array with parameters that are filled in the message |
|
206 | + * @param string $file The file including path where this event is associated with |
|
207 | + * @param string $link A link where this event is associated with |
|
208 | + * @param string $affectedUser Recipient of the activity |
|
209 | + * @param string $type Type of the notification |
|
210 | + * @param int $priority Priority of the notification |
|
211 | + */ |
|
212 | + public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
213 | + $event = $this->generateEvent(); |
|
214 | + $event->setApp($app) |
|
215 | + ->setType($type) |
|
216 | + ->setAffectedUser($affectedUser) |
|
217 | + ->setSubject($subject, $subjectParams) |
|
218 | + ->setMessage($message, $messageParams) |
|
219 | + ->setObject('', 0, $file) |
|
220 | + ->setLink($link); |
|
221 | + |
|
222 | + $this->publish($event); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
227 | + * activity consumers are actually requested |
|
228 | + * |
|
229 | + * $callable has to return an instance of OCA\Activity\IConsumer |
|
230 | + * |
|
231 | + * @param \Closure $callable |
|
232 | + */ |
|
233 | + public function registerConsumer(\Closure $callable) { |
|
234 | + $this->consumersClosures[] = $callable; |
|
235 | + $this->consumers = []; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
240 | + * activity consumers are actually requested |
|
241 | + * |
|
242 | + * $callable has to return an instance of OCA\Activity\IExtension |
|
243 | + * |
|
244 | + * @param \Closure $callable |
|
245 | + */ |
|
246 | + public function registerExtension(\Closure $callable) { |
|
247 | + $this->extensionsClosures[] = $callable; |
|
248 | + $this->extensions = []; |
|
249 | + } |
|
250 | + |
|
251 | + /** @var string[] */ |
|
252 | + protected $filterClasses = []; |
|
253 | + |
|
254 | + /** @var IFilter[] */ |
|
255 | + protected $filters = []; |
|
256 | + |
|
257 | + /** @var bool */ |
|
258 | + protected $loadedLegacyFilters = false; |
|
259 | + |
|
260 | + /** |
|
261 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
262 | + * @return void |
|
263 | + */ |
|
264 | + public function registerFilter($filter) { |
|
265 | + $this->filterClasses[$filter] = false; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return IFilter[] |
|
270 | + * @throws \InvalidArgumentException |
|
271 | + */ |
|
272 | + public function getFilters() { |
|
273 | + if (!$this->loadedLegacyFilters) { |
|
274 | + $legacyFilters = $this->getNavigation(); |
|
275 | + |
|
276 | + foreach ($legacyFilters['top'] as $filter => $data) { |
|
277 | + $this->filters[$filter] = new LegacyFilter( |
|
278 | + $this, $filter, $data['name'], true |
|
279 | + ); |
|
280 | + } |
|
281 | + |
|
282 | + foreach ($legacyFilters['apps'] as $filter => $data) { |
|
283 | + $this->filters[$filter] = new LegacyFilter( |
|
284 | + $this, $filter, $data['name'], false |
|
285 | + ); |
|
286 | + } |
|
287 | + $this->loadedLegacyFilters = true; |
|
288 | + } |
|
289 | + |
|
290 | + foreach ($this->filterClasses as $class => $false) { |
|
291 | + /** @var IFilter $filter */ |
|
292 | + $filter = \OC::$server->query($class); |
|
293 | + |
|
294 | + if (!$filter instanceof IFilter) { |
|
295 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
296 | + } |
|
297 | + |
|
298 | + $this->filters[$filter->getIdentifier()] = $filter; |
|
299 | + |
|
300 | + unset($this->filterClasses[$class]); |
|
301 | + } |
|
302 | + return $this->filters; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * @param string $id |
|
307 | + * @return IFilter |
|
308 | + * @throws \InvalidArgumentException when the filter was not found |
|
309 | + * @since 11.0.0 |
|
310 | + */ |
|
311 | + public function getFilterById($id) { |
|
312 | + $filters = $this->getFilters(); |
|
313 | + |
|
314 | + if (isset($filters[$id])) { |
|
315 | + return $filters[$id]; |
|
316 | + } |
|
317 | + |
|
318 | + throw new \InvalidArgumentException('Requested filter does not exist'); |
|
319 | + } |
|
320 | + |
|
321 | + /** @var string[] */ |
|
322 | + protected $providerClasses = []; |
|
323 | + |
|
324 | + /** @var IProvider[] */ |
|
325 | + protected $providers = []; |
|
326 | + |
|
327 | + /** |
|
328 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
329 | + * @return void |
|
330 | + */ |
|
331 | + public function registerProvider($provider) { |
|
332 | + $this->providerClasses[$provider] = false; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * @return IProvider[] |
|
337 | + * @throws \InvalidArgumentException |
|
338 | + */ |
|
339 | + public function getProviders() { |
|
340 | + foreach ($this->providerClasses as $class => $false) { |
|
341 | + /** @var IProvider $provider */ |
|
342 | + $provider = \OC::$server->query($class); |
|
343 | + |
|
344 | + if (!$provider instanceof IProvider) { |
|
345 | + throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
346 | + } |
|
347 | + |
|
348 | + $this->providers[] = $provider; |
|
349 | + |
|
350 | + unset($this->providerClasses[$class]); |
|
351 | + } |
|
352 | + return $this->providers; |
|
353 | + } |
|
354 | + |
|
355 | + /** @var string[] */ |
|
356 | + protected $settingsClasses = []; |
|
357 | + |
|
358 | + /** @var ISetting[] */ |
|
359 | + protected $settings = []; |
|
360 | + |
|
361 | + /** @var bool */ |
|
362 | + protected $loadedLegacyTypes = false; |
|
363 | + |
|
364 | + /** |
|
365 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
366 | + * @return void |
|
367 | + */ |
|
368 | + public function registerSetting($setting) { |
|
369 | + $this->settingsClasses[$setting] = false; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @return ISetting[] |
|
374 | + * @throws \InvalidArgumentException |
|
375 | + */ |
|
376 | + public function getSettings() { |
|
377 | + if (!$this->loadedLegacyTypes) { |
|
378 | + $l = \OC::$server->getL10N('core'); |
|
379 | + $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
380 | + $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
381 | + $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
382 | + foreach ($legacyTypes as $type => $data) { |
|
383 | + if (is_string($data)) { |
|
384 | + $desc = $data; |
|
385 | + $canChangeStream = true; |
|
386 | + $canChangeMail = true; |
|
387 | + } else { |
|
388 | + $desc = $data['desc']; |
|
389 | + $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
390 | + $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
391 | + } |
|
392 | + |
|
393 | + $this->settings[$type] = new LegacySetting( |
|
394 | + $type, $desc, |
|
395 | + $canChangeStream, in_array($type, $streamTypes), |
|
396 | + $canChangeMail, in_array($type, $mailTypes) |
|
397 | + ); |
|
398 | + } |
|
399 | + $this->loadedLegacyTypes = true; |
|
400 | + } |
|
401 | + |
|
402 | + foreach ($this->settingsClasses as $class => $false) { |
|
403 | + /** @var ISetting $setting */ |
|
404 | + $setting = \OC::$server->query($class); |
|
405 | + |
|
406 | + if (!$setting instanceof ISetting) { |
|
407 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
408 | + } |
|
409 | + |
|
410 | + $this->settings[$setting->getIdentifier()] = $setting; |
|
411 | + |
|
412 | + unset($this->settingsClasses[$class]); |
|
413 | + } |
|
414 | + return $this->settings; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * @param string $id |
|
419 | + * @return ISetting |
|
420 | + * @throws \InvalidArgumentException when the setting was not found |
|
421 | + * @since 11.0.0 |
|
422 | + */ |
|
423 | + public function getSettingById($id) { |
|
424 | + $settings = $this->getSettings(); |
|
425 | + |
|
426 | + if (isset($settings[$id])) { |
|
427 | + return $settings[$id]; |
|
428 | + } |
|
429 | + |
|
430 | + throw new \InvalidArgumentException('Requested setting does not exist'); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @param string $type |
|
435 | + * @return string |
|
436 | + */ |
|
437 | + public function getTypeIcon($type) { |
|
438 | + if (isset($this->typeIcons[$type])) { |
|
439 | + return $this->typeIcons[$type]; |
|
440 | + } |
|
441 | + |
|
442 | + foreach ($this->getExtensions() as $c) { |
|
443 | + $icon = $c->getTypeIcon($type); |
|
444 | + if (is_string($icon)) { |
|
445 | + $this->typeIcons[$type] = $icon; |
|
446 | + return $icon; |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + $this->typeIcons[$type] = ''; |
|
451 | + return ''; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * @param string $type |
|
456 | + * @param string $id |
|
457 | + */ |
|
458 | + public function setFormattingObject($type, $id) { |
|
459 | + $this->formattingObjectType = $type; |
|
460 | + $this->formattingObjectId = (string) $id; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * @return bool |
|
465 | + */ |
|
466 | + public function isFormattingFilteredObject() { |
|
467 | + return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
468 | + && $this->formattingObjectType === $this->request->getParam('object_type') |
|
469 | + && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
474 | + */ |
|
475 | + public function setRequirePNG($status) { |
|
476 | + $this->requirePNG = $status; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @return bool |
|
481 | + */ |
|
482 | + public function getRequirePNG() { |
|
483 | + return $this->requirePNG; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * @param string $app |
|
488 | + * @param string $text |
|
489 | + * @param array $params |
|
490 | + * @param boolean $stripPath |
|
491 | + * @param boolean $highlightParams |
|
492 | + * @param string $languageCode |
|
493 | + * @return string|false |
|
494 | + */ |
|
495 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
496 | + foreach ($this->getExtensions() as $c) { |
|
497 | + $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
498 | + if (is_string($translation)) { |
|
499 | + return $translation; |
|
500 | + } |
|
501 | + } |
|
502 | + |
|
503 | + return false; |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * @param string $app |
|
508 | + * @param string $text |
|
509 | + * @return array|false |
|
510 | + */ |
|
511 | + public function getSpecialParameterList($app, $text) { |
|
512 | + if (isset($this->specialParameters[$app][$text])) { |
|
513 | + return $this->specialParameters[$app][$text]; |
|
514 | + } |
|
515 | + |
|
516 | + if (!isset($this->specialParameters[$app])) { |
|
517 | + $this->specialParameters[$app] = array(); |
|
518 | + } |
|
519 | + |
|
520 | + foreach ($this->getExtensions() as $c) { |
|
521 | + $specialParameter = $c->getSpecialParameterList($app, $text); |
|
522 | + if (is_array($specialParameter)) { |
|
523 | + $this->specialParameters[$app][$text] = $specialParameter; |
|
524 | + return $specialParameter; |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + $this->specialParameters[$app][$text] = false; |
|
529 | + return false; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * @param array $activity |
|
534 | + * @return integer|false |
|
535 | + */ |
|
536 | + public function getGroupParameter($activity) { |
|
537 | + foreach ($this->getExtensions() as $c) { |
|
538 | + $parameter = $c->getGroupParameter($activity); |
|
539 | + if ($parameter !== false) { |
|
540 | + return $parameter; |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + return false; |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Set the user we need to use |
|
549 | + * |
|
550 | + * @param string|null $currentUserId |
|
551 | + * @throws \UnexpectedValueException If the user is invalid |
|
552 | + */ |
|
553 | + public function setCurrentUserId($currentUserId) { |
|
554 | + if (!is_string($currentUserId) && $currentUserId !== null) { |
|
555 | + throw new \UnexpectedValueException('The given current user is invalid'); |
|
556 | + } |
|
557 | + $this->currentUserId = $currentUserId; |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Get the user we need to use |
|
562 | + * |
|
563 | + * Either the user is logged in, or we try to get it from the token |
|
564 | + * |
|
565 | + * @return string |
|
566 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
567 | + */ |
|
568 | + public function getCurrentUserId() { |
|
569 | + if ($this->currentUserId !== null) { |
|
570 | + return $this->currentUserId; |
|
571 | + } else if (!$this->session->isLoggedIn()) { |
|
572 | + return $this->getUserFromToken(); |
|
573 | + } else { |
|
574 | + return $this->session->getUser()->getUID(); |
|
575 | + } |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Get the user for the token |
|
580 | + * |
|
581 | + * @return string |
|
582 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
583 | + */ |
|
584 | + protected function getUserFromToken() { |
|
585 | + $token = (string) $this->request->getParam('token', ''); |
|
586 | + if (strlen($token) !== 30) { |
|
587 | + throw new \UnexpectedValueException('The token is invalid'); |
|
588 | + } |
|
589 | + |
|
590 | + $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
591 | + |
|
592 | + if (count($users) !== 1) { |
|
593 | + // No unique user found |
|
594 | + throw new \UnexpectedValueException('The token is invalid'); |
|
595 | + } |
|
596 | + |
|
597 | + // Token found login as that user |
|
598 | + return array_shift($users); |
|
599 | + } |
|
600 | + |
|
601 | + /** |
|
602 | + * @return array |
|
603 | + * @deprecated 11.0.0 - Use getFilters() instead |
|
604 | + */ |
|
605 | + public function getNavigation() { |
|
606 | + $entries = array( |
|
607 | + 'apps' => array(), |
|
608 | + 'top' => array(), |
|
609 | + ); |
|
610 | + foreach ($this->getExtensions() as $c) { |
|
611 | + $additionalEntries = $c->getNavigation(); |
|
612 | + if (is_array($additionalEntries)) { |
|
613 | + $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
614 | + $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
615 | + } |
|
616 | + } |
|
617 | + |
|
618 | + return $entries; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * @param string $filterValue |
|
623 | + * @return boolean |
|
624 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
625 | + */ |
|
626 | + public function isFilterValid($filterValue) { |
|
627 | + if (isset($this->validFilters[$filterValue])) { |
|
628 | + return $this->validFilters[$filterValue]; |
|
629 | + } |
|
630 | + |
|
631 | + foreach ($this->getExtensions() as $c) { |
|
632 | + if ($c->isFilterValid($filterValue) === true) { |
|
633 | + $this->validFilters[$filterValue] = true; |
|
634 | + return true; |
|
635 | + } |
|
636 | + } |
|
637 | + |
|
638 | + $this->validFilters[$filterValue] = false; |
|
639 | + return false; |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * @param array $types |
|
644 | + * @param string $filter |
|
645 | + * @return array |
|
646 | + * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
647 | + */ |
|
648 | + public function filterNotificationTypes($types, $filter) { |
|
649 | + if (!$this->isFilterValid($filter)) { |
|
650 | + return $types; |
|
651 | + } |
|
652 | + |
|
653 | + foreach ($this->getExtensions() as $c) { |
|
654 | + $result = $c->filterNotificationTypes($types, $filter); |
|
655 | + if (is_array($result)) { |
|
656 | + $types = $result; |
|
657 | + } |
|
658 | + } |
|
659 | + return $types; |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * @param string $filter |
|
664 | + * @return array |
|
665 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
666 | + */ |
|
667 | + public function getQueryForFilter($filter) { |
|
668 | + if (!$this->isFilterValid($filter)) { |
|
669 | + return [null, null]; |
|
670 | + } |
|
671 | + |
|
672 | + $conditions = array(); |
|
673 | + $parameters = array(); |
|
674 | + |
|
675 | + foreach ($this->getExtensions() as $c) { |
|
676 | + $result = $c->getQueryForFilter($filter); |
|
677 | + if (is_array($result)) { |
|
678 | + list($condition, $parameter) = $result; |
|
679 | + if ($condition && is_array($parameter)) { |
|
680 | + $conditions[] = $condition; |
|
681 | + $parameters = array_merge($parameters, $parameter); |
|
682 | + } |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + if (empty($conditions)) { |
|
687 | + return array(null, null); |
|
688 | + } |
|
689 | + |
|
690 | + return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Will return additional notification types as specified by other apps |
|
695 | + * |
|
696 | + * @param string $languageCode |
|
697 | + * @return array |
|
698 | + * @deprecated 11.0.0 - Use getSettings() instead |
|
699 | + */ |
|
700 | + public function getNotificationTypes($languageCode) { |
|
701 | + $notificationTypes = $sharingNotificationTypes = []; |
|
702 | + foreach ($this->getExtensions() as $c) { |
|
703 | + $result = $c->getNotificationTypes($languageCode); |
|
704 | + if (is_array($result)) { |
|
705 | + $notificationTypes = array_merge($notificationTypes, $result); |
|
706 | + } |
|
707 | + } |
|
708 | + |
|
709 | + return array_merge($sharingNotificationTypes, $notificationTypes); |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * @param string $method |
|
714 | + * @return array |
|
715 | + * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
716 | + */ |
|
717 | + public function getDefaultTypes($method) { |
|
718 | + $defaultTypes = array(); |
|
719 | + foreach ($this->getExtensions() as $c) { |
|
720 | + $types = $c->getDefaultTypes($method); |
|
721 | + if (is_array($types)) { |
|
722 | + $defaultTypes = array_merge($types, $defaultTypes); |
|
723 | + } |
|
724 | + } |
|
725 | + return $defaultTypes; |
|
726 | + } |
|
727 | 727 | } |
@@ -25,99 +25,99 @@ |
||
25 | 25 | |
26 | 26 | class LegacySetting implements ISetting { |
27 | 27 | |
28 | - /** @var string */ |
|
29 | - protected $identifier; |
|
30 | - /** @var string */ |
|
31 | - protected $name; |
|
32 | - /** @var bool */ |
|
33 | - protected $canChangeStream; |
|
34 | - /** @var bool */ |
|
35 | - protected $isDefaultEnabledStream; |
|
36 | - /** @var bool */ |
|
37 | - protected $canChangeMail; |
|
38 | - /** @var bool */ |
|
39 | - protected $isDefaultEnabledMail; |
|
28 | + /** @var string */ |
|
29 | + protected $identifier; |
|
30 | + /** @var string */ |
|
31 | + protected $name; |
|
32 | + /** @var bool */ |
|
33 | + protected $canChangeStream; |
|
34 | + /** @var bool */ |
|
35 | + protected $isDefaultEnabledStream; |
|
36 | + /** @var bool */ |
|
37 | + protected $canChangeMail; |
|
38 | + /** @var bool */ |
|
39 | + protected $isDefaultEnabledMail; |
|
40 | 40 | |
41 | - /** |
|
42 | - * LegacySetting constructor. |
|
43 | - * |
|
44 | - * @param string $identifier |
|
45 | - * @param string $name |
|
46 | - * @param bool $canChangeStream |
|
47 | - * @param bool $isDefaultEnabledStream |
|
48 | - * @param bool $canChangeMail |
|
49 | - * @param bool $isDefaultEnabledMail |
|
50 | - */ |
|
51 | - public function __construct($identifier, |
|
52 | - $name, |
|
53 | - $canChangeStream, |
|
54 | - $isDefaultEnabledStream, |
|
55 | - $canChangeMail, |
|
56 | - $isDefaultEnabledMail) { |
|
57 | - $this->identifier = $identifier; |
|
58 | - $this->name = $name; |
|
59 | - $this->canChangeStream = $canChangeStream; |
|
60 | - $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
61 | - $this->canChangeMail = $canChangeMail; |
|
62 | - $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
63 | - } |
|
41 | + /** |
|
42 | + * LegacySetting constructor. |
|
43 | + * |
|
44 | + * @param string $identifier |
|
45 | + * @param string $name |
|
46 | + * @param bool $canChangeStream |
|
47 | + * @param bool $isDefaultEnabledStream |
|
48 | + * @param bool $canChangeMail |
|
49 | + * @param bool $isDefaultEnabledMail |
|
50 | + */ |
|
51 | + public function __construct($identifier, |
|
52 | + $name, |
|
53 | + $canChangeStream, |
|
54 | + $isDefaultEnabledStream, |
|
55 | + $canChangeMail, |
|
56 | + $isDefaultEnabledMail) { |
|
57 | + $this->identifier = $identifier; |
|
58 | + $this->name = $name; |
|
59 | + $this->canChangeStream = $canChangeStream; |
|
60 | + $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
61 | + $this->canChangeMail = $canChangeMail; |
|
62 | + $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return string Lowercase a-z and underscore only identifier |
|
67 | - * @since 11.0.0 |
|
68 | - */ |
|
69 | - public function getIdentifier() { |
|
70 | - return $this->identifier; |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return string Lowercase a-z and underscore only identifier |
|
67 | + * @since 11.0.0 |
|
68 | + */ |
|
69 | + public function getIdentifier() { |
|
70 | + return $this->identifier; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return string A translated string |
|
75 | - * @since 11.0.0 |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
73 | + /** |
|
74 | + * @return string A translated string |
|
75 | + * @since 11.0.0 |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return int whether the filter should be rather on the top or bottom of |
|
83 | - * the admin section. The filters are arranged in ascending order of the |
|
84 | - * priority values. It is required to return a value between 0 and 100. |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function getPriority() { |
|
88 | - return 70; |
|
89 | - } |
|
81 | + /** |
|
82 | + * @return int whether the filter should be rather on the top or bottom of |
|
83 | + * the admin section. The filters are arranged in ascending order of the |
|
84 | + * priority values. It is required to return a value between 0 and 100. |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function getPriority() { |
|
88 | + return 70; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return bool True when the option can be changed for the stream |
|
93 | - * @since 11.0.0 |
|
94 | - */ |
|
95 | - public function canChangeStream() { |
|
96 | - return $this->canChangeStream; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return bool True when the option can be changed for the stream |
|
93 | + * @since 11.0.0 |
|
94 | + */ |
|
95 | + public function canChangeStream() { |
|
96 | + return $this->canChangeStream; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return bool True when the option can be changed for the stream |
|
101 | - * @since 11.0.0 |
|
102 | - */ |
|
103 | - public function isDefaultEnabledStream() { |
|
104 | - return $this->isDefaultEnabledStream; |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return bool True when the option can be changed for the stream |
|
101 | + * @since 11.0.0 |
|
102 | + */ |
|
103 | + public function isDefaultEnabledStream() { |
|
104 | + return $this->isDefaultEnabledStream; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return bool True when the option can be changed for the mail |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function canChangeMail() { |
|
112 | - return $this->canChangeMail; |
|
113 | - } |
|
107 | + /** |
|
108 | + * @return bool True when the option can be changed for the mail |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function canChangeMail() { |
|
112 | + return $this->canChangeMail; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return bool True when the option can be changed for the stream |
|
117 | - * @since 11.0.0 |
|
118 | - */ |
|
119 | - public function isDefaultEnabledMail() { |
|
120 | - return $this->isDefaultEnabledMail; |
|
121 | - } |
|
115 | + /** |
|
116 | + * @return bool True when the option can be changed for the stream |
|
117 | + * @since 11.0.0 |
|
118 | + */ |
|
119 | + public function isDefaultEnabledMail() { |
|
120 | + return $this->isDefaultEnabledMail; |
|
121 | + } |
|
122 | 122 | } |
123 | 123 |
@@ -29,52 +29,52 @@ |
||
29 | 29 | * @package OC\Security\CSP |
30 | 30 | */ |
31 | 31 | class ContentSecurityPolicyNonceManager { |
32 | - /** @var CsrfTokenManager */ |
|
33 | - private $csrfTokenManager; |
|
34 | - /** @var IRequest */ |
|
35 | - private $request; |
|
36 | - /** @var string */ |
|
37 | - private $nonce = ''; |
|
32 | + /** @var CsrfTokenManager */ |
|
33 | + private $csrfTokenManager; |
|
34 | + /** @var IRequest */ |
|
35 | + private $request; |
|
36 | + /** @var string */ |
|
37 | + private $nonce = ''; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param CsrfTokenManager $csrfTokenManager |
|
41 | - * @param IRequest $request |
|
42 | - */ |
|
43 | - public function __construct(CsrfTokenManager $csrfTokenManager, |
|
44 | - IRequest $request) { |
|
45 | - $this->csrfTokenManager = $csrfTokenManager; |
|
46 | - $this->request = $request; |
|
47 | - } |
|
39 | + /** |
|
40 | + * @param CsrfTokenManager $csrfTokenManager |
|
41 | + * @param IRequest $request |
|
42 | + */ |
|
43 | + public function __construct(CsrfTokenManager $csrfTokenManager, |
|
44 | + IRequest $request) { |
|
45 | + $this->csrfTokenManager = $csrfTokenManager; |
|
46 | + $this->request = $request; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Returns the current CSP nounce |
|
51 | - * |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getNonce() { |
|
55 | - if($this->nonce === '') { |
|
56 | - $this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
57 | - } |
|
49 | + /** |
|
50 | + * Returns the current CSP nounce |
|
51 | + * |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getNonce() { |
|
55 | + if($this->nonce === '') { |
|
56 | + $this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue()); |
|
57 | + } |
|
58 | 58 | |
59 | - return $this->nonce; |
|
60 | - } |
|
59 | + return $this->nonce; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Check if the browser supports CSP v3 |
|
64 | - * |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - public function browserSupportsCspV3() { |
|
68 | - $browserWhitelist = [ |
|
69 | - Request::USER_AGENT_CHROME, |
|
70 | - // Firefox 45+ |
|
71 | - '/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/', |
|
72 | - ]; |
|
62 | + /** |
|
63 | + * Check if the browser supports CSP v3 |
|
64 | + * |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + public function browserSupportsCspV3() { |
|
68 | + $browserWhitelist = [ |
|
69 | + Request::USER_AGENT_CHROME, |
|
70 | + // Firefox 45+ |
|
71 | + '/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/', |
|
72 | + ]; |
|
73 | 73 | |
74 | - if($this->request->isUserAgent($browserWhitelist)) { |
|
75 | - return true; |
|
76 | - } |
|
74 | + if($this->request->isUserAgent($browserWhitelist)) { |
|
75 | + return true; |
|
76 | + } |
|
77 | 77 | |
78 | - return false; |
|
79 | - } |
|
78 | + return false; |
|
79 | + } |
|
80 | 80 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @return string |
53 | 53 | */ |
54 | 54 | public function getNonce() { |
55 | - if($this->nonce === '') { |
|
55 | + if ($this->nonce === '') { |
|
56 | 56 | $this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue()); |
57 | 57 | } |
58 | 58 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | '/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/', |
72 | 72 | ]; |
73 | 73 | |
74 | - if($this->request->isUserAgent($browserWhitelist)) { |
|
74 | + if ($this->request->isUserAgent($browserWhitelist)) { |
|
75 | 75 | return true; |
76 | 76 | } |
77 | 77 |
@@ -27,48 +27,48 @@ |
||
27 | 27 | use OCP\Security\IContentSecurityPolicyManager; |
28 | 28 | |
29 | 29 | class ContentSecurityPolicyManager implements IContentSecurityPolicyManager { |
30 | - /** @var ContentSecurityPolicy[] */ |
|
31 | - private $policies = []; |
|
30 | + /** @var ContentSecurityPolicy[] */ |
|
31 | + private $policies = []; |
|
32 | 32 | |
33 | - /** {@inheritdoc} */ |
|
34 | - public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) { |
|
35 | - $this->policies[] = $policy; |
|
36 | - } |
|
33 | + /** {@inheritdoc} */ |
|
34 | + public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) { |
|
35 | + $this->policies[] = $policy; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the configured default policy. This is not in the public namespace |
|
40 | - * as it is only supposed to be used by core itself. |
|
41 | - * |
|
42 | - * @return ContentSecurityPolicy |
|
43 | - */ |
|
44 | - public function getDefaultPolicy() { |
|
45 | - $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
|
46 | - foreach($this->policies as $policy) { |
|
47 | - $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
48 | - } |
|
49 | - return $defaultPolicy; |
|
50 | - } |
|
38 | + /** |
|
39 | + * Get the configured default policy. This is not in the public namespace |
|
40 | + * as it is only supposed to be used by core itself. |
|
41 | + * |
|
42 | + * @return ContentSecurityPolicy |
|
43 | + */ |
|
44 | + public function getDefaultPolicy() { |
|
45 | + $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
|
46 | + foreach($this->policies as $policy) { |
|
47 | + $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
48 | + } |
|
49 | + return $defaultPolicy; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Merges the first given policy with the second one |
|
54 | - * |
|
55 | - * @param ContentSecurityPolicy $defaultPolicy |
|
56 | - * @param EmptyContentSecurityPolicy $originalPolicy |
|
57 | - * @return ContentSecurityPolicy |
|
58 | - */ |
|
59 | - public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
|
60 | - EmptyContentSecurityPolicy $originalPolicy) { |
|
61 | - foreach((object)(array)$originalPolicy as $name => $value) { |
|
62 | - $setter = 'set'.ucfirst($name); |
|
63 | - if(is_array($value)) { |
|
64 | - $getter = 'get'.ucfirst($name); |
|
65 | - $currentValues = is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
66 | - $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
|
67 | - } elseif (is_bool($value)) { |
|
68 | - $defaultPolicy->$setter($value); |
|
69 | - } |
|
70 | - } |
|
52 | + /** |
|
53 | + * Merges the first given policy with the second one |
|
54 | + * |
|
55 | + * @param ContentSecurityPolicy $defaultPolicy |
|
56 | + * @param EmptyContentSecurityPolicy $originalPolicy |
|
57 | + * @return ContentSecurityPolicy |
|
58 | + */ |
|
59 | + public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
|
60 | + EmptyContentSecurityPolicy $originalPolicy) { |
|
61 | + foreach((object)(array)$originalPolicy as $name => $value) { |
|
62 | + $setter = 'set'.ucfirst($name); |
|
63 | + if(is_array($value)) { |
|
64 | + $getter = 'get'.ucfirst($name); |
|
65 | + $currentValues = is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
66 | + $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
|
67 | + } elseif (is_bool($value)) { |
|
68 | + $defaultPolicy->$setter($value); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - return $defaultPolicy; |
|
73 | - } |
|
72 | + return $defaultPolicy; |
|
73 | + } |
|
74 | 74 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getDefaultPolicy() { |
45 | 45 | $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy(); |
46 | - foreach($this->policies as $policy) { |
|
46 | + foreach ($this->policies as $policy) { |
|
47 | 47 | $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
48 | 48 | } |
49 | 49 | return $defaultPolicy; |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function mergePolicies(ContentSecurityPolicy $defaultPolicy, |
60 | 60 | EmptyContentSecurityPolicy $originalPolicy) { |
61 | - foreach((object)(array)$originalPolicy as $name => $value) { |
|
61 | + foreach ((object) (array) $originalPolicy as $name => $value) { |
|
62 | 62 | $setter = 'set'.ucfirst($name); |
63 | - if(is_array($value)) { |
|
63 | + if (is_array($value)) { |
|
64 | 64 | $getter = 'get'.ucfirst($name); |
65 | 65 | $currentValues = is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
66 | 66 | $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value)))); |
@@ -34,93 +34,93 @@ |
||
34 | 34 | */ |
35 | 35 | class CredentialsManager implements ICredentialsManager { |
36 | 36 | |
37 | - const DB_TABLE = 'credentials'; |
|
37 | + const DB_TABLE = 'credentials'; |
|
38 | 38 | |
39 | - /** @var ICrypto */ |
|
40 | - protected $crypto; |
|
39 | + /** @var ICrypto */ |
|
40 | + protected $crypto; |
|
41 | 41 | |
42 | - /** @var IDBConnection */ |
|
43 | - protected $dbConnection; |
|
42 | + /** @var IDBConnection */ |
|
43 | + protected $dbConnection; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param ICrypto $crypto |
|
47 | - * @param IDBConnection $dbConnection |
|
48 | - */ |
|
49 | - public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | - $this->crypto = $crypto; |
|
51 | - $this->dbConnection = $dbConnection; |
|
52 | - } |
|
45 | + /** |
|
46 | + * @param ICrypto $crypto |
|
47 | + * @param IDBConnection $dbConnection |
|
48 | + */ |
|
49 | + public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | + $this->crypto = $crypto; |
|
51 | + $this->dbConnection = $dbConnection; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Store a set of credentials |
|
56 | - * |
|
57 | - * @param string|null $userId Null for system-wide credentials |
|
58 | - * @param string $identifier |
|
59 | - * @param mixed $credentials |
|
60 | - */ |
|
61 | - public function store($userId, $identifier, $credentials) { |
|
62 | - $value = $this->crypto->encrypt(json_encode($credentials)); |
|
54 | + /** |
|
55 | + * Store a set of credentials |
|
56 | + * |
|
57 | + * @param string|null $userId Null for system-wide credentials |
|
58 | + * @param string $identifier |
|
59 | + * @param mixed $credentials |
|
60 | + */ |
|
61 | + public function store($userId, $identifier, $credentials) { |
|
62 | + $value = $this->crypto->encrypt(json_encode($credentials)); |
|
63 | 63 | |
64 | - $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | - 'user' => $userId, |
|
66 | - 'identifier' => $identifier, |
|
67 | - ], [ |
|
68 | - 'credentials' => $value, |
|
69 | - ]); |
|
70 | - } |
|
64 | + $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | + 'user' => $userId, |
|
66 | + 'identifier' => $identifier, |
|
67 | + ], [ |
|
68 | + 'credentials' => $value, |
|
69 | + ]); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Retrieve a set of credentials |
|
74 | - * |
|
75 | - * @param string|null $userId Null for system-wide credentials |
|
76 | - * @param string $identifier |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function retrieve($userId, $identifier) { |
|
80 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | - $qb->select('credentials') |
|
82 | - ->from(self::DB_TABLE) |
|
83 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | - ; |
|
86 | - $result = $qb->execute()->fetch(); |
|
72 | + /** |
|
73 | + * Retrieve a set of credentials |
|
74 | + * |
|
75 | + * @param string|null $userId Null for system-wide credentials |
|
76 | + * @param string $identifier |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function retrieve($userId, $identifier) { |
|
80 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | + $qb->select('credentials') |
|
82 | + ->from(self::DB_TABLE) |
|
83 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | + ; |
|
86 | + $result = $qb->execute()->fetch(); |
|
87 | 87 | |
88 | - if (!$result) { |
|
89 | - return null; |
|
90 | - } |
|
91 | - $value = $result['credentials']; |
|
88 | + if (!$result) { |
|
89 | + return null; |
|
90 | + } |
|
91 | + $value = $result['credentials']; |
|
92 | 92 | |
93 | - return json_decode($this->crypto->decrypt($value), true); |
|
94 | - } |
|
93 | + return json_decode($this->crypto->decrypt($value), true); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Delete a set of credentials |
|
98 | - * |
|
99 | - * @param string|null $userId Null for system-wide credentials |
|
100 | - * @param string $identifier |
|
101 | - * @return int rows removed |
|
102 | - */ |
|
103 | - public function delete($userId, $identifier) { |
|
104 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | - $qb->delete(self::DB_TABLE) |
|
106 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | - ; |
|
109 | - return $qb->execute(); |
|
110 | - } |
|
96 | + /** |
|
97 | + * Delete a set of credentials |
|
98 | + * |
|
99 | + * @param string|null $userId Null for system-wide credentials |
|
100 | + * @param string $identifier |
|
101 | + * @return int rows removed |
|
102 | + */ |
|
103 | + public function delete($userId, $identifier) { |
|
104 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | + $qb->delete(self::DB_TABLE) |
|
106 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | + ; |
|
109 | + return $qb->execute(); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Erase all credentials stored for a user |
|
114 | - * |
|
115 | - * @param string $userId |
|
116 | - * @return int rows removed |
|
117 | - */ |
|
118 | - public function erase($userId) { |
|
119 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | - $qb->delete(self::DB_TABLE) |
|
121 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | - ; |
|
123 | - return $qb->execute(); |
|
124 | - } |
|
112 | + /** |
|
113 | + * Erase all credentials stored for a user |
|
114 | + * |
|
115 | + * @param string $userId |
|
116 | + * @return int rows removed |
|
117 | + */ |
|
118 | + public function erase($userId) { |
|
119 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | + $qb->delete(self::DB_TABLE) |
|
121 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | + ; |
|
123 | + return $qb->execute(); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -50,9 +50,9 @@ |
||
50 | 50 | * @return string |
51 | 51 | */ |
52 | 52 | public function getEncryptedValue() { |
53 | - if($this->encryptedValue === '') { |
|
53 | + if ($this->encryptedValue === '') { |
|
54 | 54 | $sharedSecret = random_bytes(strlen($this->value)); |
55 | - $this->encryptedValue = base64_encode($this->value ^ $sharedSecret) . ':' . base64_encode($sharedSecret); |
|
55 | + $this->encryptedValue = base64_encode($this->value ^ $sharedSecret).':'.base64_encode($sharedSecret); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return $this->encryptedValue; |
@@ -31,46 +31,46 @@ |
||
31 | 31 | * @package OC\Security\CSRF |
32 | 32 | */ |
33 | 33 | class CsrfToken { |
34 | - /** @var string */ |
|
35 | - private $value; |
|
36 | - /** @var string */ |
|
37 | - private $encryptedValue = ''; |
|
34 | + /** @var string */ |
|
35 | + private $value; |
|
36 | + /** @var string */ |
|
37 | + private $encryptedValue = ''; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $value Value of the token. Can be encrypted or not encrypted. |
|
41 | - */ |
|
42 | - public function __construct($value) { |
|
43 | - $this->value = $value; |
|
44 | - } |
|
39 | + /** |
|
40 | + * @param string $value Value of the token. Can be encrypted or not encrypted. |
|
41 | + */ |
|
42 | + public function __construct($value) { |
|
43 | + $this->value = $value; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Encrypted value of the token. This is used to mitigate BREACH alike |
|
48 | - * vulnerabilities. For display measures do use this functionality. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function getEncryptedValue() { |
|
53 | - if($this->encryptedValue === '') { |
|
54 | - $sharedSecret = random_bytes(strlen($this->value)); |
|
55 | - $this->encryptedValue = base64_encode($this->value ^ $sharedSecret) . ':' . base64_encode($sharedSecret); |
|
56 | - } |
|
46 | + /** |
|
47 | + * Encrypted value of the token. This is used to mitigate BREACH alike |
|
48 | + * vulnerabilities. For display measures do use this functionality. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function getEncryptedValue() { |
|
53 | + if($this->encryptedValue === '') { |
|
54 | + $sharedSecret = random_bytes(strlen($this->value)); |
|
55 | + $this->encryptedValue = base64_encode($this->value ^ $sharedSecret) . ':' . base64_encode($sharedSecret); |
|
56 | + } |
|
57 | 57 | |
58 | - return $this->encryptedValue; |
|
59 | - } |
|
58 | + return $this->encryptedValue; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * The unencrypted value of the token. Used for decrypting an already |
|
63 | - * encrypted token. |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getDecryptedValue() { |
|
68 | - $token = explode(':', $this->value); |
|
69 | - if (count($token) !== 2) { |
|
70 | - return ''; |
|
71 | - } |
|
72 | - $obfuscatedToken = $token[0]; |
|
73 | - $secret = $token[1]; |
|
74 | - return base64_decode($obfuscatedToken) ^ base64_decode($secret); |
|
75 | - } |
|
61 | + /** |
|
62 | + * The unencrypted value of the token. Used for decrypting an already |
|
63 | + * encrypted token. |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getDecryptedValue() { |
|
68 | + $token = explode(':', $this->value); |
|
69 | + if (count($token) !== 2) { |
|
70 | + return ''; |
|
71 | + } |
|
72 | + $obfuscatedToken = $token[0]; |
|
73 | + $secret = $token[1]; |
|
74 | + return base64_decode($obfuscatedToken) ^ base64_decode($secret); |
|
75 | + } |
|
76 | 76 | } |
@@ -30,59 +30,59 @@ |
||
30 | 30 | * @package OC\Security\CSRF\TokenStorage |
31 | 31 | */ |
32 | 32 | class SessionStorage { |
33 | - /** @var ISession */ |
|
34 | - private $session; |
|
33 | + /** @var ISession */ |
|
34 | + private $session; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param ISession $session |
|
38 | - */ |
|
39 | - public function __construct(ISession $session) { |
|
40 | - $this->session = $session; |
|
41 | - } |
|
36 | + /** |
|
37 | + * @param ISession $session |
|
38 | + */ |
|
39 | + public function __construct(ISession $session) { |
|
40 | + $this->session = $session; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param ISession $session |
|
45 | - */ |
|
46 | - public function setSession(ISession $session) { |
|
47 | - $this->session = $session; |
|
48 | - } |
|
43 | + /** |
|
44 | + * @param ISession $session |
|
45 | + */ |
|
46 | + public function setSession(ISession $session) { |
|
47 | + $this->session = $session; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns the current token or throws an exception if none is found. |
|
52 | - * |
|
53 | - * @return string |
|
54 | - * @throws \Exception |
|
55 | - */ |
|
56 | - public function getToken() { |
|
57 | - $token = $this->session->get('requesttoken'); |
|
58 | - if(empty($token)) { |
|
59 | - throw new \Exception('Session does not contain a requesttoken'); |
|
60 | - } |
|
50 | + /** |
|
51 | + * Returns the current token or throws an exception if none is found. |
|
52 | + * |
|
53 | + * @return string |
|
54 | + * @throws \Exception |
|
55 | + */ |
|
56 | + public function getToken() { |
|
57 | + $token = $this->session->get('requesttoken'); |
|
58 | + if(empty($token)) { |
|
59 | + throw new \Exception('Session does not contain a requesttoken'); |
|
60 | + } |
|
61 | 61 | |
62 | - return $token; |
|
63 | - } |
|
62 | + return $token; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Set the valid current token to $value. |
|
67 | - * |
|
68 | - * @param string $value |
|
69 | - */ |
|
70 | - public function setToken($value) { |
|
71 | - $this->session->set('requesttoken', $value); |
|
72 | - } |
|
65 | + /** |
|
66 | + * Set the valid current token to $value. |
|
67 | + * |
|
68 | + * @param string $value |
|
69 | + */ |
|
70 | + public function setToken($value) { |
|
71 | + $this->session->set('requesttoken', $value); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Removes the current token. |
|
76 | - */ |
|
77 | - public function removeToken() { |
|
78 | - $this->session->remove('requesttoken'); |
|
79 | - } |
|
80 | - /** |
|
81 | - * Whether the storage has a storage. |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function hasToken() { |
|
86 | - return $this->session->exists('requesttoken'); |
|
87 | - } |
|
74 | + /** |
|
75 | + * Removes the current token. |
|
76 | + */ |
|
77 | + public function removeToken() { |
|
78 | + $this->session->remove('requesttoken'); |
|
79 | + } |
|
80 | + /** |
|
81 | + * Whether the storage has a storage. |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function hasToken() { |
|
86 | + return $this->session->exists('requesttoken'); |
|
87 | + } |
|
88 | 88 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | */ |
56 | 56 | public function getToken() { |
57 | 57 | $token = $this->session->get('requesttoken'); |
58 | - if(empty($token)) { |
|
58 | + if (empty($token)) { |
|
59 | 59 | throw new \Exception('Session does not contain a requesttoken'); |
60 | 60 | } |
61 | 61 |
@@ -30,78 +30,78 @@ |
||
30 | 30 | * @package OC\Security\CSRF |
31 | 31 | */ |
32 | 32 | class CsrfTokenManager { |
33 | - /** @var CsrfTokenGenerator */ |
|
34 | - private $tokenGenerator; |
|
35 | - /** @var SessionStorage */ |
|
36 | - private $sessionStorage; |
|
37 | - /** @var CsrfToken|null */ |
|
38 | - private $csrfToken = null; |
|
33 | + /** @var CsrfTokenGenerator */ |
|
34 | + private $tokenGenerator; |
|
35 | + /** @var SessionStorage */ |
|
36 | + private $sessionStorage; |
|
37 | + /** @var CsrfToken|null */ |
|
38 | + private $csrfToken = null; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param CsrfTokenGenerator $tokenGenerator |
|
42 | - * @param SessionStorage $storageInterface |
|
43 | - */ |
|
44 | - public function __construct(CsrfTokenGenerator $tokenGenerator, |
|
45 | - SessionStorage $storageInterface) { |
|
46 | - $this->tokenGenerator = $tokenGenerator; |
|
47 | - $this->sessionStorage = $storageInterface; |
|
48 | - } |
|
40 | + /** |
|
41 | + * @param CsrfTokenGenerator $tokenGenerator |
|
42 | + * @param SessionStorage $storageInterface |
|
43 | + */ |
|
44 | + public function __construct(CsrfTokenGenerator $tokenGenerator, |
|
45 | + SessionStorage $storageInterface) { |
|
46 | + $this->tokenGenerator = $tokenGenerator; |
|
47 | + $this->sessionStorage = $storageInterface; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns the current CSRF token, if none set it will create a new one. |
|
52 | - * |
|
53 | - * @return CsrfToken |
|
54 | - */ |
|
55 | - public function getToken() { |
|
56 | - if(!is_null($this->csrfToken)) { |
|
57 | - return $this->csrfToken; |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns the current CSRF token, if none set it will create a new one. |
|
52 | + * |
|
53 | + * @return CsrfToken |
|
54 | + */ |
|
55 | + public function getToken() { |
|
56 | + if(!is_null($this->csrfToken)) { |
|
57 | + return $this->csrfToken; |
|
58 | + } |
|
59 | 59 | |
60 | - if($this->sessionStorage->hasToken()) { |
|
61 | - $value = $this->sessionStorage->getToken(); |
|
62 | - } else { |
|
63 | - $value = $this->tokenGenerator->generateToken(); |
|
64 | - $this->sessionStorage->setToken($value); |
|
65 | - } |
|
60 | + if($this->sessionStorage->hasToken()) { |
|
61 | + $value = $this->sessionStorage->getToken(); |
|
62 | + } else { |
|
63 | + $value = $this->tokenGenerator->generateToken(); |
|
64 | + $this->sessionStorage->setToken($value); |
|
65 | + } |
|
66 | 66 | |
67 | - $this->csrfToken = new CsrfToken($value); |
|
68 | - return $this->csrfToken; |
|
69 | - } |
|
67 | + $this->csrfToken = new CsrfToken($value); |
|
68 | + return $this->csrfToken; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Invalidates any current token and sets a new one. |
|
73 | - * |
|
74 | - * @return CsrfToken |
|
75 | - */ |
|
76 | - public function refreshToken() { |
|
77 | - $value = $this->tokenGenerator->generateToken(); |
|
78 | - $this->sessionStorage->setToken($value); |
|
79 | - $this->csrfToken = new CsrfToken($value); |
|
80 | - return $this->csrfToken; |
|
81 | - } |
|
71 | + /** |
|
72 | + * Invalidates any current token and sets a new one. |
|
73 | + * |
|
74 | + * @return CsrfToken |
|
75 | + */ |
|
76 | + public function refreshToken() { |
|
77 | + $value = $this->tokenGenerator->generateToken(); |
|
78 | + $this->sessionStorage->setToken($value); |
|
79 | + $this->csrfToken = new CsrfToken($value); |
|
80 | + return $this->csrfToken; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Remove the current token from the storage. |
|
85 | - */ |
|
86 | - public function removeToken() { |
|
87 | - $this->csrfToken = null; |
|
88 | - $this->sessionStorage->removeToken(); |
|
89 | - } |
|
83 | + /** |
|
84 | + * Remove the current token from the storage. |
|
85 | + */ |
|
86 | + public function removeToken() { |
|
87 | + $this->csrfToken = null; |
|
88 | + $this->sessionStorage->removeToken(); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Verifies whether the provided token is valid. |
|
93 | - * |
|
94 | - * @param CsrfToken $token |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function isTokenValid(CsrfToken $token) { |
|
98 | - if(!$this->sessionStorage->hasToken()) { |
|
99 | - return false; |
|
100 | - } |
|
91 | + /** |
|
92 | + * Verifies whether the provided token is valid. |
|
93 | + * |
|
94 | + * @param CsrfToken $token |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function isTokenValid(CsrfToken $token) { |
|
98 | + if(!$this->sessionStorage->hasToken()) { |
|
99 | + return false; |
|
100 | + } |
|
101 | 101 | |
102 | - return hash_equals( |
|
103 | - $this->sessionStorage->getToken(), |
|
104 | - $token->getDecryptedValue() |
|
105 | - ); |
|
106 | - } |
|
102 | + return hash_equals( |
|
103 | + $this->sessionStorage->getToken(), |
|
104 | + $token->getDecryptedValue() |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | } |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | * @return CsrfToken |
54 | 54 | */ |
55 | 55 | public function getToken() { |
56 | - if(!is_null($this->csrfToken)) { |
|
56 | + if (!is_null($this->csrfToken)) { |
|
57 | 57 | return $this->csrfToken; |
58 | 58 | } |
59 | 59 | |
60 | - if($this->sessionStorage->hasToken()) { |
|
60 | + if ($this->sessionStorage->hasToken()) { |
|
61 | 61 | $value = $this->sessionStorage->getToken(); |
62 | 62 | } else { |
63 | 63 | $value = $this->tokenGenerator->generateToken(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return bool |
96 | 96 | */ |
97 | 97 | public function isTokenValid(CsrfToken $token) { |
98 | - if(!$this->sessionStorage->hasToken()) { |
|
98 | + if (!$this->sessionStorage->hasToken()) { |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 |
@@ -31,23 +31,23 @@ |
||
31 | 31 | * @package OC\Security\CSRF |
32 | 32 | */ |
33 | 33 | class CsrfTokenGenerator { |
34 | - /** @var ISecureRandom */ |
|
35 | - private $random; |
|
34 | + /** @var ISecureRandom */ |
|
35 | + private $random; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param ISecureRandom $random |
|
39 | - */ |
|
40 | - public function __construct(ISecureRandom $random) { |
|
41 | - $this->random = $random; |
|
42 | - } |
|
37 | + /** |
|
38 | + * @param ISecureRandom $random |
|
39 | + */ |
|
40 | + public function __construct(ISecureRandom $random) { |
|
41 | + $this->random = $random; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Generate a new CSRF token. |
|
46 | - * |
|
47 | - * @param int $length Length of the token in characters. |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function generateToken($length = 32) { |
|
51 | - return $this->random->generate($length); |
|
52 | - } |
|
44 | + /** |
|
45 | + * Generate a new CSRF token. |
|
46 | + * |
|
47 | + * @param int $length Length of the token in characters. |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function generateToken($length = 32) { |
|
51 | + return $this->random->generate($length); |
|
52 | + } |
|
53 | 53 | } |