@@ -244,2059 +244,2059 @@ |
||
244 | 244 | */ |
245 | 245 | class Server extends ServerContainer implements IServerContainer { |
246 | 246 | |
247 | - /** @var string */ |
|
248 | - private $webRoot; |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $webRoot |
|
252 | - * @param \OC\Config $config |
|
253 | - */ |
|
254 | - public function __construct($webRoot, \OC\Config $config) { |
|
255 | - parent::__construct(); |
|
256 | - $this->webRoot = $webRoot; |
|
257 | - |
|
258 | - // To find out if we are running from CLI or not |
|
259 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
260 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
261 | - |
|
262 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
263 | - return $c; |
|
264 | - }); |
|
265 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
266 | - return $c; |
|
267 | - }); |
|
268 | - |
|
269 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
270 | - /** @deprecated 19.0.0 */ |
|
271 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
272 | - |
|
273 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
274 | - /** @deprecated 19.0.0 */ |
|
275 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
276 | - |
|
277 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
278 | - /** @deprecated 19.0.0 */ |
|
279 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
280 | - |
|
281 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
282 | - /** @deprecated 19.0.0 */ |
|
283 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
284 | - |
|
285 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
286 | - |
|
287 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
288 | - |
|
289 | - |
|
290 | - $this->registerService(IPreview::class, function (Server $c) { |
|
291 | - return new PreviewManager( |
|
292 | - $c->getConfig(), |
|
293 | - $c->getRootFolder(), |
|
294 | - new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()), |
|
295 | - $c->getEventDispatcher(), |
|
296 | - $c->getGeneratorHelper(), |
|
297 | - $c->getSession()->get('user_id') |
|
298 | - ); |
|
299 | - }); |
|
300 | - /** @deprecated 19.0.0 */ |
|
301 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
302 | - |
|
303 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
304 | - return new \OC\Preview\Watcher( |
|
305 | - new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()) |
|
306 | - ); |
|
307 | - }); |
|
308 | - |
|
309 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
310 | - $view = new View(); |
|
311 | - $util = new Encryption\Util( |
|
312 | - $view, |
|
313 | - $c->getUserManager(), |
|
314 | - $c->getGroupManager(), |
|
315 | - $c->getConfig() |
|
316 | - ); |
|
317 | - return new Encryption\Manager( |
|
318 | - $c->getConfig(), |
|
319 | - $c->getLogger(), |
|
320 | - $c->getL10N('core'), |
|
321 | - new View(), |
|
322 | - $util, |
|
323 | - new ArrayCache() |
|
324 | - ); |
|
325 | - }); |
|
326 | - /** @deprecated 19.0.0 */ |
|
327 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
328 | - |
|
329 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
330 | - $util = new Encryption\Util( |
|
331 | - new View(), |
|
332 | - $c->getUserManager(), |
|
333 | - $c->getGroupManager(), |
|
334 | - $c->getConfig() |
|
335 | - ); |
|
336 | - return new Encryption\File( |
|
337 | - $util, |
|
338 | - $c->getRootFolder(), |
|
339 | - $c->getShareManager() |
|
340 | - ); |
|
341 | - }); |
|
342 | - |
|
343 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
344 | - $view = new View(); |
|
345 | - $util = new Encryption\Util( |
|
346 | - $view, |
|
347 | - $c->getUserManager(), |
|
348 | - $c->getGroupManager(), |
|
349 | - $c->getConfig() |
|
350 | - ); |
|
351 | - |
|
352 | - return new Encryption\Keys\Storage($view, $util, $c->getCrypto(), $c->getConfig()); |
|
353 | - }); |
|
354 | - /** @deprecated 20.0.0 */ |
|
355 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
356 | - |
|
357 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
358 | - /** @deprecated 19.0.0 */ |
|
359 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
360 | - |
|
361 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
362 | - $config = $c->getConfig(); |
|
363 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
364 | - return new $factoryClass($this); |
|
365 | - }); |
|
366 | - $this->registerService(ISystemTagManager::class, function (Server $c) { |
|
367 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
368 | - }); |
|
369 | - /** @deprecated 19.0.0 */ |
|
370 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
371 | - |
|
372 | - $this->registerService(ISystemTagObjectMapper::class, function (Server $c) { |
|
373 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
374 | - }); |
|
375 | - $this->registerService('RootFolder', function (Server $c) { |
|
376 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
377 | - $view = new View(); |
|
378 | - $root = new Root( |
|
379 | - $manager, |
|
380 | - $view, |
|
381 | - null, |
|
382 | - $c->getUserMountCache(), |
|
383 | - $this->getLogger(), |
|
384 | - $this->getUserManager() |
|
385 | - ); |
|
386 | - |
|
387 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
388 | - $previewConnector->connectWatcher(); |
|
389 | - |
|
390 | - return $root; |
|
391 | - }); |
|
392 | - $this->registerService(HookConnector::class, function (Server $c) { |
|
393 | - return new HookConnector( |
|
394 | - $c->query(IRootFolder::class), |
|
395 | - new View(), |
|
396 | - $c->query(\OC\EventDispatcher\SymfonyAdapter::class), |
|
397 | - $c->query(IEventDispatcher::class) |
|
398 | - ); |
|
399 | - }); |
|
400 | - |
|
401 | - /** @deprecated 19.0.0 */ |
|
402 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
403 | - |
|
404 | - $this->registerService(IRootFolder::class, function (Server $c) { |
|
405 | - return new LazyRoot(function () use ($c) { |
|
406 | - return $c->query('RootFolder'); |
|
407 | - }); |
|
408 | - }); |
|
409 | - /** @deprecated 19.0.0 */ |
|
410 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
411 | - |
|
412 | - /** @deprecated 19.0.0 */ |
|
413 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
414 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
415 | - |
|
416 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
417 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
418 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
419 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
|
420 | - |
|
421 | - /** @var IEventDispatcher $dispatcher */ |
|
422 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
423 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
424 | - }); |
|
425 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
426 | - \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]); |
|
427 | - |
|
428 | - /** @var IEventDispatcher $dispatcher */ |
|
429 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
430 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
431 | - }); |
|
432 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
433 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
|
434 | - |
|
435 | - /** @var IEventDispatcher $dispatcher */ |
|
436 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
437 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
438 | - }); |
|
439 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
440 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
|
441 | - |
|
442 | - /** @var IEventDispatcher $dispatcher */ |
|
443 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
444 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
445 | - }); |
|
446 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
447 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
448 | - |
|
449 | - /** @var IEventDispatcher $dispatcher */ |
|
450 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
451 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
452 | - }); |
|
453 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
454 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
455 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
456 | - \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
457 | - |
|
458 | - /** @var IEventDispatcher $dispatcher */ |
|
459 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
460 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
461 | - }); |
|
462 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
463 | - /** @var IEventDispatcher $dispatcher */ |
|
464 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
465 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
466 | - }); |
|
467 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
468 | - /** @var IEventDispatcher $dispatcher */ |
|
469 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
470 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
471 | - }); |
|
472 | - return $groupManager; |
|
473 | - }); |
|
474 | - /** @deprecated 19.0.0 */ |
|
475 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
476 | - |
|
477 | - $this->registerService(Store::class, function (Server $c) { |
|
478 | - $session = $c->getSession(); |
|
479 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
480 | - $tokenProvider = $c->query(IProvider::class); |
|
481 | - } else { |
|
482 | - $tokenProvider = null; |
|
483 | - } |
|
484 | - $logger = $c->getLogger(); |
|
485 | - return new Store($session, $logger, $tokenProvider); |
|
486 | - }); |
|
487 | - $this->registerAlias(IStore::class, Store::class); |
|
488 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
489 | - |
|
490 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
491 | - $manager = $c->getUserManager(); |
|
492 | - $session = new \OC\Session\Memory(''); |
|
493 | - $timeFactory = new TimeFactory(); |
|
494 | - // Token providers might require a working database. This code |
|
495 | - // might however be called when ownCloud is not yet setup. |
|
496 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
497 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
498 | - } else { |
|
499 | - $defaultTokenProvider = null; |
|
500 | - } |
|
501 | - |
|
502 | - $legacyDispatcher = $c->getEventDispatcher(); |
|
503 | - |
|
504 | - $userSession = new \OC\User\Session( |
|
505 | - $manager, |
|
506 | - $session, |
|
507 | - $timeFactory, |
|
508 | - $defaultTokenProvider, |
|
509 | - $c->getConfig(), |
|
510 | - $c->getSecureRandom(), |
|
511 | - $c->getLockdownManager(), |
|
512 | - $c->getLogger(), |
|
513 | - $c->query(IEventDispatcher::class) |
|
514 | - ); |
|
515 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
516 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
517 | - |
|
518 | - /** @var IEventDispatcher $dispatcher */ |
|
519 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
520 | - $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); |
|
521 | - }); |
|
522 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
523 | - /** @var \OC\User\User $user */ |
|
524 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
525 | - |
|
526 | - /** @var IEventDispatcher $dispatcher */ |
|
527 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
528 | - $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
529 | - }); |
|
530 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
531 | - /** @var \OC\User\User $user */ |
|
532 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
533 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
534 | - |
|
535 | - /** @var IEventDispatcher $dispatcher */ |
|
536 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
537 | - $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); |
|
538 | - }); |
|
539 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
540 | - /** @var \OC\User\User $user */ |
|
541 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
542 | - |
|
543 | - /** @var IEventDispatcher $dispatcher */ |
|
544 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
545 | - $dispatcher->dispatchTyped(new UserDeletedEvent($user)); |
|
546 | - }); |
|
547 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
548 | - /** @var \OC\User\User $user */ |
|
549 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
550 | - |
|
551 | - /** @var IEventDispatcher $dispatcher */ |
|
552 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
553 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
554 | - }); |
|
555 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
556 | - /** @var \OC\User\User $user */ |
|
557 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
558 | - |
|
559 | - /** @var IEventDispatcher $dispatcher */ |
|
560 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
561 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
562 | - }); |
|
563 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
564 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
565 | - |
|
566 | - /** @var IEventDispatcher $dispatcher */ |
|
567 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
568 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
569 | - }); |
|
570 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
571 | - /** @var \OC\User\User $user */ |
|
572 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
573 | - |
|
574 | - /** @var IEventDispatcher $dispatcher */ |
|
575 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
576 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
577 | - }); |
|
578 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
579 | - /** @var IEventDispatcher $dispatcher */ |
|
580 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
581 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
582 | - }); |
|
583 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
584 | - /** @var \OC\User\User $user */ |
|
585 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
586 | - |
|
587 | - /** @var IEventDispatcher $dispatcher */ |
|
588 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
589 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
590 | - }); |
|
591 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
592 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
593 | - |
|
594 | - /** @var IEventDispatcher $dispatcher */ |
|
595 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
596 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
597 | - }); |
|
598 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
599 | - /** @var IEventDispatcher $dispatcher */ |
|
600 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
601 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
602 | - }); |
|
603 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
604 | - /** @var \OC\User\User $user */ |
|
605 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
606 | - |
|
607 | - /** @var IEventDispatcher $dispatcher */ |
|
608 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
609 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
610 | - }); |
|
611 | - return $userSession; |
|
612 | - }); |
|
613 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
614 | - /** @deprecated 19.0.0 */ |
|
615 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
616 | - |
|
617 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
618 | - |
|
619 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
620 | - /** @deprecated 19.0.0 */ |
|
621 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
622 | - |
|
623 | - /** @deprecated 19.0.0 */ |
|
624 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
625 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
626 | - |
|
627 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
628 | - return new \OC\SystemConfig($config); |
|
629 | - }); |
|
630 | - /** @deprecated 19.0.0 */ |
|
631 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
632 | - |
|
633 | - /** @deprecated 19.0.0 */ |
|
634 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
635 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
636 | - |
|
637 | - $this->registerService(IFactory::class, function (Server $c) { |
|
638 | - return new \OC\L10N\Factory( |
|
639 | - $c->getConfig(), |
|
640 | - $c->getRequest(), |
|
641 | - $c->getUserSession(), |
|
642 | - \OC::$SERVERROOT |
|
643 | - ); |
|
644 | - }); |
|
645 | - /** @deprecated 19.0.0 */ |
|
646 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
647 | - |
|
648 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
649 | - /** @deprecated 19.0.0 */ |
|
650 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
651 | - |
|
652 | - /** @deprecated 19.0.0 */ |
|
653 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
654 | - /** @deprecated 19.0.0 */ |
|
655 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
656 | - |
|
657 | - $this->registerService(ICache::class, function ($c) { |
|
658 | - return new Cache\File(); |
|
659 | - }); |
|
660 | - /** @deprecated 19.0.0 */ |
|
661 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
662 | - |
|
663 | - $this->registerService(Factory::class, function (Server $c) { |
|
664 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
665 | - ArrayCache::class, |
|
666 | - ArrayCache::class, |
|
667 | - ArrayCache::class |
|
668 | - ); |
|
669 | - $config = $c->getConfig(); |
|
670 | - |
|
671 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
672 | - $v = \OC_App::getAppVersions(); |
|
673 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
674 | - $version = implode(',', $v); |
|
675 | - $instanceId = \OC_Util::getInstanceId(); |
|
676 | - $path = \OC::$SERVERROOT; |
|
677 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
678 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
679 | - $config->getSystemValue('memcache.local', null), |
|
680 | - $config->getSystemValue('memcache.distributed', null), |
|
681 | - $config->getSystemValue('memcache.locking', null) |
|
682 | - ); |
|
683 | - } |
|
684 | - return $arrayCacheFactory; |
|
685 | - }); |
|
686 | - /** @deprecated 19.0.0 */ |
|
687 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
688 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
689 | - |
|
690 | - $this->registerService('RedisFactory', function (Server $c) { |
|
691 | - $systemConfig = $c->getSystemConfig(); |
|
692 | - return new RedisFactory($systemConfig); |
|
693 | - }); |
|
694 | - |
|
695 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
696 | - $l10n = $this->get(IFactory::class)->get('activity'); |
|
697 | - return new \OC\Activity\Manager( |
|
698 | - $c->getRequest(), |
|
699 | - $c->getUserSession(), |
|
700 | - $c->getConfig(), |
|
701 | - $c->query(IValidator::class), |
|
702 | - $l10n |
|
703 | - ); |
|
704 | - }); |
|
705 | - /** @deprecated 19.0.0 */ |
|
706 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
707 | - |
|
708 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
709 | - return new \OC\Activity\EventMerger( |
|
710 | - $c->getL10N('lib') |
|
711 | - ); |
|
712 | - }); |
|
713 | - $this->registerAlias(IValidator::class, Validator::class); |
|
714 | - |
|
715 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
716 | - return new AvatarManager( |
|
717 | - $c->query(\OC\User\Manager::class), |
|
718 | - $c->getAppDataDir('avatar'), |
|
719 | - $c->getL10N('lib'), |
|
720 | - $c->getLogger(), |
|
721 | - $c->getConfig() |
|
722 | - ); |
|
723 | - }); |
|
724 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
725 | - /** @deprecated 19.0.0 */ |
|
726 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
727 | - |
|
728 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
729 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
730 | - |
|
731 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
732 | - $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
733 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
734 | - $logger = $factory->get($logType); |
|
735 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
736 | - |
|
737 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
738 | - }); |
|
739 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
740 | - /** @deprecated 19.0.0 */ |
|
741 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
742 | - // PSR-3 logger |
|
743 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
744 | - |
|
745 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
746 | - return new LogFactory($c, $this->getSystemConfig()); |
|
747 | - }); |
|
748 | - |
|
749 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
750 | - /** @deprecated 19.0.0 */ |
|
751 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
752 | - |
|
753 | - $this->registerService(IRouter::class, function (Server $c) { |
|
754 | - $cacheFactory = $c->getMemCacheFactory(); |
|
755 | - $logger = $c->getLogger(); |
|
756 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
757 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
758 | - } else { |
|
759 | - $router = new \OC\Route\Router($logger); |
|
760 | - } |
|
761 | - return $router; |
|
762 | - }); |
|
763 | - /** @deprecated 19.0.0 */ |
|
764 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
765 | - |
|
766 | - $this->registerAlias(ISearch::class, Search::class); |
|
767 | - /** @deprecated 19.0.0 */ |
|
768 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
769 | - |
|
770 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
771 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
772 | - $this->getMemCacheFactory(), |
|
773 | - new \OC\AppFramework\Utility\TimeFactory() |
|
774 | - ); |
|
775 | - }); |
|
776 | - |
|
777 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
778 | - /** @deprecated 19.0.0 */ |
|
779 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
780 | - |
|
781 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
782 | - /** @deprecated 19.0.0 */ |
|
783 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
784 | - |
|
785 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
786 | - /** @deprecated 19.0.0 */ |
|
787 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
788 | - |
|
789 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
790 | - /** @deprecated 19.0.0 */ |
|
791 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
792 | - |
|
793 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
794 | - $systemConfig = $c->getSystemConfig(); |
|
795 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
796 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
797 | - if (!$factory->isValidType($type)) { |
|
798 | - throw new \OC\DatabaseException('Invalid database type'); |
|
799 | - } |
|
800 | - $connectionParams = $factory->createConnectionParams(); |
|
801 | - $connection = $factory->getConnection($type, $connectionParams); |
|
802 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
803 | - return $connection; |
|
804 | - }); |
|
805 | - /** @deprecated 19.0.0 */ |
|
806 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
807 | - |
|
808 | - |
|
809 | - $this->registerService(IClientService::class, function (Server $c) { |
|
810 | - $user = \OC_User::getUser(); |
|
811 | - $uid = $user ? $user : null; |
|
812 | - return new ClientService( |
|
813 | - $c->getConfig(), |
|
814 | - $c->getLogger(), |
|
815 | - new \OC\Security\CertificateManager( |
|
816 | - $uid, |
|
817 | - new View(), |
|
818 | - $c->getConfig(), |
|
819 | - $c->getLogger(), |
|
820 | - $c->getSecureRandom() |
|
821 | - ) |
|
822 | - ); |
|
823 | - }); |
|
824 | - /** @deprecated 19.0.0 */ |
|
825 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
826 | - $this->registerService(IEventLogger::class, function (Server $c) { |
|
827 | - $eventLogger = new EventLogger(); |
|
828 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
829 | - // In debug mode, module is being activated by default |
|
830 | - $eventLogger->activate(); |
|
831 | - } |
|
832 | - return $eventLogger; |
|
833 | - }); |
|
834 | - /** @deprecated 19.0.0 */ |
|
835 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
836 | - |
|
837 | - $this->registerService(IQueryLogger::class, function (Server $c) { |
|
838 | - $queryLogger = new QueryLogger(); |
|
839 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
840 | - // In debug mode, module is being activated by default |
|
841 | - $queryLogger->activate(); |
|
842 | - } |
|
843 | - return $queryLogger; |
|
844 | - }); |
|
845 | - /** @deprecated 19.0.0 */ |
|
846 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
847 | - |
|
848 | - /** @deprecated 19.0.0 */ |
|
849 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
850 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
851 | - |
|
852 | - $this->registerService(AppManager::class, function (Server $c) { |
|
853 | - return new \OC\App\AppManager( |
|
854 | - $c->getUserSession(), |
|
855 | - $c->getConfig(), |
|
856 | - $c->query(\OC\AppConfig::class), |
|
857 | - $c->getGroupManager(), |
|
858 | - $c->getMemCacheFactory(), |
|
859 | - $c->getEventDispatcher(), |
|
860 | - $c->getLogger() |
|
861 | - ); |
|
862 | - }); |
|
863 | - /** @deprecated 19.0.0 */ |
|
864 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
865 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
866 | - |
|
867 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
868 | - /** @deprecated 19.0.0 */ |
|
869 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
870 | - |
|
871 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
872 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
873 | - |
|
874 | - return new DateTimeFormatter( |
|
875 | - $c->getDateTimeZone()->getTimeZone(), |
|
876 | - $c->getL10N('lib', $language) |
|
877 | - ); |
|
878 | - }); |
|
879 | - /** @deprecated 19.0.0 */ |
|
880 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
881 | - |
|
882 | - $this->registerService(IUserMountCache::class, function (Server $c) { |
|
883 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
884 | - $listener = new UserMountCacheListener($mountCache); |
|
885 | - $listener->listen($c->getUserManager()); |
|
886 | - return $mountCache; |
|
887 | - }); |
|
888 | - /** @deprecated 19.0.0 */ |
|
889 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
890 | - |
|
891 | - $this->registerService(IMountProviderCollection::class, function (Server $c) { |
|
892 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
893 | - $mountCache = $c->query(IUserMountCache::class); |
|
894 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
895 | - |
|
896 | - // builtin providers |
|
897 | - |
|
898 | - $config = $c->getConfig(); |
|
899 | - $logger = $c->getLogger(); |
|
900 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
901 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
902 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
903 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
904 | - |
|
905 | - return $manager; |
|
906 | - }); |
|
907 | - /** @deprecated 19.0.0 */ |
|
908 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
909 | - |
|
910 | - /** @deprecated 20.0.0 */ |
|
911 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
912 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
913 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
914 | - if ($busClass) { |
|
915 | - [$app, $class] = explode('::', $busClass, 2); |
|
916 | - if ($c->getAppManager()->isInstalled($app)) { |
|
917 | - \OC_App::loadApp($app); |
|
918 | - return $c->query($class); |
|
919 | - } else { |
|
920 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
921 | - } |
|
922 | - } else { |
|
923 | - $jobList = $c->getJobList(); |
|
924 | - return new CronBus($jobList); |
|
925 | - } |
|
926 | - }); |
|
927 | - $this->registerAlias(IBus::class, 'AsyncCommandBus'); |
|
928 | - /** @deprecated 20.0.0 */ |
|
929 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
930 | - /** @deprecated 19.0.0 */ |
|
931 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
932 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
933 | - // IConfig and IAppManager requires a working database. This code |
|
934 | - // might however be called when ownCloud is not yet setup. |
|
935 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
936 | - $config = $c->getConfig(); |
|
937 | - $appManager = $c->getAppManager(); |
|
938 | - } else { |
|
939 | - $config = null; |
|
940 | - $appManager = null; |
|
941 | - } |
|
942 | - |
|
943 | - return new Checker( |
|
944 | - new EnvironmentHelper(), |
|
945 | - new FileAccessHelper(), |
|
946 | - new AppLocator(), |
|
947 | - $config, |
|
948 | - $c->getMemCacheFactory(), |
|
949 | - $appManager, |
|
950 | - $c->getTempManager(), |
|
951 | - $c->getMimeTypeDetector() |
|
952 | - ); |
|
953 | - }); |
|
954 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
955 | - if (isset($this['urlParams'])) { |
|
956 | - $urlParams = $this['urlParams']; |
|
957 | - } else { |
|
958 | - $urlParams = []; |
|
959 | - } |
|
960 | - |
|
961 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
962 | - && in_array('fakeinput', stream_get_wrappers()) |
|
963 | - ) { |
|
964 | - $stream = 'fakeinput://data'; |
|
965 | - } else { |
|
966 | - $stream = 'php://input'; |
|
967 | - } |
|
968 | - |
|
969 | - return new Request( |
|
970 | - [ |
|
971 | - 'get' => $_GET, |
|
972 | - 'post' => $_POST, |
|
973 | - 'files' => $_FILES, |
|
974 | - 'server' => $_SERVER, |
|
975 | - 'env' => $_ENV, |
|
976 | - 'cookies' => $_COOKIE, |
|
977 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
978 | - ? $_SERVER['REQUEST_METHOD'] |
|
979 | - : '', |
|
980 | - 'urlParams' => $urlParams, |
|
981 | - ], |
|
982 | - $this->getSecureRandom(), |
|
983 | - $this->getConfig(), |
|
984 | - $this->getCsrfTokenManager(), |
|
985 | - $stream |
|
986 | - ); |
|
987 | - }); |
|
988 | - /** @deprecated 19.0.0 */ |
|
989 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
990 | - |
|
991 | - $this->registerService(IMailer::class, function (Server $c) { |
|
992 | - return new Mailer( |
|
993 | - $c->getConfig(), |
|
994 | - $c->getLogger(), |
|
995 | - $c->query(Defaults::class), |
|
996 | - $c->getURLGenerator(), |
|
997 | - $c->getL10N('lib'), |
|
998 | - $c->query(IEventDispatcher::class), |
|
999 | - $c->getL10NFactory() |
|
1000 | - ); |
|
1001 | - }); |
|
1002 | - /** @deprecated 19.0.0 */ |
|
1003 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1004 | - |
|
1005 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
1006 | - $config = $c->getConfig(); |
|
1007 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1008 | - if (is_null($factoryClass)) { |
|
1009 | - throw new \Exception('ldapProviderFactory not set'); |
|
1010 | - } |
|
1011 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1012 | - $factory = new $factoryClass($this); |
|
1013 | - return $factory->getLDAPProvider(); |
|
1014 | - }); |
|
1015 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
1016 | - $ini = $c->get(IniGetWrapper::class); |
|
1017 | - $config = $c->getConfig(); |
|
1018 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1019 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1020 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1021 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1022 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
1023 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1024 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
1025 | - } |
|
1026 | - return new DBLockingProvider( |
|
1027 | - $c->getDatabaseConnection(), |
|
1028 | - $c->getLogger(), |
|
1029 | - new TimeFactory(), |
|
1030 | - $ttl, |
|
1031 | - !\OC::$CLI |
|
1032 | - ); |
|
1033 | - } |
|
1034 | - return new NoopLockingProvider(); |
|
1035 | - }); |
|
1036 | - /** @deprecated 19.0.0 */ |
|
1037 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1038 | - |
|
1039 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1040 | - /** @deprecated 19.0.0 */ |
|
1041 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1042 | - |
|
1043 | - $this->registerService(IMimeTypeDetector::class, function (Server $c) { |
|
1044 | - return new \OC\Files\Type\Detection( |
|
1045 | - $c->getURLGenerator(), |
|
1046 | - $c->getLogger(), |
|
1047 | - \OC::$configDir, |
|
1048 | - \OC::$SERVERROOT . '/resources/config/' |
|
1049 | - ); |
|
1050 | - }); |
|
1051 | - /** @deprecated 19.0.0 */ |
|
1052 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1053 | - |
|
1054 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1055 | - /** @deprecated 19.0.0 */ |
|
1056 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1057 | - $this->registerService(BundleFetcher::class, function () { |
|
1058 | - return new BundleFetcher($this->getL10N('lib')); |
|
1059 | - }); |
|
1060 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1061 | - /** @deprecated 19.0.0 */ |
|
1062 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1063 | - |
|
1064 | - $this->registerService(CapabilitiesManager::class, function (Server $c) { |
|
1065 | - $manager = new CapabilitiesManager($c->getLogger()); |
|
1066 | - $manager->registerCapability(function () use ($c) { |
|
1067 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
1068 | - }); |
|
1069 | - $manager->registerCapability(function () use ($c) { |
|
1070 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
1071 | - }); |
|
1072 | - return $manager; |
|
1073 | - }); |
|
1074 | - /** @deprecated 19.0.0 */ |
|
1075 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1076 | - |
|
1077 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1078 | - $config = $c->getConfig(); |
|
1079 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1080 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1081 | - $factory = new $factoryClass($this); |
|
1082 | - $manager = $factory->getManager(); |
|
1083 | - |
|
1084 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1085 | - $manager = $c->getUserManager(); |
|
1086 | - $user = $manager->get($id); |
|
1087 | - if (is_null($user)) { |
|
1088 | - $l = $c->getL10N('core'); |
|
1089 | - $displayName = $l->t('Unknown user'); |
|
1090 | - } else { |
|
1091 | - $displayName = $user->getDisplayName(); |
|
1092 | - } |
|
1093 | - return $displayName; |
|
1094 | - }); |
|
1095 | - |
|
1096 | - return $manager; |
|
1097 | - }); |
|
1098 | - /** @deprecated 19.0.0 */ |
|
1099 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1100 | - |
|
1101 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1102 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
1103 | - /* |
|
247 | + /** @var string */ |
|
248 | + private $webRoot; |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $webRoot |
|
252 | + * @param \OC\Config $config |
|
253 | + */ |
|
254 | + public function __construct($webRoot, \OC\Config $config) { |
|
255 | + parent::__construct(); |
|
256 | + $this->webRoot = $webRoot; |
|
257 | + |
|
258 | + // To find out if we are running from CLI or not |
|
259 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
260 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
261 | + |
|
262 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
263 | + return $c; |
|
264 | + }); |
|
265 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
266 | + return $c; |
|
267 | + }); |
|
268 | + |
|
269 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
270 | + /** @deprecated 19.0.0 */ |
|
271 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
272 | + |
|
273 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
274 | + /** @deprecated 19.0.0 */ |
|
275 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
276 | + |
|
277 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
278 | + /** @deprecated 19.0.0 */ |
|
279 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
280 | + |
|
281 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
282 | + /** @deprecated 19.0.0 */ |
|
283 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
284 | + |
|
285 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
286 | + |
|
287 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
288 | + |
|
289 | + |
|
290 | + $this->registerService(IPreview::class, function (Server $c) { |
|
291 | + return new PreviewManager( |
|
292 | + $c->getConfig(), |
|
293 | + $c->getRootFolder(), |
|
294 | + new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()), |
|
295 | + $c->getEventDispatcher(), |
|
296 | + $c->getGeneratorHelper(), |
|
297 | + $c->getSession()->get('user_id') |
|
298 | + ); |
|
299 | + }); |
|
300 | + /** @deprecated 19.0.0 */ |
|
301 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
302 | + |
|
303 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
304 | + return new \OC\Preview\Watcher( |
|
305 | + new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()) |
|
306 | + ); |
|
307 | + }); |
|
308 | + |
|
309 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
310 | + $view = new View(); |
|
311 | + $util = new Encryption\Util( |
|
312 | + $view, |
|
313 | + $c->getUserManager(), |
|
314 | + $c->getGroupManager(), |
|
315 | + $c->getConfig() |
|
316 | + ); |
|
317 | + return new Encryption\Manager( |
|
318 | + $c->getConfig(), |
|
319 | + $c->getLogger(), |
|
320 | + $c->getL10N('core'), |
|
321 | + new View(), |
|
322 | + $util, |
|
323 | + new ArrayCache() |
|
324 | + ); |
|
325 | + }); |
|
326 | + /** @deprecated 19.0.0 */ |
|
327 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
328 | + |
|
329 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
330 | + $util = new Encryption\Util( |
|
331 | + new View(), |
|
332 | + $c->getUserManager(), |
|
333 | + $c->getGroupManager(), |
|
334 | + $c->getConfig() |
|
335 | + ); |
|
336 | + return new Encryption\File( |
|
337 | + $util, |
|
338 | + $c->getRootFolder(), |
|
339 | + $c->getShareManager() |
|
340 | + ); |
|
341 | + }); |
|
342 | + |
|
343 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
344 | + $view = new View(); |
|
345 | + $util = new Encryption\Util( |
|
346 | + $view, |
|
347 | + $c->getUserManager(), |
|
348 | + $c->getGroupManager(), |
|
349 | + $c->getConfig() |
|
350 | + ); |
|
351 | + |
|
352 | + return new Encryption\Keys\Storage($view, $util, $c->getCrypto(), $c->getConfig()); |
|
353 | + }); |
|
354 | + /** @deprecated 20.0.0 */ |
|
355 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
356 | + |
|
357 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
358 | + /** @deprecated 19.0.0 */ |
|
359 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
360 | + |
|
361 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
362 | + $config = $c->getConfig(); |
|
363 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
364 | + return new $factoryClass($this); |
|
365 | + }); |
|
366 | + $this->registerService(ISystemTagManager::class, function (Server $c) { |
|
367 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
368 | + }); |
|
369 | + /** @deprecated 19.0.0 */ |
|
370 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
371 | + |
|
372 | + $this->registerService(ISystemTagObjectMapper::class, function (Server $c) { |
|
373 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
374 | + }); |
|
375 | + $this->registerService('RootFolder', function (Server $c) { |
|
376 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
377 | + $view = new View(); |
|
378 | + $root = new Root( |
|
379 | + $manager, |
|
380 | + $view, |
|
381 | + null, |
|
382 | + $c->getUserMountCache(), |
|
383 | + $this->getLogger(), |
|
384 | + $this->getUserManager() |
|
385 | + ); |
|
386 | + |
|
387 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
388 | + $previewConnector->connectWatcher(); |
|
389 | + |
|
390 | + return $root; |
|
391 | + }); |
|
392 | + $this->registerService(HookConnector::class, function (Server $c) { |
|
393 | + return new HookConnector( |
|
394 | + $c->query(IRootFolder::class), |
|
395 | + new View(), |
|
396 | + $c->query(\OC\EventDispatcher\SymfonyAdapter::class), |
|
397 | + $c->query(IEventDispatcher::class) |
|
398 | + ); |
|
399 | + }); |
|
400 | + |
|
401 | + /** @deprecated 19.0.0 */ |
|
402 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
403 | + |
|
404 | + $this->registerService(IRootFolder::class, function (Server $c) { |
|
405 | + return new LazyRoot(function () use ($c) { |
|
406 | + return $c->query('RootFolder'); |
|
407 | + }); |
|
408 | + }); |
|
409 | + /** @deprecated 19.0.0 */ |
|
410 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
411 | + |
|
412 | + /** @deprecated 19.0.0 */ |
|
413 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
414 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
415 | + |
|
416 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
417 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
418 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
419 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
|
420 | + |
|
421 | + /** @var IEventDispatcher $dispatcher */ |
|
422 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
423 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
424 | + }); |
|
425 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
426 | + \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]); |
|
427 | + |
|
428 | + /** @var IEventDispatcher $dispatcher */ |
|
429 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
430 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
431 | + }); |
|
432 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
433 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
|
434 | + |
|
435 | + /** @var IEventDispatcher $dispatcher */ |
|
436 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
437 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
438 | + }); |
|
439 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
440 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
|
441 | + |
|
442 | + /** @var IEventDispatcher $dispatcher */ |
|
443 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
444 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
445 | + }); |
|
446 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
447 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
448 | + |
|
449 | + /** @var IEventDispatcher $dispatcher */ |
|
450 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
451 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
452 | + }); |
|
453 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
454 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
455 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
456 | + \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
457 | + |
|
458 | + /** @var IEventDispatcher $dispatcher */ |
|
459 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
460 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
461 | + }); |
|
462 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
463 | + /** @var IEventDispatcher $dispatcher */ |
|
464 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
465 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
466 | + }); |
|
467 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
468 | + /** @var IEventDispatcher $dispatcher */ |
|
469 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
470 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
471 | + }); |
|
472 | + return $groupManager; |
|
473 | + }); |
|
474 | + /** @deprecated 19.0.0 */ |
|
475 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
476 | + |
|
477 | + $this->registerService(Store::class, function (Server $c) { |
|
478 | + $session = $c->getSession(); |
|
479 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
480 | + $tokenProvider = $c->query(IProvider::class); |
|
481 | + } else { |
|
482 | + $tokenProvider = null; |
|
483 | + } |
|
484 | + $logger = $c->getLogger(); |
|
485 | + return new Store($session, $logger, $tokenProvider); |
|
486 | + }); |
|
487 | + $this->registerAlias(IStore::class, Store::class); |
|
488 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
489 | + |
|
490 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
491 | + $manager = $c->getUserManager(); |
|
492 | + $session = new \OC\Session\Memory(''); |
|
493 | + $timeFactory = new TimeFactory(); |
|
494 | + // Token providers might require a working database. This code |
|
495 | + // might however be called when ownCloud is not yet setup. |
|
496 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
497 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
498 | + } else { |
|
499 | + $defaultTokenProvider = null; |
|
500 | + } |
|
501 | + |
|
502 | + $legacyDispatcher = $c->getEventDispatcher(); |
|
503 | + |
|
504 | + $userSession = new \OC\User\Session( |
|
505 | + $manager, |
|
506 | + $session, |
|
507 | + $timeFactory, |
|
508 | + $defaultTokenProvider, |
|
509 | + $c->getConfig(), |
|
510 | + $c->getSecureRandom(), |
|
511 | + $c->getLockdownManager(), |
|
512 | + $c->getLogger(), |
|
513 | + $c->query(IEventDispatcher::class) |
|
514 | + ); |
|
515 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
516 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
517 | + |
|
518 | + /** @var IEventDispatcher $dispatcher */ |
|
519 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
520 | + $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); |
|
521 | + }); |
|
522 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
523 | + /** @var \OC\User\User $user */ |
|
524 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
525 | + |
|
526 | + /** @var IEventDispatcher $dispatcher */ |
|
527 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
528 | + $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
529 | + }); |
|
530 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
531 | + /** @var \OC\User\User $user */ |
|
532 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
533 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
534 | + |
|
535 | + /** @var IEventDispatcher $dispatcher */ |
|
536 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
537 | + $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); |
|
538 | + }); |
|
539 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
540 | + /** @var \OC\User\User $user */ |
|
541 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
542 | + |
|
543 | + /** @var IEventDispatcher $dispatcher */ |
|
544 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
545 | + $dispatcher->dispatchTyped(new UserDeletedEvent($user)); |
|
546 | + }); |
|
547 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
548 | + /** @var \OC\User\User $user */ |
|
549 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
550 | + |
|
551 | + /** @var IEventDispatcher $dispatcher */ |
|
552 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
553 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
554 | + }); |
|
555 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
556 | + /** @var \OC\User\User $user */ |
|
557 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
558 | + |
|
559 | + /** @var IEventDispatcher $dispatcher */ |
|
560 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
561 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
562 | + }); |
|
563 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
564 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
565 | + |
|
566 | + /** @var IEventDispatcher $dispatcher */ |
|
567 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
568 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
569 | + }); |
|
570 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
571 | + /** @var \OC\User\User $user */ |
|
572 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
573 | + |
|
574 | + /** @var IEventDispatcher $dispatcher */ |
|
575 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
576 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
577 | + }); |
|
578 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
579 | + /** @var IEventDispatcher $dispatcher */ |
|
580 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
581 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
582 | + }); |
|
583 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
584 | + /** @var \OC\User\User $user */ |
|
585 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
586 | + |
|
587 | + /** @var IEventDispatcher $dispatcher */ |
|
588 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
589 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
590 | + }); |
|
591 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
592 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
593 | + |
|
594 | + /** @var IEventDispatcher $dispatcher */ |
|
595 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
596 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
597 | + }); |
|
598 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
599 | + /** @var IEventDispatcher $dispatcher */ |
|
600 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
601 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
602 | + }); |
|
603 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
604 | + /** @var \OC\User\User $user */ |
|
605 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
606 | + |
|
607 | + /** @var IEventDispatcher $dispatcher */ |
|
608 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
609 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
610 | + }); |
|
611 | + return $userSession; |
|
612 | + }); |
|
613 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
614 | + /** @deprecated 19.0.0 */ |
|
615 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
616 | + |
|
617 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
618 | + |
|
619 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
620 | + /** @deprecated 19.0.0 */ |
|
621 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
622 | + |
|
623 | + /** @deprecated 19.0.0 */ |
|
624 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
625 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
626 | + |
|
627 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
628 | + return new \OC\SystemConfig($config); |
|
629 | + }); |
|
630 | + /** @deprecated 19.0.0 */ |
|
631 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
632 | + |
|
633 | + /** @deprecated 19.0.0 */ |
|
634 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
635 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
636 | + |
|
637 | + $this->registerService(IFactory::class, function (Server $c) { |
|
638 | + return new \OC\L10N\Factory( |
|
639 | + $c->getConfig(), |
|
640 | + $c->getRequest(), |
|
641 | + $c->getUserSession(), |
|
642 | + \OC::$SERVERROOT |
|
643 | + ); |
|
644 | + }); |
|
645 | + /** @deprecated 19.0.0 */ |
|
646 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
647 | + |
|
648 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
649 | + /** @deprecated 19.0.0 */ |
|
650 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
651 | + |
|
652 | + /** @deprecated 19.0.0 */ |
|
653 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
654 | + /** @deprecated 19.0.0 */ |
|
655 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
656 | + |
|
657 | + $this->registerService(ICache::class, function ($c) { |
|
658 | + return new Cache\File(); |
|
659 | + }); |
|
660 | + /** @deprecated 19.0.0 */ |
|
661 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
662 | + |
|
663 | + $this->registerService(Factory::class, function (Server $c) { |
|
664 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
665 | + ArrayCache::class, |
|
666 | + ArrayCache::class, |
|
667 | + ArrayCache::class |
|
668 | + ); |
|
669 | + $config = $c->getConfig(); |
|
670 | + |
|
671 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
672 | + $v = \OC_App::getAppVersions(); |
|
673 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
674 | + $version = implode(',', $v); |
|
675 | + $instanceId = \OC_Util::getInstanceId(); |
|
676 | + $path = \OC::$SERVERROOT; |
|
677 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
678 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
679 | + $config->getSystemValue('memcache.local', null), |
|
680 | + $config->getSystemValue('memcache.distributed', null), |
|
681 | + $config->getSystemValue('memcache.locking', null) |
|
682 | + ); |
|
683 | + } |
|
684 | + return $arrayCacheFactory; |
|
685 | + }); |
|
686 | + /** @deprecated 19.0.0 */ |
|
687 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
688 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
689 | + |
|
690 | + $this->registerService('RedisFactory', function (Server $c) { |
|
691 | + $systemConfig = $c->getSystemConfig(); |
|
692 | + return new RedisFactory($systemConfig); |
|
693 | + }); |
|
694 | + |
|
695 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
696 | + $l10n = $this->get(IFactory::class)->get('activity'); |
|
697 | + return new \OC\Activity\Manager( |
|
698 | + $c->getRequest(), |
|
699 | + $c->getUserSession(), |
|
700 | + $c->getConfig(), |
|
701 | + $c->query(IValidator::class), |
|
702 | + $l10n |
|
703 | + ); |
|
704 | + }); |
|
705 | + /** @deprecated 19.0.0 */ |
|
706 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
707 | + |
|
708 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
709 | + return new \OC\Activity\EventMerger( |
|
710 | + $c->getL10N('lib') |
|
711 | + ); |
|
712 | + }); |
|
713 | + $this->registerAlias(IValidator::class, Validator::class); |
|
714 | + |
|
715 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
716 | + return new AvatarManager( |
|
717 | + $c->query(\OC\User\Manager::class), |
|
718 | + $c->getAppDataDir('avatar'), |
|
719 | + $c->getL10N('lib'), |
|
720 | + $c->getLogger(), |
|
721 | + $c->getConfig() |
|
722 | + ); |
|
723 | + }); |
|
724 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
725 | + /** @deprecated 19.0.0 */ |
|
726 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
727 | + |
|
728 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
729 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
730 | + |
|
731 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
732 | + $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
733 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
734 | + $logger = $factory->get($logType); |
|
735 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
736 | + |
|
737 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
738 | + }); |
|
739 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
740 | + /** @deprecated 19.0.0 */ |
|
741 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
742 | + // PSR-3 logger |
|
743 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
744 | + |
|
745 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
746 | + return new LogFactory($c, $this->getSystemConfig()); |
|
747 | + }); |
|
748 | + |
|
749 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
750 | + /** @deprecated 19.0.0 */ |
|
751 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
752 | + |
|
753 | + $this->registerService(IRouter::class, function (Server $c) { |
|
754 | + $cacheFactory = $c->getMemCacheFactory(); |
|
755 | + $logger = $c->getLogger(); |
|
756 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
757 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
758 | + } else { |
|
759 | + $router = new \OC\Route\Router($logger); |
|
760 | + } |
|
761 | + return $router; |
|
762 | + }); |
|
763 | + /** @deprecated 19.0.0 */ |
|
764 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
765 | + |
|
766 | + $this->registerAlias(ISearch::class, Search::class); |
|
767 | + /** @deprecated 19.0.0 */ |
|
768 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
769 | + |
|
770 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
771 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
772 | + $this->getMemCacheFactory(), |
|
773 | + new \OC\AppFramework\Utility\TimeFactory() |
|
774 | + ); |
|
775 | + }); |
|
776 | + |
|
777 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
778 | + /** @deprecated 19.0.0 */ |
|
779 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
780 | + |
|
781 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
782 | + /** @deprecated 19.0.0 */ |
|
783 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
784 | + |
|
785 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
786 | + /** @deprecated 19.0.0 */ |
|
787 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
788 | + |
|
789 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
790 | + /** @deprecated 19.0.0 */ |
|
791 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
792 | + |
|
793 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
794 | + $systemConfig = $c->getSystemConfig(); |
|
795 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
796 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
797 | + if (!$factory->isValidType($type)) { |
|
798 | + throw new \OC\DatabaseException('Invalid database type'); |
|
799 | + } |
|
800 | + $connectionParams = $factory->createConnectionParams(); |
|
801 | + $connection = $factory->getConnection($type, $connectionParams); |
|
802 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
803 | + return $connection; |
|
804 | + }); |
|
805 | + /** @deprecated 19.0.0 */ |
|
806 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
807 | + |
|
808 | + |
|
809 | + $this->registerService(IClientService::class, function (Server $c) { |
|
810 | + $user = \OC_User::getUser(); |
|
811 | + $uid = $user ? $user : null; |
|
812 | + return new ClientService( |
|
813 | + $c->getConfig(), |
|
814 | + $c->getLogger(), |
|
815 | + new \OC\Security\CertificateManager( |
|
816 | + $uid, |
|
817 | + new View(), |
|
818 | + $c->getConfig(), |
|
819 | + $c->getLogger(), |
|
820 | + $c->getSecureRandom() |
|
821 | + ) |
|
822 | + ); |
|
823 | + }); |
|
824 | + /** @deprecated 19.0.0 */ |
|
825 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
826 | + $this->registerService(IEventLogger::class, function (Server $c) { |
|
827 | + $eventLogger = new EventLogger(); |
|
828 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
829 | + // In debug mode, module is being activated by default |
|
830 | + $eventLogger->activate(); |
|
831 | + } |
|
832 | + return $eventLogger; |
|
833 | + }); |
|
834 | + /** @deprecated 19.0.0 */ |
|
835 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
836 | + |
|
837 | + $this->registerService(IQueryLogger::class, function (Server $c) { |
|
838 | + $queryLogger = new QueryLogger(); |
|
839 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
840 | + // In debug mode, module is being activated by default |
|
841 | + $queryLogger->activate(); |
|
842 | + } |
|
843 | + return $queryLogger; |
|
844 | + }); |
|
845 | + /** @deprecated 19.0.0 */ |
|
846 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
847 | + |
|
848 | + /** @deprecated 19.0.0 */ |
|
849 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
850 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
851 | + |
|
852 | + $this->registerService(AppManager::class, function (Server $c) { |
|
853 | + return new \OC\App\AppManager( |
|
854 | + $c->getUserSession(), |
|
855 | + $c->getConfig(), |
|
856 | + $c->query(\OC\AppConfig::class), |
|
857 | + $c->getGroupManager(), |
|
858 | + $c->getMemCacheFactory(), |
|
859 | + $c->getEventDispatcher(), |
|
860 | + $c->getLogger() |
|
861 | + ); |
|
862 | + }); |
|
863 | + /** @deprecated 19.0.0 */ |
|
864 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
865 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
866 | + |
|
867 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
868 | + /** @deprecated 19.0.0 */ |
|
869 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
870 | + |
|
871 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
872 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
873 | + |
|
874 | + return new DateTimeFormatter( |
|
875 | + $c->getDateTimeZone()->getTimeZone(), |
|
876 | + $c->getL10N('lib', $language) |
|
877 | + ); |
|
878 | + }); |
|
879 | + /** @deprecated 19.0.0 */ |
|
880 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
881 | + |
|
882 | + $this->registerService(IUserMountCache::class, function (Server $c) { |
|
883 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
884 | + $listener = new UserMountCacheListener($mountCache); |
|
885 | + $listener->listen($c->getUserManager()); |
|
886 | + return $mountCache; |
|
887 | + }); |
|
888 | + /** @deprecated 19.0.0 */ |
|
889 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
890 | + |
|
891 | + $this->registerService(IMountProviderCollection::class, function (Server $c) { |
|
892 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
893 | + $mountCache = $c->query(IUserMountCache::class); |
|
894 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
895 | + |
|
896 | + // builtin providers |
|
897 | + |
|
898 | + $config = $c->getConfig(); |
|
899 | + $logger = $c->getLogger(); |
|
900 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
901 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
902 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
903 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
904 | + |
|
905 | + return $manager; |
|
906 | + }); |
|
907 | + /** @deprecated 19.0.0 */ |
|
908 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
909 | + |
|
910 | + /** @deprecated 20.0.0 */ |
|
911 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
912 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
913 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
914 | + if ($busClass) { |
|
915 | + [$app, $class] = explode('::', $busClass, 2); |
|
916 | + if ($c->getAppManager()->isInstalled($app)) { |
|
917 | + \OC_App::loadApp($app); |
|
918 | + return $c->query($class); |
|
919 | + } else { |
|
920 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
921 | + } |
|
922 | + } else { |
|
923 | + $jobList = $c->getJobList(); |
|
924 | + return new CronBus($jobList); |
|
925 | + } |
|
926 | + }); |
|
927 | + $this->registerAlias(IBus::class, 'AsyncCommandBus'); |
|
928 | + /** @deprecated 20.0.0 */ |
|
929 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
930 | + /** @deprecated 19.0.0 */ |
|
931 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
932 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
933 | + // IConfig and IAppManager requires a working database. This code |
|
934 | + // might however be called when ownCloud is not yet setup. |
|
935 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
936 | + $config = $c->getConfig(); |
|
937 | + $appManager = $c->getAppManager(); |
|
938 | + } else { |
|
939 | + $config = null; |
|
940 | + $appManager = null; |
|
941 | + } |
|
942 | + |
|
943 | + return new Checker( |
|
944 | + new EnvironmentHelper(), |
|
945 | + new FileAccessHelper(), |
|
946 | + new AppLocator(), |
|
947 | + $config, |
|
948 | + $c->getMemCacheFactory(), |
|
949 | + $appManager, |
|
950 | + $c->getTempManager(), |
|
951 | + $c->getMimeTypeDetector() |
|
952 | + ); |
|
953 | + }); |
|
954 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
955 | + if (isset($this['urlParams'])) { |
|
956 | + $urlParams = $this['urlParams']; |
|
957 | + } else { |
|
958 | + $urlParams = []; |
|
959 | + } |
|
960 | + |
|
961 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
962 | + && in_array('fakeinput', stream_get_wrappers()) |
|
963 | + ) { |
|
964 | + $stream = 'fakeinput://data'; |
|
965 | + } else { |
|
966 | + $stream = 'php://input'; |
|
967 | + } |
|
968 | + |
|
969 | + return new Request( |
|
970 | + [ |
|
971 | + 'get' => $_GET, |
|
972 | + 'post' => $_POST, |
|
973 | + 'files' => $_FILES, |
|
974 | + 'server' => $_SERVER, |
|
975 | + 'env' => $_ENV, |
|
976 | + 'cookies' => $_COOKIE, |
|
977 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
978 | + ? $_SERVER['REQUEST_METHOD'] |
|
979 | + : '', |
|
980 | + 'urlParams' => $urlParams, |
|
981 | + ], |
|
982 | + $this->getSecureRandom(), |
|
983 | + $this->getConfig(), |
|
984 | + $this->getCsrfTokenManager(), |
|
985 | + $stream |
|
986 | + ); |
|
987 | + }); |
|
988 | + /** @deprecated 19.0.0 */ |
|
989 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
990 | + |
|
991 | + $this->registerService(IMailer::class, function (Server $c) { |
|
992 | + return new Mailer( |
|
993 | + $c->getConfig(), |
|
994 | + $c->getLogger(), |
|
995 | + $c->query(Defaults::class), |
|
996 | + $c->getURLGenerator(), |
|
997 | + $c->getL10N('lib'), |
|
998 | + $c->query(IEventDispatcher::class), |
|
999 | + $c->getL10NFactory() |
|
1000 | + ); |
|
1001 | + }); |
|
1002 | + /** @deprecated 19.0.0 */ |
|
1003 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1004 | + |
|
1005 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
1006 | + $config = $c->getConfig(); |
|
1007 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1008 | + if (is_null($factoryClass)) { |
|
1009 | + throw new \Exception('ldapProviderFactory not set'); |
|
1010 | + } |
|
1011 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1012 | + $factory = new $factoryClass($this); |
|
1013 | + return $factory->getLDAPProvider(); |
|
1014 | + }); |
|
1015 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
1016 | + $ini = $c->get(IniGetWrapper::class); |
|
1017 | + $config = $c->getConfig(); |
|
1018 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1019 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1020 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1021 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1022 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
1023 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1024 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
1025 | + } |
|
1026 | + return new DBLockingProvider( |
|
1027 | + $c->getDatabaseConnection(), |
|
1028 | + $c->getLogger(), |
|
1029 | + new TimeFactory(), |
|
1030 | + $ttl, |
|
1031 | + !\OC::$CLI |
|
1032 | + ); |
|
1033 | + } |
|
1034 | + return new NoopLockingProvider(); |
|
1035 | + }); |
|
1036 | + /** @deprecated 19.0.0 */ |
|
1037 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1038 | + |
|
1039 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1040 | + /** @deprecated 19.0.0 */ |
|
1041 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1042 | + |
|
1043 | + $this->registerService(IMimeTypeDetector::class, function (Server $c) { |
|
1044 | + return new \OC\Files\Type\Detection( |
|
1045 | + $c->getURLGenerator(), |
|
1046 | + $c->getLogger(), |
|
1047 | + \OC::$configDir, |
|
1048 | + \OC::$SERVERROOT . '/resources/config/' |
|
1049 | + ); |
|
1050 | + }); |
|
1051 | + /** @deprecated 19.0.0 */ |
|
1052 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1053 | + |
|
1054 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1055 | + /** @deprecated 19.0.0 */ |
|
1056 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1057 | + $this->registerService(BundleFetcher::class, function () { |
|
1058 | + return new BundleFetcher($this->getL10N('lib')); |
|
1059 | + }); |
|
1060 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1061 | + /** @deprecated 19.0.0 */ |
|
1062 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1063 | + |
|
1064 | + $this->registerService(CapabilitiesManager::class, function (Server $c) { |
|
1065 | + $manager = new CapabilitiesManager($c->getLogger()); |
|
1066 | + $manager->registerCapability(function () use ($c) { |
|
1067 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
1068 | + }); |
|
1069 | + $manager->registerCapability(function () use ($c) { |
|
1070 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
1071 | + }); |
|
1072 | + return $manager; |
|
1073 | + }); |
|
1074 | + /** @deprecated 19.0.0 */ |
|
1075 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1076 | + |
|
1077 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1078 | + $config = $c->getConfig(); |
|
1079 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1080 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1081 | + $factory = new $factoryClass($this); |
|
1082 | + $manager = $factory->getManager(); |
|
1083 | + |
|
1084 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1085 | + $manager = $c->getUserManager(); |
|
1086 | + $user = $manager->get($id); |
|
1087 | + if (is_null($user)) { |
|
1088 | + $l = $c->getL10N('core'); |
|
1089 | + $displayName = $l->t('Unknown user'); |
|
1090 | + } else { |
|
1091 | + $displayName = $user->getDisplayName(); |
|
1092 | + } |
|
1093 | + return $displayName; |
|
1094 | + }); |
|
1095 | + |
|
1096 | + return $manager; |
|
1097 | + }); |
|
1098 | + /** @deprecated 19.0.0 */ |
|
1099 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1100 | + |
|
1101 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1102 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
1103 | + /* |
|
1104 | 1104 | * Dark magic for autoloader. |
1105 | 1105 | * If we do a class_exists it will try to load the class which will |
1106 | 1106 | * make composer cache the result. Resulting in errors when enabling |
1107 | 1107 | * the theming app. |
1108 | 1108 | */ |
1109 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1110 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
1111 | - $classExists = true; |
|
1112 | - } else { |
|
1113 | - $classExists = false; |
|
1114 | - } |
|
1115 | - |
|
1116 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1117 | - return new ThemingDefaults( |
|
1118 | - $c->getConfig(), |
|
1119 | - $c->getL10N('theming'), |
|
1120 | - $c->getURLGenerator(), |
|
1121 | - $c->getMemCacheFactory(), |
|
1122 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
1123 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
1124 | - $c->getAppManager(), |
|
1125 | - $c->getNavigationManager() |
|
1126 | - ); |
|
1127 | - } |
|
1128 | - return new \OC_Defaults(); |
|
1129 | - }); |
|
1130 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
1131 | - return new JSCombiner( |
|
1132 | - $c->getAppDataDir('js'), |
|
1133 | - $c->getURLGenerator(), |
|
1134 | - $this->getMemCacheFactory(), |
|
1135 | - $c->getSystemConfig(), |
|
1136 | - $c->getLogger() |
|
1137 | - ); |
|
1138 | - }); |
|
1139 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1140 | - /** @deprecated 19.0.0 */ |
|
1141 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1142 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1143 | - |
|
1144 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
1145 | - // FIXME: Instantiiated here due to cyclic dependency |
|
1146 | - $request = new Request( |
|
1147 | - [ |
|
1148 | - 'get' => $_GET, |
|
1149 | - 'post' => $_POST, |
|
1150 | - 'files' => $_FILES, |
|
1151 | - 'server' => $_SERVER, |
|
1152 | - 'env' => $_ENV, |
|
1153 | - 'cookies' => $_COOKIE, |
|
1154 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1155 | - ? $_SERVER['REQUEST_METHOD'] |
|
1156 | - : null, |
|
1157 | - ], |
|
1158 | - $c->getSecureRandom(), |
|
1159 | - $c->getConfig() |
|
1160 | - ); |
|
1161 | - |
|
1162 | - return new CryptoWrapper( |
|
1163 | - $c->getConfig(), |
|
1164 | - $c->getCrypto(), |
|
1165 | - $c->getSecureRandom(), |
|
1166 | - $request |
|
1167 | - ); |
|
1168 | - }); |
|
1169 | - /** @deprecated 19.0.0 */ |
|
1170 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1171 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1172 | - return new SessionStorage($c->getSession()); |
|
1173 | - }); |
|
1174 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1175 | - /** @deprecated 19.0.0 */ |
|
1176 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1177 | - |
|
1178 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1179 | - $config = $c->getConfig(); |
|
1180 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1181 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1182 | - $factory = new $factoryClass($this); |
|
1183 | - |
|
1184 | - $manager = new \OC\Share20\Manager( |
|
1185 | - $c->getLogger(), |
|
1186 | - $c->getConfig(), |
|
1187 | - $c->getSecureRandom(), |
|
1188 | - $c->getHasher(), |
|
1189 | - $c->getMountManager(), |
|
1190 | - $c->getGroupManager(), |
|
1191 | - $c->getL10N('lib'), |
|
1192 | - $c->getL10NFactory(), |
|
1193 | - $factory, |
|
1194 | - $c->getUserManager(), |
|
1195 | - $c->getLazyRootFolder(), |
|
1196 | - $c->getEventDispatcher(), |
|
1197 | - $c->getMailer(), |
|
1198 | - $c->getURLGenerator(), |
|
1199 | - $c->getThemingDefaults(), |
|
1200 | - $c->query(IEventDispatcher::class) |
|
1201 | - ); |
|
1202 | - |
|
1203 | - return $manager; |
|
1204 | - }); |
|
1205 | - /** @deprecated 19.0.0 */ |
|
1206 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1207 | - |
|
1208 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1209 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1210 | - |
|
1211 | - // register default plugins |
|
1212 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1213 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1214 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1215 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1216 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1217 | - |
|
1218 | - return $instance; |
|
1219 | - }); |
|
1220 | - /** @deprecated 19.0.0 */ |
|
1221 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1222 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1223 | - |
|
1224 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1225 | - |
|
1226 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1227 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1228 | - |
|
1229 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1230 | - $manager = new \OC\Settings\Manager( |
|
1231 | - $c->getLogger(), |
|
1232 | - $c->getL10NFactory(), |
|
1233 | - $c->getURLGenerator(), |
|
1234 | - $c |
|
1235 | - ); |
|
1236 | - return $manager; |
|
1237 | - }); |
|
1238 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1239 | - return new \OC\Files\AppData\Factory( |
|
1240 | - $c->getRootFolder(), |
|
1241 | - $c->getSystemConfig() |
|
1242 | - ); |
|
1243 | - }); |
|
1244 | - |
|
1245 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1246 | - return new LockdownManager(function () use ($c) { |
|
1247 | - return $c->getSession(); |
|
1248 | - }); |
|
1249 | - }); |
|
1250 | - |
|
1251 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1252 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1253 | - }); |
|
1254 | - |
|
1255 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1256 | - return new CloudIdManager(); |
|
1257 | - }); |
|
1258 | - |
|
1259 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1260 | - |
|
1261 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1262 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1263 | - }); |
|
1264 | - |
|
1265 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1266 | - return new CloudFederationFactory(); |
|
1267 | - }); |
|
1268 | - |
|
1269 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1270 | - /** @deprecated 19.0.0 */ |
|
1271 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1272 | - |
|
1273 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1274 | - /** @deprecated 19.0.0 */ |
|
1275 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1276 | - |
|
1277 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1278 | - return new Defaults( |
|
1279 | - $c->getThemingDefaults() |
|
1280 | - ); |
|
1281 | - }); |
|
1282 | - /** @deprecated 19.0.0 */ |
|
1283 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1284 | - |
|
1285 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1286 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1287 | - }); |
|
1288 | - |
|
1289 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1290 | - return new ShareHelper( |
|
1291 | - $c->query(\OCP\Share\IManager::class) |
|
1292 | - ); |
|
1293 | - }); |
|
1294 | - |
|
1295 | - $this->registerService(Installer::class, function (Server $c) { |
|
1296 | - return new Installer( |
|
1297 | - $c->getAppFetcher(), |
|
1298 | - $c->getHTTPClientService(), |
|
1299 | - $c->getTempManager(), |
|
1300 | - $c->getLogger(), |
|
1301 | - $c->getConfig(), |
|
1302 | - \OC::$CLI |
|
1303 | - ); |
|
1304 | - }); |
|
1305 | - |
|
1306 | - $this->registerService(IApiFactory::class, function (Server $c) { |
|
1307 | - return new ApiFactory($c->getHTTPClientService()); |
|
1308 | - }); |
|
1309 | - |
|
1310 | - $this->registerService(IInstanceFactory::class, function (Server $c) { |
|
1311 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1312 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1313 | - }); |
|
1314 | - |
|
1315 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1316 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1317 | - |
|
1318 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1319 | - |
|
1320 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1321 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1322 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1323 | - |
|
1324 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1325 | - |
|
1326 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1327 | - |
|
1328 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1329 | - |
|
1330 | - $this->connectDispatcher(); |
|
1331 | - } |
|
1332 | - |
|
1333 | - public function boot() { |
|
1334 | - /** @var HookConnector $hookConnector */ |
|
1335 | - $hookConnector = $this->query(HookConnector::class); |
|
1336 | - $hookConnector->viewToNode(); |
|
1337 | - } |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * @return \OCP\Calendar\IManager |
|
1341 | - * @deprecated |
|
1342 | - */ |
|
1343 | - public function getCalendarManager() { |
|
1344 | - return $this->query(\OC\Calendar\Manager::class); |
|
1345 | - } |
|
1346 | - |
|
1347 | - /** |
|
1348 | - * @return \OCP\Calendar\Resource\IManager |
|
1349 | - * @deprecated |
|
1350 | - */ |
|
1351 | - public function getCalendarResourceBackendManager() { |
|
1352 | - return $this->query(\OC\Calendar\Resource\Manager::class); |
|
1353 | - } |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * @return \OCP\Calendar\Room\IManager |
|
1357 | - * @deprecated |
|
1358 | - */ |
|
1359 | - public function getCalendarRoomBackendManager() { |
|
1360 | - return $this->query(\OC\Calendar\Room\Manager::class); |
|
1361 | - } |
|
1362 | - |
|
1363 | - private function connectDispatcher() { |
|
1364 | - $dispatcher = $this->getEventDispatcher(); |
|
1365 | - |
|
1366 | - // Delete avatar on user deletion |
|
1367 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1368 | - $logger = $this->getLogger(); |
|
1369 | - $manager = $this->getAvatarManager(); |
|
1370 | - /** @var IUser $user */ |
|
1371 | - $user = $e->getSubject(); |
|
1372 | - |
|
1373 | - try { |
|
1374 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1375 | - $avatar->remove(); |
|
1376 | - } catch (NotFoundException $e) { |
|
1377 | - // no avatar to remove |
|
1378 | - } catch (\Exception $e) { |
|
1379 | - // Ignore exceptions |
|
1380 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1381 | - } |
|
1382 | - }); |
|
1383 | - |
|
1384 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1385 | - $manager = $this->getAvatarManager(); |
|
1386 | - /** @var IUser $user */ |
|
1387 | - $user = $e->getSubject(); |
|
1388 | - $feature = $e->getArgument('feature'); |
|
1389 | - $oldValue = $e->getArgument('oldValue'); |
|
1390 | - $value = $e->getArgument('value'); |
|
1391 | - |
|
1392 | - // We only change the avatar on display name changes |
|
1393 | - if ($feature !== 'displayName') { |
|
1394 | - return; |
|
1395 | - } |
|
1396 | - |
|
1397 | - try { |
|
1398 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1399 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1400 | - } catch (NotFoundException $e) { |
|
1401 | - // no avatar to remove |
|
1402 | - } |
|
1403 | - }); |
|
1404 | - |
|
1405 | - /** @var IEventDispatcher $eventDispatched */ |
|
1406 | - $eventDispatched = $this->query(IEventDispatcher::class); |
|
1407 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1408 | - $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1409 | - } |
|
1410 | - |
|
1411 | - /** |
|
1412 | - * @return \OCP\Contacts\IManager |
|
1413 | - * @deprecated |
|
1414 | - */ |
|
1415 | - public function getContactsManager() { |
|
1416 | - return $this->query(\OCP\Contacts\IManager::class); |
|
1417 | - } |
|
1418 | - |
|
1419 | - /** |
|
1420 | - * @return \OC\Encryption\Manager |
|
1421 | - * @deprecated |
|
1422 | - */ |
|
1423 | - public function getEncryptionManager() { |
|
1424 | - return $this->query(\OCP\Encryption\IManager::class); |
|
1425 | - } |
|
1426 | - |
|
1427 | - /** |
|
1428 | - * @return \OC\Encryption\File |
|
1429 | - * @deprecated |
|
1430 | - */ |
|
1431 | - public function getEncryptionFilesHelper() { |
|
1432 | - return $this->query('EncryptionFileHelper'); |
|
1433 | - } |
|
1434 | - |
|
1435 | - /** |
|
1436 | - * @return \OCP\Encryption\Keys\IStorage |
|
1437 | - * @deprecated |
|
1438 | - */ |
|
1439 | - public function getEncryptionKeyStorage() { |
|
1440 | - return $this->query('EncryptionKeyStorage'); |
|
1441 | - } |
|
1442 | - |
|
1443 | - /** |
|
1444 | - * The current request object holding all information about the request |
|
1445 | - * currently being processed is returned from this method. |
|
1446 | - * In case the current execution was not initiated by a web request null is returned |
|
1447 | - * |
|
1448 | - * @return \OCP\IRequest |
|
1449 | - * @deprecated |
|
1450 | - */ |
|
1451 | - public function getRequest() { |
|
1452 | - return $this->query(IRequest::class); |
|
1453 | - } |
|
1454 | - |
|
1455 | - /** |
|
1456 | - * Returns the preview manager which can create preview images for a given file |
|
1457 | - * |
|
1458 | - * @return IPreview |
|
1459 | - * @deprecated |
|
1460 | - */ |
|
1461 | - public function getPreviewManager() { |
|
1462 | - return $this->query(IPreview::class); |
|
1463 | - } |
|
1464 | - |
|
1465 | - /** |
|
1466 | - * Returns the tag manager which can get and set tags for different object types |
|
1467 | - * |
|
1468 | - * @see \OCP\ITagManager::load() |
|
1469 | - * @return ITagManager |
|
1470 | - * @deprecated |
|
1471 | - */ |
|
1472 | - public function getTagManager() { |
|
1473 | - return $this->query(ITagManager::class); |
|
1474 | - } |
|
1475 | - |
|
1476 | - /** |
|
1477 | - * Returns the system-tag manager |
|
1478 | - * |
|
1479 | - * @return ISystemTagManager |
|
1480 | - * |
|
1481 | - * @since 9.0.0 |
|
1482 | - * @deprecated |
|
1483 | - */ |
|
1484 | - public function getSystemTagManager() { |
|
1485 | - return $this->query(ISystemTagManager::class); |
|
1486 | - } |
|
1487 | - |
|
1488 | - /** |
|
1489 | - * Returns the system-tag object mapper |
|
1490 | - * |
|
1491 | - * @return ISystemTagObjectMapper |
|
1492 | - * |
|
1493 | - * @since 9.0.0 |
|
1494 | - * @deprecated |
|
1495 | - */ |
|
1496 | - public function getSystemTagObjectMapper() { |
|
1497 | - return $this->query(ISystemTagObjectMapper::class); |
|
1498 | - } |
|
1499 | - |
|
1500 | - /** |
|
1501 | - * Returns the avatar manager, used for avatar functionality |
|
1502 | - * |
|
1503 | - * @return IAvatarManager |
|
1504 | - * @deprecated |
|
1505 | - */ |
|
1506 | - public function getAvatarManager() { |
|
1507 | - return $this->query(IAvatarManager::class); |
|
1508 | - } |
|
1509 | - |
|
1510 | - /** |
|
1511 | - * Returns the root folder of ownCloud's data directory |
|
1512 | - * |
|
1513 | - * @return IRootFolder |
|
1514 | - * @deprecated |
|
1515 | - */ |
|
1516 | - public function getRootFolder() { |
|
1517 | - return $this->query(IRootFolder::class); |
|
1518 | - } |
|
1519 | - |
|
1520 | - /** |
|
1521 | - * Returns the root folder of ownCloud's data directory |
|
1522 | - * This is the lazy variant so this gets only initialized once it |
|
1523 | - * is actually used. |
|
1524 | - * |
|
1525 | - * @return IRootFolder |
|
1526 | - */ |
|
1527 | - public function getLazyRootFolder() { |
|
1528 | - return $this->query(IRootFolder::class); |
|
1529 | - } |
|
1530 | - |
|
1531 | - /** |
|
1532 | - * Returns a view to ownCloud's files folder |
|
1533 | - * |
|
1534 | - * @param string $userId user ID |
|
1535 | - * @return \OCP\Files\Folder|null |
|
1536 | - * @deprecated |
|
1537 | - */ |
|
1538 | - public function getUserFolder($userId = null) { |
|
1539 | - if ($userId === null) { |
|
1540 | - $user = $this->getUserSession()->getUser(); |
|
1541 | - if (!$user) { |
|
1542 | - return null; |
|
1543 | - } |
|
1544 | - $userId = $user->getUID(); |
|
1545 | - } |
|
1546 | - $root = $this->getRootFolder(); |
|
1547 | - return $root->getUserFolder($userId); |
|
1548 | - } |
|
1549 | - |
|
1550 | - /** |
|
1551 | - * @return \OC\User\Manager |
|
1552 | - * @deprecated |
|
1553 | - */ |
|
1554 | - public function getUserManager() { |
|
1555 | - return $this->query(IUserManager::class); |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * @return \OC\Group\Manager |
|
1560 | - * @deprecated |
|
1561 | - */ |
|
1562 | - public function getGroupManager() { |
|
1563 | - return $this->query(IGroupManager::class); |
|
1564 | - } |
|
1565 | - |
|
1566 | - /** |
|
1567 | - * @return \OC\User\Session |
|
1568 | - * @deprecated |
|
1569 | - */ |
|
1570 | - public function getUserSession() { |
|
1571 | - return $this->query(IUserSession::class); |
|
1572 | - } |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * @return \OCP\ISession |
|
1576 | - * @deprecated |
|
1577 | - */ |
|
1578 | - public function getSession() { |
|
1579 | - return $this->getUserSession()->getSession(); |
|
1580 | - } |
|
1581 | - |
|
1582 | - /** |
|
1583 | - * @param \OCP\ISession $session |
|
1584 | - */ |
|
1585 | - public function setSession(\OCP\ISession $session) { |
|
1586 | - $this->query(SessionStorage::class)->setSession($session); |
|
1587 | - $this->getUserSession()->setSession($session); |
|
1588 | - $this->query(Store::class)->setSession($session); |
|
1589 | - } |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1593 | - * @deprecated |
|
1594 | - */ |
|
1595 | - public function getTwoFactorAuthManager() { |
|
1596 | - return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1597 | - } |
|
1598 | - |
|
1599 | - /** |
|
1600 | - * @return \OC\NavigationManager |
|
1601 | - * @deprecated |
|
1602 | - */ |
|
1603 | - public function getNavigationManager() { |
|
1604 | - return $this->query(INavigationManager::class); |
|
1605 | - } |
|
1606 | - |
|
1607 | - /** |
|
1608 | - * @return \OCP\IConfig |
|
1609 | - * @deprecated |
|
1610 | - */ |
|
1611 | - public function getConfig() { |
|
1612 | - return $this->query(AllConfig::class); |
|
1613 | - } |
|
1614 | - |
|
1615 | - /** |
|
1616 | - * @return \OC\SystemConfig |
|
1617 | - * @deprecated |
|
1618 | - */ |
|
1619 | - public function getSystemConfig() { |
|
1620 | - return $this->query(SystemConfig::class); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Returns the app config manager |
|
1625 | - * |
|
1626 | - * @return IAppConfig |
|
1627 | - * @deprecated |
|
1628 | - */ |
|
1629 | - public function getAppConfig() { |
|
1630 | - return $this->query(IAppConfig::class); |
|
1631 | - } |
|
1632 | - |
|
1633 | - /** |
|
1634 | - * @return IFactory |
|
1635 | - * @deprecated |
|
1636 | - */ |
|
1637 | - public function getL10NFactory() { |
|
1638 | - return $this->query(IFactory::class); |
|
1639 | - } |
|
1640 | - |
|
1641 | - /** |
|
1642 | - * get an L10N instance |
|
1643 | - * |
|
1644 | - * @param string $app appid |
|
1645 | - * @param string $lang |
|
1646 | - * @return IL10N |
|
1647 | - * @deprecated |
|
1648 | - */ |
|
1649 | - public function getL10N($app, $lang = null) { |
|
1650 | - return $this->getL10NFactory()->get($app, $lang); |
|
1651 | - } |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * @return IURLGenerator |
|
1655 | - * @deprecated |
|
1656 | - */ |
|
1657 | - public function getURLGenerator() { |
|
1658 | - return $this->query(IURLGenerator::class); |
|
1659 | - } |
|
1660 | - |
|
1661 | - /** |
|
1662 | - * @return AppFetcher |
|
1663 | - * @deprecated |
|
1664 | - */ |
|
1665 | - public function getAppFetcher() { |
|
1666 | - return $this->query(AppFetcher::class); |
|
1667 | - } |
|
1668 | - |
|
1669 | - /** |
|
1670 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1671 | - * getMemCacheFactory() instead. |
|
1672 | - * |
|
1673 | - * @return ICache |
|
1674 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1675 | - */ |
|
1676 | - public function getCache() { |
|
1677 | - return $this->query(ICache::class); |
|
1678 | - } |
|
1679 | - |
|
1680 | - /** |
|
1681 | - * Returns an \OCP\CacheFactory instance |
|
1682 | - * |
|
1683 | - * @return \OCP\ICacheFactory |
|
1684 | - * @deprecated |
|
1685 | - */ |
|
1686 | - public function getMemCacheFactory() { |
|
1687 | - return $this->query(Factory::class); |
|
1688 | - } |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * Returns an \OC\RedisFactory instance |
|
1692 | - * |
|
1693 | - * @return \OC\RedisFactory |
|
1694 | - * @deprecated |
|
1695 | - */ |
|
1696 | - public function getGetRedisFactory() { |
|
1697 | - return $this->query('RedisFactory'); |
|
1698 | - } |
|
1699 | - |
|
1700 | - |
|
1701 | - /** |
|
1702 | - * Returns the current session |
|
1703 | - * |
|
1704 | - * @return \OCP\IDBConnection |
|
1705 | - * @deprecated |
|
1706 | - */ |
|
1707 | - public function getDatabaseConnection() { |
|
1708 | - return $this->query(IDBConnection::class); |
|
1709 | - } |
|
1710 | - |
|
1711 | - /** |
|
1712 | - * Returns the activity manager |
|
1713 | - * |
|
1714 | - * @return \OCP\Activity\IManager |
|
1715 | - * @deprecated |
|
1716 | - */ |
|
1717 | - public function getActivityManager() { |
|
1718 | - return $this->query(\OCP\Activity\IManager::class); |
|
1719 | - } |
|
1720 | - |
|
1721 | - /** |
|
1722 | - * Returns an job list for controlling background jobs |
|
1723 | - * |
|
1724 | - * @return IJobList |
|
1725 | - * @deprecated |
|
1726 | - */ |
|
1727 | - public function getJobList() { |
|
1728 | - return $this->query(IJobList::class); |
|
1729 | - } |
|
1730 | - |
|
1731 | - /** |
|
1732 | - * Returns a logger instance |
|
1733 | - * |
|
1734 | - * @return ILogger |
|
1735 | - * @deprecated |
|
1736 | - */ |
|
1737 | - public function getLogger() { |
|
1738 | - return $this->query(ILogger::class); |
|
1739 | - } |
|
1740 | - |
|
1741 | - /** |
|
1742 | - * @return ILogFactory |
|
1743 | - * @throws \OCP\AppFramework\QueryException |
|
1744 | - * @deprecated |
|
1745 | - */ |
|
1746 | - public function getLogFactory() { |
|
1747 | - return $this->query(ILogFactory::class); |
|
1748 | - } |
|
1749 | - |
|
1750 | - /** |
|
1751 | - * Returns a router for generating and matching urls |
|
1752 | - * |
|
1753 | - * @return IRouter |
|
1754 | - * @deprecated |
|
1755 | - */ |
|
1756 | - public function getRouter() { |
|
1757 | - return $this->query(IRouter::class); |
|
1758 | - } |
|
1759 | - |
|
1760 | - /** |
|
1761 | - * Returns a search instance |
|
1762 | - * |
|
1763 | - * @return ISearch |
|
1764 | - * @deprecated |
|
1765 | - */ |
|
1766 | - public function getSearch() { |
|
1767 | - return $this->query(ISearch::class); |
|
1768 | - } |
|
1769 | - |
|
1770 | - /** |
|
1771 | - * Returns a SecureRandom instance |
|
1772 | - * |
|
1773 | - * @return \OCP\Security\ISecureRandom |
|
1774 | - * @deprecated |
|
1775 | - */ |
|
1776 | - public function getSecureRandom() { |
|
1777 | - return $this->query(ISecureRandom::class); |
|
1778 | - } |
|
1779 | - |
|
1780 | - /** |
|
1781 | - * Returns a Crypto instance |
|
1782 | - * |
|
1783 | - * @return ICrypto |
|
1784 | - * @deprecated |
|
1785 | - */ |
|
1786 | - public function getCrypto() { |
|
1787 | - return $this->query(ICrypto::class); |
|
1788 | - } |
|
1789 | - |
|
1790 | - /** |
|
1791 | - * Returns a Hasher instance |
|
1792 | - * |
|
1793 | - * @return IHasher |
|
1794 | - * @deprecated |
|
1795 | - */ |
|
1796 | - public function getHasher() { |
|
1797 | - return $this->query(IHasher::class); |
|
1798 | - } |
|
1799 | - |
|
1800 | - /** |
|
1801 | - * Returns a CredentialsManager instance |
|
1802 | - * |
|
1803 | - * @return ICredentialsManager |
|
1804 | - * @deprecated |
|
1805 | - */ |
|
1806 | - public function getCredentialsManager() { |
|
1807 | - return $this->query(ICredentialsManager::class); |
|
1808 | - } |
|
1809 | - |
|
1810 | - /** |
|
1811 | - * Get the certificate manager for the user |
|
1812 | - * |
|
1813 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1814 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1815 | - * @deprecated |
|
1816 | - */ |
|
1817 | - public function getCertificateManager($userId = '') { |
|
1818 | - if ($userId === '') { |
|
1819 | - $userSession = $this->getUserSession(); |
|
1820 | - $user = $userSession->getUser(); |
|
1821 | - if (is_null($user)) { |
|
1822 | - return null; |
|
1823 | - } |
|
1824 | - $userId = $user->getUID(); |
|
1825 | - } |
|
1826 | - return new CertificateManager( |
|
1827 | - $userId, |
|
1828 | - new View(), |
|
1829 | - $this->getConfig(), |
|
1830 | - $this->getLogger(), |
|
1831 | - $this->getSecureRandom() |
|
1832 | - ); |
|
1833 | - } |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * Returns an instance of the HTTP client service |
|
1837 | - * |
|
1838 | - * @return IClientService |
|
1839 | - * @deprecated |
|
1840 | - */ |
|
1841 | - public function getHTTPClientService() { |
|
1842 | - return $this->query(IClientService::class); |
|
1843 | - } |
|
1844 | - |
|
1845 | - /** |
|
1846 | - * Create a new event source |
|
1847 | - * |
|
1848 | - * @return \OCP\IEventSource |
|
1849 | - * @deprecated |
|
1850 | - */ |
|
1851 | - public function createEventSource() { |
|
1852 | - return new \OC_EventSource(); |
|
1853 | - } |
|
1854 | - |
|
1855 | - /** |
|
1856 | - * Get the active event logger |
|
1857 | - * |
|
1858 | - * The returned logger only logs data when debug mode is enabled |
|
1859 | - * |
|
1860 | - * @return IEventLogger |
|
1861 | - * @deprecated |
|
1862 | - */ |
|
1863 | - public function getEventLogger() { |
|
1864 | - return $this->query(IEventLogger::class); |
|
1865 | - } |
|
1866 | - |
|
1867 | - /** |
|
1868 | - * Get the active query logger |
|
1869 | - * |
|
1870 | - * The returned logger only logs data when debug mode is enabled |
|
1871 | - * |
|
1872 | - * @return IQueryLogger |
|
1873 | - * @deprecated |
|
1874 | - */ |
|
1875 | - public function getQueryLogger() { |
|
1876 | - return $this->query(IQueryLogger::class); |
|
1877 | - } |
|
1878 | - |
|
1879 | - /** |
|
1880 | - * Get the manager for temporary files and folders |
|
1881 | - * |
|
1882 | - * @return \OCP\ITempManager |
|
1883 | - * @deprecated |
|
1884 | - */ |
|
1885 | - public function getTempManager() { |
|
1886 | - return $this->query(ITempManager::class); |
|
1887 | - } |
|
1888 | - |
|
1889 | - /** |
|
1890 | - * Get the app manager |
|
1891 | - * |
|
1892 | - * @return \OCP\App\IAppManager |
|
1893 | - * @deprecated |
|
1894 | - */ |
|
1895 | - public function getAppManager() { |
|
1896 | - return $this->query(IAppManager::class); |
|
1897 | - } |
|
1898 | - |
|
1899 | - /** |
|
1900 | - * Creates a new mailer |
|
1901 | - * |
|
1902 | - * @return IMailer |
|
1903 | - * @deprecated |
|
1904 | - */ |
|
1905 | - public function getMailer() { |
|
1906 | - return $this->query(IMailer::class); |
|
1907 | - } |
|
1908 | - |
|
1909 | - /** |
|
1910 | - * Get the webroot |
|
1911 | - * |
|
1912 | - * @return string |
|
1913 | - * @deprecated |
|
1914 | - */ |
|
1915 | - public function getWebRoot() { |
|
1916 | - return $this->webRoot; |
|
1917 | - } |
|
1918 | - |
|
1919 | - /** |
|
1920 | - * @return \OC\OCSClient |
|
1921 | - * @deprecated |
|
1922 | - */ |
|
1923 | - public function getOcsClient() { |
|
1924 | - return $this->query('OcsClient'); |
|
1925 | - } |
|
1926 | - |
|
1927 | - /** |
|
1928 | - * @return IDateTimeZone |
|
1929 | - * @deprecated |
|
1930 | - */ |
|
1931 | - public function getDateTimeZone() { |
|
1932 | - return $this->query(IDateTimeZone::class); |
|
1933 | - } |
|
1934 | - |
|
1935 | - /** |
|
1936 | - * @return IDateTimeFormatter |
|
1937 | - * @deprecated |
|
1938 | - */ |
|
1939 | - public function getDateTimeFormatter() { |
|
1940 | - return $this->query(IDateTimeFormatter::class); |
|
1941 | - } |
|
1942 | - |
|
1943 | - /** |
|
1944 | - * @return IMountProviderCollection |
|
1945 | - * @deprecated |
|
1946 | - */ |
|
1947 | - public function getMountProviderCollection() { |
|
1948 | - return $this->query(IMountProviderCollection::class); |
|
1949 | - } |
|
1950 | - |
|
1951 | - /** |
|
1952 | - * Get the IniWrapper |
|
1953 | - * |
|
1954 | - * @return IniGetWrapper |
|
1955 | - * @deprecated |
|
1956 | - */ |
|
1957 | - public function getIniWrapper() { |
|
1958 | - return $this->query(IniGetWrapper::class); |
|
1959 | - } |
|
1960 | - |
|
1961 | - /** |
|
1962 | - * @return \OCP\Command\IBus |
|
1963 | - * @deprecated |
|
1964 | - */ |
|
1965 | - public function getCommandBus() { |
|
1966 | - return $this->query('AsyncCommandBus'); |
|
1967 | - } |
|
1968 | - |
|
1969 | - /** |
|
1970 | - * Get the trusted domain helper |
|
1971 | - * |
|
1972 | - * @return TrustedDomainHelper |
|
1973 | - * @deprecated |
|
1974 | - */ |
|
1975 | - public function getTrustedDomainHelper() { |
|
1976 | - return $this->query('TrustedDomainHelper'); |
|
1977 | - } |
|
1978 | - |
|
1979 | - /** |
|
1980 | - * Get the locking provider |
|
1981 | - * |
|
1982 | - * @return ILockingProvider |
|
1983 | - * @since 8.1.0 |
|
1984 | - * @deprecated |
|
1985 | - */ |
|
1986 | - public function getLockingProvider() { |
|
1987 | - return $this->query(ILockingProvider::class); |
|
1988 | - } |
|
1989 | - |
|
1990 | - /** |
|
1991 | - * @return IMountManager |
|
1992 | - * @deprecated |
|
1993 | - **/ |
|
1994 | - public function getMountManager() { |
|
1995 | - return $this->query(IMountManager::class); |
|
1996 | - } |
|
1997 | - |
|
1998 | - /** |
|
1999 | - * @return IUserMountCache |
|
2000 | - * @deprecated |
|
2001 | - */ |
|
2002 | - public function getUserMountCache() { |
|
2003 | - return $this->query(IUserMountCache::class); |
|
2004 | - } |
|
2005 | - |
|
2006 | - /** |
|
2007 | - * Get the MimeTypeDetector |
|
2008 | - * |
|
2009 | - * @return IMimeTypeDetector |
|
2010 | - * @deprecated |
|
2011 | - */ |
|
2012 | - public function getMimeTypeDetector() { |
|
2013 | - return $this->query(IMimeTypeDetector::class); |
|
2014 | - } |
|
2015 | - |
|
2016 | - /** |
|
2017 | - * Get the MimeTypeLoader |
|
2018 | - * |
|
2019 | - * @return IMimeTypeLoader |
|
2020 | - * @deprecated |
|
2021 | - */ |
|
2022 | - public function getMimeTypeLoader() { |
|
2023 | - return $this->query(IMimeTypeLoader::class); |
|
2024 | - } |
|
2025 | - |
|
2026 | - /** |
|
2027 | - * Get the manager of all the capabilities |
|
2028 | - * |
|
2029 | - * @return CapabilitiesManager |
|
2030 | - * @deprecated |
|
2031 | - */ |
|
2032 | - public function getCapabilitiesManager() { |
|
2033 | - return $this->query(CapabilitiesManager::class); |
|
2034 | - } |
|
2035 | - |
|
2036 | - /** |
|
2037 | - * Get the EventDispatcher |
|
2038 | - * |
|
2039 | - * @return EventDispatcherInterface |
|
2040 | - * @since 8.2.0 |
|
2041 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2042 | - */ |
|
2043 | - public function getEventDispatcher() { |
|
2044 | - return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2045 | - } |
|
2046 | - |
|
2047 | - /** |
|
2048 | - * Get the Notification Manager |
|
2049 | - * |
|
2050 | - * @return \OCP\Notification\IManager |
|
2051 | - * @since 8.2.0 |
|
2052 | - * @deprecated |
|
2053 | - */ |
|
2054 | - public function getNotificationManager() { |
|
2055 | - return $this->query(\OCP\Notification\IManager::class); |
|
2056 | - } |
|
2057 | - |
|
2058 | - /** |
|
2059 | - * @return ICommentsManager |
|
2060 | - * @deprecated |
|
2061 | - */ |
|
2062 | - public function getCommentsManager() { |
|
2063 | - return $this->query(ICommentsManager::class); |
|
2064 | - } |
|
2065 | - |
|
2066 | - /** |
|
2067 | - * @return \OCA\Theming\ThemingDefaults |
|
2068 | - * @deprecated |
|
2069 | - */ |
|
2070 | - public function getThemingDefaults() { |
|
2071 | - return $this->query('ThemingDefaults'); |
|
2072 | - } |
|
2073 | - |
|
2074 | - /** |
|
2075 | - * @return \OC\IntegrityCheck\Checker |
|
2076 | - * @deprecated |
|
2077 | - */ |
|
2078 | - public function getIntegrityCodeChecker() { |
|
2079 | - return $this->query('IntegrityCodeChecker'); |
|
2080 | - } |
|
2081 | - |
|
2082 | - /** |
|
2083 | - * @return \OC\Session\CryptoWrapper |
|
2084 | - * @deprecated |
|
2085 | - */ |
|
2086 | - public function getSessionCryptoWrapper() { |
|
2087 | - return $this->query('CryptoWrapper'); |
|
2088 | - } |
|
2089 | - |
|
2090 | - /** |
|
2091 | - * @return CsrfTokenManager |
|
2092 | - * @deprecated |
|
2093 | - */ |
|
2094 | - public function getCsrfTokenManager() { |
|
2095 | - return $this->query(CsrfTokenManager::class); |
|
2096 | - } |
|
2097 | - |
|
2098 | - /** |
|
2099 | - * @return Throttler |
|
2100 | - * @deprecated |
|
2101 | - */ |
|
2102 | - public function getBruteForceThrottler() { |
|
2103 | - return $this->query(Throttler::class); |
|
2104 | - } |
|
2105 | - |
|
2106 | - /** |
|
2107 | - * @return IContentSecurityPolicyManager |
|
2108 | - * @deprecated |
|
2109 | - */ |
|
2110 | - public function getContentSecurityPolicyManager() { |
|
2111 | - return $this->query(ContentSecurityPolicyManager::class); |
|
2112 | - } |
|
2113 | - |
|
2114 | - /** |
|
2115 | - * @return ContentSecurityPolicyNonceManager |
|
2116 | - * @deprecated |
|
2117 | - */ |
|
2118 | - public function getContentSecurityPolicyNonceManager() { |
|
2119 | - return $this->query(ContentSecurityPolicyNonceManager::class); |
|
2120 | - } |
|
2121 | - |
|
2122 | - /** |
|
2123 | - * Not a public API as of 8.2, wait for 9.0 |
|
2124 | - * |
|
2125 | - * @return \OCA\Files_External\Service\BackendService |
|
2126 | - * @deprecated |
|
2127 | - */ |
|
2128 | - public function getStoragesBackendService() { |
|
2129 | - return $this->query(BackendService::class); |
|
2130 | - } |
|
2131 | - |
|
2132 | - /** |
|
2133 | - * Not a public API as of 8.2, wait for 9.0 |
|
2134 | - * |
|
2135 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2136 | - * @deprecated |
|
2137 | - */ |
|
2138 | - public function getGlobalStoragesService() { |
|
2139 | - return $this->query(GlobalStoragesService::class); |
|
2140 | - } |
|
2141 | - |
|
2142 | - /** |
|
2143 | - * Not a public API as of 8.2, wait for 9.0 |
|
2144 | - * |
|
2145 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2146 | - * @deprecated |
|
2147 | - */ |
|
2148 | - public function getUserGlobalStoragesService() { |
|
2149 | - return $this->query(UserGlobalStoragesService::class); |
|
2150 | - } |
|
2151 | - |
|
2152 | - /** |
|
2153 | - * Not a public API as of 8.2, wait for 9.0 |
|
2154 | - * |
|
2155 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
2156 | - * @deprecated |
|
2157 | - */ |
|
2158 | - public function getUserStoragesService() { |
|
2159 | - return $this->query(UserStoragesService::class); |
|
2160 | - } |
|
2161 | - |
|
2162 | - /** |
|
2163 | - * @return \OCP\Share\IManager |
|
2164 | - * @deprecated |
|
2165 | - */ |
|
2166 | - public function getShareManager() { |
|
2167 | - return $this->query(\OCP\Share\IManager::class); |
|
2168 | - } |
|
2169 | - |
|
2170 | - /** |
|
2171 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
2172 | - * @deprecated |
|
2173 | - */ |
|
2174 | - public function getCollaboratorSearch() { |
|
2175 | - return $this->query(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2176 | - } |
|
2177 | - |
|
2178 | - /** |
|
2179 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
2180 | - * @deprecated |
|
2181 | - */ |
|
2182 | - public function getAutoCompleteManager() { |
|
2183 | - return $this->query(IManager::class); |
|
2184 | - } |
|
2185 | - |
|
2186 | - /** |
|
2187 | - * Returns the LDAP Provider |
|
2188 | - * |
|
2189 | - * @return \OCP\LDAP\ILDAPProvider |
|
2190 | - * @deprecated |
|
2191 | - */ |
|
2192 | - public function getLDAPProvider() { |
|
2193 | - return $this->query('LDAPProvider'); |
|
2194 | - } |
|
2195 | - |
|
2196 | - /** |
|
2197 | - * @return \OCP\Settings\IManager |
|
2198 | - * @deprecated |
|
2199 | - */ |
|
2200 | - public function getSettingsManager() { |
|
2201 | - return $this->query('SettingsManager'); |
|
2202 | - } |
|
2203 | - |
|
2204 | - /** |
|
2205 | - * @return \OCP\Files\IAppData |
|
2206 | - * @deprecated |
|
2207 | - */ |
|
2208 | - public function getAppDataDir($app) { |
|
2209 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
2210 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
2211 | - return $factory->get($app); |
|
2212 | - } |
|
2213 | - |
|
2214 | - /** |
|
2215 | - * @return \OCP\Lockdown\ILockdownManager |
|
2216 | - * @deprecated |
|
2217 | - */ |
|
2218 | - public function getLockdownManager() { |
|
2219 | - return $this->query('LockdownManager'); |
|
2220 | - } |
|
2221 | - |
|
2222 | - /** |
|
2223 | - * @return \OCP\Federation\ICloudIdManager |
|
2224 | - * @deprecated |
|
2225 | - */ |
|
2226 | - public function getCloudIdManager() { |
|
2227 | - return $this->query(ICloudIdManager::class); |
|
2228 | - } |
|
2229 | - |
|
2230 | - /** |
|
2231 | - * @return \OCP\GlobalScale\IConfig |
|
2232 | - * @deprecated |
|
2233 | - */ |
|
2234 | - public function getGlobalScaleConfig() { |
|
2235 | - return $this->query(IConfig::class); |
|
2236 | - } |
|
2237 | - |
|
2238 | - /** |
|
2239 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2240 | - * @deprecated |
|
2241 | - */ |
|
2242 | - public function getCloudFederationProviderManager() { |
|
2243 | - return $this->query(ICloudFederationProviderManager::class); |
|
2244 | - } |
|
2245 | - |
|
2246 | - /** |
|
2247 | - * @return \OCP\Remote\Api\IApiFactory |
|
2248 | - * @deprecated |
|
2249 | - */ |
|
2250 | - public function getRemoteApiFactory() { |
|
2251 | - return $this->query(IApiFactory::class); |
|
2252 | - } |
|
2253 | - |
|
2254 | - /** |
|
2255 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2256 | - * @deprecated |
|
2257 | - */ |
|
2258 | - public function getCloudFederationFactory() { |
|
2259 | - return $this->query(ICloudFederationFactory::class); |
|
2260 | - } |
|
2261 | - |
|
2262 | - /** |
|
2263 | - * @return \OCP\Remote\IInstanceFactory |
|
2264 | - * @deprecated |
|
2265 | - */ |
|
2266 | - public function getRemoteInstanceFactory() { |
|
2267 | - return $this->query(IInstanceFactory::class); |
|
2268 | - } |
|
2269 | - |
|
2270 | - /** |
|
2271 | - * @return IStorageFactory |
|
2272 | - * @deprecated |
|
2273 | - */ |
|
2274 | - public function getStorageFactory() { |
|
2275 | - return $this->query(IStorageFactory::class); |
|
2276 | - } |
|
2277 | - |
|
2278 | - /** |
|
2279 | - * Get the Preview GeneratorHelper |
|
2280 | - * |
|
2281 | - * @return GeneratorHelper |
|
2282 | - * @since 17.0.0 |
|
2283 | - * @deprecated |
|
2284 | - */ |
|
2285 | - public function getGeneratorHelper() { |
|
2286 | - return $this->query(\OC\Preview\GeneratorHelper::class); |
|
2287 | - } |
|
2288 | - |
|
2289 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
2290 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2291 | - try { |
|
2292 | - /** @var ILogger $logger */ |
|
2293 | - $logger = $container->get(ILogger::class); |
|
2294 | - $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2295 | - } catch (ContainerExceptionInterface $e) { |
|
2296 | - // Could not get logger. Continue |
|
2297 | - } |
|
2298 | - |
|
2299 | - return $container->get($target); |
|
2300 | - }, false); |
|
2301 | - } |
|
1109 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1110 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
1111 | + $classExists = true; |
|
1112 | + } else { |
|
1113 | + $classExists = false; |
|
1114 | + } |
|
1115 | + |
|
1116 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1117 | + return new ThemingDefaults( |
|
1118 | + $c->getConfig(), |
|
1119 | + $c->getL10N('theming'), |
|
1120 | + $c->getURLGenerator(), |
|
1121 | + $c->getMemCacheFactory(), |
|
1122 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
1123 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
1124 | + $c->getAppManager(), |
|
1125 | + $c->getNavigationManager() |
|
1126 | + ); |
|
1127 | + } |
|
1128 | + return new \OC_Defaults(); |
|
1129 | + }); |
|
1130 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
1131 | + return new JSCombiner( |
|
1132 | + $c->getAppDataDir('js'), |
|
1133 | + $c->getURLGenerator(), |
|
1134 | + $this->getMemCacheFactory(), |
|
1135 | + $c->getSystemConfig(), |
|
1136 | + $c->getLogger() |
|
1137 | + ); |
|
1138 | + }); |
|
1139 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1140 | + /** @deprecated 19.0.0 */ |
|
1141 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1142 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1143 | + |
|
1144 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
1145 | + // FIXME: Instantiiated here due to cyclic dependency |
|
1146 | + $request = new Request( |
|
1147 | + [ |
|
1148 | + 'get' => $_GET, |
|
1149 | + 'post' => $_POST, |
|
1150 | + 'files' => $_FILES, |
|
1151 | + 'server' => $_SERVER, |
|
1152 | + 'env' => $_ENV, |
|
1153 | + 'cookies' => $_COOKIE, |
|
1154 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1155 | + ? $_SERVER['REQUEST_METHOD'] |
|
1156 | + : null, |
|
1157 | + ], |
|
1158 | + $c->getSecureRandom(), |
|
1159 | + $c->getConfig() |
|
1160 | + ); |
|
1161 | + |
|
1162 | + return new CryptoWrapper( |
|
1163 | + $c->getConfig(), |
|
1164 | + $c->getCrypto(), |
|
1165 | + $c->getSecureRandom(), |
|
1166 | + $request |
|
1167 | + ); |
|
1168 | + }); |
|
1169 | + /** @deprecated 19.0.0 */ |
|
1170 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1171 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1172 | + return new SessionStorage($c->getSession()); |
|
1173 | + }); |
|
1174 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1175 | + /** @deprecated 19.0.0 */ |
|
1176 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1177 | + |
|
1178 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1179 | + $config = $c->getConfig(); |
|
1180 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1181 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1182 | + $factory = new $factoryClass($this); |
|
1183 | + |
|
1184 | + $manager = new \OC\Share20\Manager( |
|
1185 | + $c->getLogger(), |
|
1186 | + $c->getConfig(), |
|
1187 | + $c->getSecureRandom(), |
|
1188 | + $c->getHasher(), |
|
1189 | + $c->getMountManager(), |
|
1190 | + $c->getGroupManager(), |
|
1191 | + $c->getL10N('lib'), |
|
1192 | + $c->getL10NFactory(), |
|
1193 | + $factory, |
|
1194 | + $c->getUserManager(), |
|
1195 | + $c->getLazyRootFolder(), |
|
1196 | + $c->getEventDispatcher(), |
|
1197 | + $c->getMailer(), |
|
1198 | + $c->getURLGenerator(), |
|
1199 | + $c->getThemingDefaults(), |
|
1200 | + $c->query(IEventDispatcher::class) |
|
1201 | + ); |
|
1202 | + |
|
1203 | + return $manager; |
|
1204 | + }); |
|
1205 | + /** @deprecated 19.0.0 */ |
|
1206 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1207 | + |
|
1208 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1209 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1210 | + |
|
1211 | + // register default plugins |
|
1212 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1213 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1214 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1215 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1216 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1217 | + |
|
1218 | + return $instance; |
|
1219 | + }); |
|
1220 | + /** @deprecated 19.0.0 */ |
|
1221 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1222 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1223 | + |
|
1224 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1225 | + |
|
1226 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1227 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1228 | + |
|
1229 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1230 | + $manager = new \OC\Settings\Manager( |
|
1231 | + $c->getLogger(), |
|
1232 | + $c->getL10NFactory(), |
|
1233 | + $c->getURLGenerator(), |
|
1234 | + $c |
|
1235 | + ); |
|
1236 | + return $manager; |
|
1237 | + }); |
|
1238 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1239 | + return new \OC\Files\AppData\Factory( |
|
1240 | + $c->getRootFolder(), |
|
1241 | + $c->getSystemConfig() |
|
1242 | + ); |
|
1243 | + }); |
|
1244 | + |
|
1245 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1246 | + return new LockdownManager(function () use ($c) { |
|
1247 | + return $c->getSession(); |
|
1248 | + }); |
|
1249 | + }); |
|
1250 | + |
|
1251 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1252 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1253 | + }); |
|
1254 | + |
|
1255 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1256 | + return new CloudIdManager(); |
|
1257 | + }); |
|
1258 | + |
|
1259 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1260 | + |
|
1261 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1262 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1263 | + }); |
|
1264 | + |
|
1265 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1266 | + return new CloudFederationFactory(); |
|
1267 | + }); |
|
1268 | + |
|
1269 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1270 | + /** @deprecated 19.0.0 */ |
|
1271 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1272 | + |
|
1273 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1274 | + /** @deprecated 19.0.0 */ |
|
1275 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1276 | + |
|
1277 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1278 | + return new Defaults( |
|
1279 | + $c->getThemingDefaults() |
|
1280 | + ); |
|
1281 | + }); |
|
1282 | + /** @deprecated 19.0.0 */ |
|
1283 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1284 | + |
|
1285 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1286 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1287 | + }); |
|
1288 | + |
|
1289 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1290 | + return new ShareHelper( |
|
1291 | + $c->query(\OCP\Share\IManager::class) |
|
1292 | + ); |
|
1293 | + }); |
|
1294 | + |
|
1295 | + $this->registerService(Installer::class, function (Server $c) { |
|
1296 | + return new Installer( |
|
1297 | + $c->getAppFetcher(), |
|
1298 | + $c->getHTTPClientService(), |
|
1299 | + $c->getTempManager(), |
|
1300 | + $c->getLogger(), |
|
1301 | + $c->getConfig(), |
|
1302 | + \OC::$CLI |
|
1303 | + ); |
|
1304 | + }); |
|
1305 | + |
|
1306 | + $this->registerService(IApiFactory::class, function (Server $c) { |
|
1307 | + return new ApiFactory($c->getHTTPClientService()); |
|
1308 | + }); |
|
1309 | + |
|
1310 | + $this->registerService(IInstanceFactory::class, function (Server $c) { |
|
1311 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1312 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1313 | + }); |
|
1314 | + |
|
1315 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1316 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1317 | + |
|
1318 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1319 | + |
|
1320 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1321 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1322 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1323 | + |
|
1324 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1325 | + |
|
1326 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1327 | + |
|
1328 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1329 | + |
|
1330 | + $this->connectDispatcher(); |
|
1331 | + } |
|
1332 | + |
|
1333 | + public function boot() { |
|
1334 | + /** @var HookConnector $hookConnector */ |
|
1335 | + $hookConnector = $this->query(HookConnector::class); |
|
1336 | + $hookConnector->viewToNode(); |
|
1337 | + } |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * @return \OCP\Calendar\IManager |
|
1341 | + * @deprecated |
|
1342 | + */ |
|
1343 | + public function getCalendarManager() { |
|
1344 | + return $this->query(\OC\Calendar\Manager::class); |
|
1345 | + } |
|
1346 | + |
|
1347 | + /** |
|
1348 | + * @return \OCP\Calendar\Resource\IManager |
|
1349 | + * @deprecated |
|
1350 | + */ |
|
1351 | + public function getCalendarResourceBackendManager() { |
|
1352 | + return $this->query(\OC\Calendar\Resource\Manager::class); |
|
1353 | + } |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * @return \OCP\Calendar\Room\IManager |
|
1357 | + * @deprecated |
|
1358 | + */ |
|
1359 | + public function getCalendarRoomBackendManager() { |
|
1360 | + return $this->query(\OC\Calendar\Room\Manager::class); |
|
1361 | + } |
|
1362 | + |
|
1363 | + private function connectDispatcher() { |
|
1364 | + $dispatcher = $this->getEventDispatcher(); |
|
1365 | + |
|
1366 | + // Delete avatar on user deletion |
|
1367 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1368 | + $logger = $this->getLogger(); |
|
1369 | + $manager = $this->getAvatarManager(); |
|
1370 | + /** @var IUser $user */ |
|
1371 | + $user = $e->getSubject(); |
|
1372 | + |
|
1373 | + try { |
|
1374 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1375 | + $avatar->remove(); |
|
1376 | + } catch (NotFoundException $e) { |
|
1377 | + // no avatar to remove |
|
1378 | + } catch (\Exception $e) { |
|
1379 | + // Ignore exceptions |
|
1380 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1381 | + } |
|
1382 | + }); |
|
1383 | + |
|
1384 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1385 | + $manager = $this->getAvatarManager(); |
|
1386 | + /** @var IUser $user */ |
|
1387 | + $user = $e->getSubject(); |
|
1388 | + $feature = $e->getArgument('feature'); |
|
1389 | + $oldValue = $e->getArgument('oldValue'); |
|
1390 | + $value = $e->getArgument('value'); |
|
1391 | + |
|
1392 | + // We only change the avatar on display name changes |
|
1393 | + if ($feature !== 'displayName') { |
|
1394 | + return; |
|
1395 | + } |
|
1396 | + |
|
1397 | + try { |
|
1398 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1399 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1400 | + } catch (NotFoundException $e) { |
|
1401 | + // no avatar to remove |
|
1402 | + } |
|
1403 | + }); |
|
1404 | + |
|
1405 | + /** @var IEventDispatcher $eventDispatched */ |
|
1406 | + $eventDispatched = $this->query(IEventDispatcher::class); |
|
1407 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1408 | + $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1409 | + } |
|
1410 | + |
|
1411 | + /** |
|
1412 | + * @return \OCP\Contacts\IManager |
|
1413 | + * @deprecated |
|
1414 | + */ |
|
1415 | + public function getContactsManager() { |
|
1416 | + return $this->query(\OCP\Contacts\IManager::class); |
|
1417 | + } |
|
1418 | + |
|
1419 | + /** |
|
1420 | + * @return \OC\Encryption\Manager |
|
1421 | + * @deprecated |
|
1422 | + */ |
|
1423 | + public function getEncryptionManager() { |
|
1424 | + return $this->query(\OCP\Encryption\IManager::class); |
|
1425 | + } |
|
1426 | + |
|
1427 | + /** |
|
1428 | + * @return \OC\Encryption\File |
|
1429 | + * @deprecated |
|
1430 | + */ |
|
1431 | + public function getEncryptionFilesHelper() { |
|
1432 | + return $this->query('EncryptionFileHelper'); |
|
1433 | + } |
|
1434 | + |
|
1435 | + /** |
|
1436 | + * @return \OCP\Encryption\Keys\IStorage |
|
1437 | + * @deprecated |
|
1438 | + */ |
|
1439 | + public function getEncryptionKeyStorage() { |
|
1440 | + return $this->query('EncryptionKeyStorage'); |
|
1441 | + } |
|
1442 | + |
|
1443 | + /** |
|
1444 | + * The current request object holding all information about the request |
|
1445 | + * currently being processed is returned from this method. |
|
1446 | + * In case the current execution was not initiated by a web request null is returned |
|
1447 | + * |
|
1448 | + * @return \OCP\IRequest |
|
1449 | + * @deprecated |
|
1450 | + */ |
|
1451 | + public function getRequest() { |
|
1452 | + return $this->query(IRequest::class); |
|
1453 | + } |
|
1454 | + |
|
1455 | + /** |
|
1456 | + * Returns the preview manager which can create preview images for a given file |
|
1457 | + * |
|
1458 | + * @return IPreview |
|
1459 | + * @deprecated |
|
1460 | + */ |
|
1461 | + public function getPreviewManager() { |
|
1462 | + return $this->query(IPreview::class); |
|
1463 | + } |
|
1464 | + |
|
1465 | + /** |
|
1466 | + * Returns the tag manager which can get and set tags for different object types |
|
1467 | + * |
|
1468 | + * @see \OCP\ITagManager::load() |
|
1469 | + * @return ITagManager |
|
1470 | + * @deprecated |
|
1471 | + */ |
|
1472 | + public function getTagManager() { |
|
1473 | + return $this->query(ITagManager::class); |
|
1474 | + } |
|
1475 | + |
|
1476 | + /** |
|
1477 | + * Returns the system-tag manager |
|
1478 | + * |
|
1479 | + * @return ISystemTagManager |
|
1480 | + * |
|
1481 | + * @since 9.0.0 |
|
1482 | + * @deprecated |
|
1483 | + */ |
|
1484 | + public function getSystemTagManager() { |
|
1485 | + return $this->query(ISystemTagManager::class); |
|
1486 | + } |
|
1487 | + |
|
1488 | + /** |
|
1489 | + * Returns the system-tag object mapper |
|
1490 | + * |
|
1491 | + * @return ISystemTagObjectMapper |
|
1492 | + * |
|
1493 | + * @since 9.0.0 |
|
1494 | + * @deprecated |
|
1495 | + */ |
|
1496 | + public function getSystemTagObjectMapper() { |
|
1497 | + return $this->query(ISystemTagObjectMapper::class); |
|
1498 | + } |
|
1499 | + |
|
1500 | + /** |
|
1501 | + * Returns the avatar manager, used for avatar functionality |
|
1502 | + * |
|
1503 | + * @return IAvatarManager |
|
1504 | + * @deprecated |
|
1505 | + */ |
|
1506 | + public function getAvatarManager() { |
|
1507 | + return $this->query(IAvatarManager::class); |
|
1508 | + } |
|
1509 | + |
|
1510 | + /** |
|
1511 | + * Returns the root folder of ownCloud's data directory |
|
1512 | + * |
|
1513 | + * @return IRootFolder |
|
1514 | + * @deprecated |
|
1515 | + */ |
|
1516 | + public function getRootFolder() { |
|
1517 | + return $this->query(IRootFolder::class); |
|
1518 | + } |
|
1519 | + |
|
1520 | + /** |
|
1521 | + * Returns the root folder of ownCloud's data directory |
|
1522 | + * This is the lazy variant so this gets only initialized once it |
|
1523 | + * is actually used. |
|
1524 | + * |
|
1525 | + * @return IRootFolder |
|
1526 | + */ |
|
1527 | + public function getLazyRootFolder() { |
|
1528 | + return $this->query(IRootFolder::class); |
|
1529 | + } |
|
1530 | + |
|
1531 | + /** |
|
1532 | + * Returns a view to ownCloud's files folder |
|
1533 | + * |
|
1534 | + * @param string $userId user ID |
|
1535 | + * @return \OCP\Files\Folder|null |
|
1536 | + * @deprecated |
|
1537 | + */ |
|
1538 | + public function getUserFolder($userId = null) { |
|
1539 | + if ($userId === null) { |
|
1540 | + $user = $this->getUserSession()->getUser(); |
|
1541 | + if (!$user) { |
|
1542 | + return null; |
|
1543 | + } |
|
1544 | + $userId = $user->getUID(); |
|
1545 | + } |
|
1546 | + $root = $this->getRootFolder(); |
|
1547 | + return $root->getUserFolder($userId); |
|
1548 | + } |
|
1549 | + |
|
1550 | + /** |
|
1551 | + * @return \OC\User\Manager |
|
1552 | + * @deprecated |
|
1553 | + */ |
|
1554 | + public function getUserManager() { |
|
1555 | + return $this->query(IUserManager::class); |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * @return \OC\Group\Manager |
|
1560 | + * @deprecated |
|
1561 | + */ |
|
1562 | + public function getGroupManager() { |
|
1563 | + return $this->query(IGroupManager::class); |
|
1564 | + } |
|
1565 | + |
|
1566 | + /** |
|
1567 | + * @return \OC\User\Session |
|
1568 | + * @deprecated |
|
1569 | + */ |
|
1570 | + public function getUserSession() { |
|
1571 | + return $this->query(IUserSession::class); |
|
1572 | + } |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * @return \OCP\ISession |
|
1576 | + * @deprecated |
|
1577 | + */ |
|
1578 | + public function getSession() { |
|
1579 | + return $this->getUserSession()->getSession(); |
|
1580 | + } |
|
1581 | + |
|
1582 | + /** |
|
1583 | + * @param \OCP\ISession $session |
|
1584 | + */ |
|
1585 | + public function setSession(\OCP\ISession $session) { |
|
1586 | + $this->query(SessionStorage::class)->setSession($session); |
|
1587 | + $this->getUserSession()->setSession($session); |
|
1588 | + $this->query(Store::class)->setSession($session); |
|
1589 | + } |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1593 | + * @deprecated |
|
1594 | + */ |
|
1595 | + public function getTwoFactorAuthManager() { |
|
1596 | + return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1597 | + } |
|
1598 | + |
|
1599 | + /** |
|
1600 | + * @return \OC\NavigationManager |
|
1601 | + * @deprecated |
|
1602 | + */ |
|
1603 | + public function getNavigationManager() { |
|
1604 | + return $this->query(INavigationManager::class); |
|
1605 | + } |
|
1606 | + |
|
1607 | + /** |
|
1608 | + * @return \OCP\IConfig |
|
1609 | + * @deprecated |
|
1610 | + */ |
|
1611 | + public function getConfig() { |
|
1612 | + return $this->query(AllConfig::class); |
|
1613 | + } |
|
1614 | + |
|
1615 | + /** |
|
1616 | + * @return \OC\SystemConfig |
|
1617 | + * @deprecated |
|
1618 | + */ |
|
1619 | + public function getSystemConfig() { |
|
1620 | + return $this->query(SystemConfig::class); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Returns the app config manager |
|
1625 | + * |
|
1626 | + * @return IAppConfig |
|
1627 | + * @deprecated |
|
1628 | + */ |
|
1629 | + public function getAppConfig() { |
|
1630 | + return $this->query(IAppConfig::class); |
|
1631 | + } |
|
1632 | + |
|
1633 | + /** |
|
1634 | + * @return IFactory |
|
1635 | + * @deprecated |
|
1636 | + */ |
|
1637 | + public function getL10NFactory() { |
|
1638 | + return $this->query(IFactory::class); |
|
1639 | + } |
|
1640 | + |
|
1641 | + /** |
|
1642 | + * get an L10N instance |
|
1643 | + * |
|
1644 | + * @param string $app appid |
|
1645 | + * @param string $lang |
|
1646 | + * @return IL10N |
|
1647 | + * @deprecated |
|
1648 | + */ |
|
1649 | + public function getL10N($app, $lang = null) { |
|
1650 | + return $this->getL10NFactory()->get($app, $lang); |
|
1651 | + } |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * @return IURLGenerator |
|
1655 | + * @deprecated |
|
1656 | + */ |
|
1657 | + public function getURLGenerator() { |
|
1658 | + return $this->query(IURLGenerator::class); |
|
1659 | + } |
|
1660 | + |
|
1661 | + /** |
|
1662 | + * @return AppFetcher |
|
1663 | + * @deprecated |
|
1664 | + */ |
|
1665 | + public function getAppFetcher() { |
|
1666 | + return $this->query(AppFetcher::class); |
|
1667 | + } |
|
1668 | + |
|
1669 | + /** |
|
1670 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1671 | + * getMemCacheFactory() instead. |
|
1672 | + * |
|
1673 | + * @return ICache |
|
1674 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1675 | + */ |
|
1676 | + public function getCache() { |
|
1677 | + return $this->query(ICache::class); |
|
1678 | + } |
|
1679 | + |
|
1680 | + /** |
|
1681 | + * Returns an \OCP\CacheFactory instance |
|
1682 | + * |
|
1683 | + * @return \OCP\ICacheFactory |
|
1684 | + * @deprecated |
|
1685 | + */ |
|
1686 | + public function getMemCacheFactory() { |
|
1687 | + return $this->query(Factory::class); |
|
1688 | + } |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * Returns an \OC\RedisFactory instance |
|
1692 | + * |
|
1693 | + * @return \OC\RedisFactory |
|
1694 | + * @deprecated |
|
1695 | + */ |
|
1696 | + public function getGetRedisFactory() { |
|
1697 | + return $this->query('RedisFactory'); |
|
1698 | + } |
|
1699 | + |
|
1700 | + |
|
1701 | + /** |
|
1702 | + * Returns the current session |
|
1703 | + * |
|
1704 | + * @return \OCP\IDBConnection |
|
1705 | + * @deprecated |
|
1706 | + */ |
|
1707 | + public function getDatabaseConnection() { |
|
1708 | + return $this->query(IDBConnection::class); |
|
1709 | + } |
|
1710 | + |
|
1711 | + /** |
|
1712 | + * Returns the activity manager |
|
1713 | + * |
|
1714 | + * @return \OCP\Activity\IManager |
|
1715 | + * @deprecated |
|
1716 | + */ |
|
1717 | + public function getActivityManager() { |
|
1718 | + return $this->query(\OCP\Activity\IManager::class); |
|
1719 | + } |
|
1720 | + |
|
1721 | + /** |
|
1722 | + * Returns an job list for controlling background jobs |
|
1723 | + * |
|
1724 | + * @return IJobList |
|
1725 | + * @deprecated |
|
1726 | + */ |
|
1727 | + public function getJobList() { |
|
1728 | + return $this->query(IJobList::class); |
|
1729 | + } |
|
1730 | + |
|
1731 | + /** |
|
1732 | + * Returns a logger instance |
|
1733 | + * |
|
1734 | + * @return ILogger |
|
1735 | + * @deprecated |
|
1736 | + */ |
|
1737 | + public function getLogger() { |
|
1738 | + return $this->query(ILogger::class); |
|
1739 | + } |
|
1740 | + |
|
1741 | + /** |
|
1742 | + * @return ILogFactory |
|
1743 | + * @throws \OCP\AppFramework\QueryException |
|
1744 | + * @deprecated |
|
1745 | + */ |
|
1746 | + public function getLogFactory() { |
|
1747 | + return $this->query(ILogFactory::class); |
|
1748 | + } |
|
1749 | + |
|
1750 | + /** |
|
1751 | + * Returns a router for generating and matching urls |
|
1752 | + * |
|
1753 | + * @return IRouter |
|
1754 | + * @deprecated |
|
1755 | + */ |
|
1756 | + public function getRouter() { |
|
1757 | + return $this->query(IRouter::class); |
|
1758 | + } |
|
1759 | + |
|
1760 | + /** |
|
1761 | + * Returns a search instance |
|
1762 | + * |
|
1763 | + * @return ISearch |
|
1764 | + * @deprecated |
|
1765 | + */ |
|
1766 | + public function getSearch() { |
|
1767 | + return $this->query(ISearch::class); |
|
1768 | + } |
|
1769 | + |
|
1770 | + /** |
|
1771 | + * Returns a SecureRandom instance |
|
1772 | + * |
|
1773 | + * @return \OCP\Security\ISecureRandom |
|
1774 | + * @deprecated |
|
1775 | + */ |
|
1776 | + public function getSecureRandom() { |
|
1777 | + return $this->query(ISecureRandom::class); |
|
1778 | + } |
|
1779 | + |
|
1780 | + /** |
|
1781 | + * Returns a Crypto instance |
|
1782 | + * |
|
1783 | + * @return ICrypto |
|
1784 | + * @deprecated |
|
1785 | + */ |
|
1786 | + public function getCrypto() { |
|
1787 | + return $this->query(ICrypto::class); |
|
1788 | + } |
|
1789 | + |
|
1790 | + /** |
|
1791 | + * Returns a Hasher instance |
|
1792 | + * |
|
1793 | + * @return IHasher |
|
1794 | + * @deprecated |
|
1795 | + */ |
|
1796 | + public function getHasher() { |
|
1797 | + return $this->query(IHasher::class); |
|
1798 | + } |
|
1799 | + |
|
1800 | + /** |
|
1801 | + * Returns a CredentialsManager instance |
|
1802 | + * |
|
1803 | + * @return ICredentialsManager |
|
1804 | + * @deprecated |
|
1805 | + */ |
|
1806 | + public function getCredentialsManager() { |
|
1807 | + return $this->query(ICredentialsManager::class); |
|
1808 | + } |
|
1809 | + |
|
1810 | + /** |
|
1811 | + * Get the certificate manager for the user |
|
1812 | + * |
|
1813 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1814 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1815 | + * @deprecated |
|
1816 | + */ |
|
1817 | + public function getCertificateManager($userId = '') { |
|
1818 | + if ($userId === '') { |
|
1819 | + $userSession = $this->getUserSession(); |
|
1820 | + $user = $userSession->getUser(); |
|
1821 | + if (is_null($user)) { |
|
1822 | + return null; |
|
1823 | + } |
|
1824 | + $userId = $user->getUID(); |
|
1825 | + } |
|
1826 | + return new CertificateManager( |
|
1827 | + $userId, |
|
1828 | + new View(), |
|
1829 | + $this->getConfig(), |
|
1830 | + $this->getLogger(), |
|
1831 | + $this->getSecureRandom() |
|
1832 | + ); |
|
1833 | + } |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * Returns an instance of the HTTP client service |
|
1837 | + * |
|
1838 | + * @return IClientService |
|
1839 | + * @deprecated |
|
1840 | + */ |
|
1841 | + public function getHTTPClientService() { |
|
1842 | + return $this->query(IClientService::class); |
|
1843 | + } |
|
1844 | + |
|
1845 | + /** |
|
1846 | + * Create a new event source |
|
1847 | + * |
|
1848 | + * @return \OCP\IEventSource |
|
1849 | + * @deprecated |
|
1850 | + */ |
|
1851 | + public function createEventSource() { |
|
1852 | + return new \OC_EventSource(); |
|
1853 | + } |
|
1854 | + |
|
1855 | + /** |
|
1856 | + * Get the active event logger |
|
1857 | + * |
|
1858 | + * The returned logger only logs data when debug mode is enabled |
|
1859 | + * |
|
1860 | + * @return IEventLogger |
|
1861 | + * @deprecated |
|
1862 | + */ |
|
1863 | + public function getEventLogger() { |
|
1864 | + return $this->query(IEventLogger::class); |
|
1865 | + } |
|
1866 | + |
|
1867 | + /** |
|
1868 | + * Get the active query logger |
|
1869 | + * |
|
1870 | + * The returned logger only logs data when debug mode is enabled |
|
1871 | + * |
|
1872 | + * @return IQueryLogger |
|
1873 | + * @deprecated |
|
1874 | + */ |
|
1875 | + public function getQueryLogger() { |
|
1876 | + return $this->query(IQueryLogger::class); |
|
1877 | + } |
|
1878 | + |
|
1879 | + /** |
|
1880 | + * Get the manager for temporary files and folders |
|
1881 | + * |
|
1882 | + * @return \OCP\ITempManager |
|
1883 | + * @deprecated |
|
1884 | + */ |
|
1885 | + public function getTempManager() { |
|
1886 | + return $this->query(ITempManager::class); |
|
1887 | + } |
|
1888 | + |
|
1889 | + /** |
|
1890 | + * Get the app manager |
|
1891 | + * |
|
1892 | + * @return \OCP\App\IAppManager |
|
1893 | + * @deprecated |
|
1894 | + */ |
|
1895 | + public function getAppManager() { |
|
1896 | + return $this->query(IAppManager::class); |
|
1897 | + } |
|
1898 | + |
|
1899 | + /** |
|
1900 | + * Creates a new mailer |
|
1901 | + * |
|
1902 | + * @return IMailer |
|
1903 | + * @deprecated |
|
1904 | + */ |
|
1905 | + public function getMailer() { |
|
1906 | + return $this->query(IMailer::class); |
|
1907 | + } |
|
1908 | + |
|
1909 | + /** |
|
1910 | + * Get the webroot |
|
1911 | + * |
|
1912 | + * @return string |
|
1913 | + * @deprecated |
|
1914 | + */ |
|
1915 | + public function getWebRoot() { |
|
1916 | + return $this->webRoot; |
|
1917 | + } |
|
1918 | + |
|
1919 | + /** |
|
1920 | + * @return \OC\OCSClient |
|
1921 | + * @deprecated |
|
1922 | + */ |
|
1923 | + public function getOcsClient() { |
|
1924 | + return $this->query('OcsClient'); |
|
1925 | + } |
|
1926 | + |
|
1927 | + /** |
|
1928 | + * @return IDateTimeZone |
|
1929 | + * @deprecated |
|
1930 | + */ |
|
1931 | + public function getDateTimeZone() { |
|
1932 | + return $this->query(IDateTimeZone::class); |
|
1933 | + } |
|
1934 | + |
|
1935 | + /** |
|
1936 | + * @return IDateTimeFormatter |
|
1937 | + * @deprecated |
|
1938 | + */ |
|
1939 | + public function getDateTimeFormatter() { |
|
1940 | + return $this->query(IDateTimeFormatter::class); |
|
1941 | + } |
|
1942 | + |
|
1943 | + /** |
|
1944 | + * @return IMountProviderCollection |
|
1945 | + * @deprecated |
|
1946 | + */ |
|
1947 | + public function getMountProviderCollection() { |
|
1948 | + return $this->query(IMountProviderCollection::class); |
|
1949 | + } |
|
1950 | + |
|
1951 | + /** |
|
1952 | + * Get the IniWrapper |
|
1953 | + * |
|
1954 | + * @return IniGetWrapper |
|
1955 | + * @deprecated |
|
1956 | + */ |
|
1957 | + public function getIniWrapper() { |
|
1958 | + return $this->query(IniGetWrapper::class); |
|
1959 | + } |
|
1960 | + |
|
1961 | + /** |
|
1962 | + * @return \OCP\Command\IBus |
|
1963 | + * @deprecated |
|
1964 | + */ |
|
1965 | + public function getCommandBus() { |
|
1966 | + return $this->query('AsyncCommandBus'); |
|
1967 | + } |
|
1968 | + |
|
1969 | + /** |
|
1970 | + * Get the trusted domain helper |
|
1971 | + * |
|
1972 | + * @return TrustedDomainHelper |
|
1973 | + * @deprecated |
|
1974 | + */ |
|
1975 | + public function getTrustedDomainHelper() { |
|
1976 | + return $this->query('TrustedDomainHelper'); |
|
1977 | + } |
|
1978 | + |
|
1979 | + /** |
|
1980 | + * Get the locking provider |
|
1981 | + * |
|
1982 | + * @return ILockingProvider |
|
1983 | + * @since 8.1.0 |
|
1984 | + * @deprecated |
|
1985 | + */ |
|
1986 | + public function getLockingProvider() { |
|
1987 | + return $this->query(ILockingProvider::class); |
|
1988 | + } |
|
1989 | + |
|
1990 | + /** |
|
1991 | + * @return IMountManager |
|
1992 | + * @deprecated |
|
1993 | + **/ |
|
1994 | + public function getMountManager() { |
|
1995 | + return $this->query(IMountManager::class); |
|
1996 | + } |
|
1997 | + |
|
1998 | + /** |
|
1999 | + * @return IUserMountCache |
|
2000 | + * @deprecated |
|
2001 | + */ |
|
2002 | + public function getUserMountCache() { |
|
2003 | + return $this->query(IUserMountCache::class); |
|
2004 | + } |
|
2005 | + |
|
2006 | + /** |
|
2007 | + * Get the MimeTypeDetector |
|
2008 | + * |
|
2009 | + * @return IMimeTypeDetector |
|
2010 | + * @deprecated |
|
2011 | + */ |
|
2012 | + public function getMimeTypeDetector() { |
|
2013 | + return $this->query(IMimeTypeDetector::class); |
|
2014 | + } |
|
2015 | + |
|
2016 | + /** |
|
2017 | + * Get the MimeTypeLoader |
|
2018 | + * |
|
2019 | + * @return IMimeTypeLoader |
|
2020 | + * @deprecated |
|
2021 | + */ |
|
2022 | + public function getMimeTypeLoader() { |
|
2023 | + return $this->query(IMimeTypeLoader::class); |
|
2024 | + } |
|
2025 | + |
|
2026 | + /** |
|
2027 | + * Get the manager of all the capabilities |
|
2028 | + * |
|
2029 | + * @return CapabilitiesManager |
|
2030 | + * @deprecated |
|
2031 | + */ |
|
2032 | + public function getCapabilitiesManager() { |
|
2033 | + return $this->query(CapabilitiesManager::class); |
|
2034 | + } |
|
2035 | + |
|
2036 | + /** |
|
2037 | + * Get the EventDispatcher |
|
2038 | + * |
|
2039 | + * @return EventDispatcherInterface |
|
2040 | + * @since 8.2.0 |
|
2041 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2042 | + */ |
|
2043 | + public function getEventDispatcher() { |
|
2044 | + return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2045 | + } |
|
2046 | + |
|
2047 | + /** |
|
2048 | + * Get the Notification Manager |
|
2049 | + * |
|
2050 | + * @return \OCP\Notification\IManager |
|
2051 | + * @since 8.2.0 |
|
2052 | + * @deprecated |
|
2053 | + */ |
|
2054 | + public function getNotificationManager() { |
|
2055 | + return $this->query(\OCP\Notification\IManager::class); |
|
2056 | + } |
|
2057 | + |
|
2058 | + /** |
|
2059 | + * @return ICommentsManager |
|
2060 | + * @deprecated |
|
2061 | + */ |
|
2062 | + public function getCommentsManager() { |
|
2063 | + return $this->query(ICommentsManager::class); |
|
2064 | + } |
|
2065 | + |
|
2066 | + /** |
|
2067 | + * @return \OCA\Theming\ThemingDefaults |
|
2068 | + * @deprecated |
|
2069 | + */ |
|
2070 | + public function getThemingDefaults() { |
|
2071 | + return $this->query('ThemingDefaults'); |
|
2072 | + } |
|
2073 | + |
|
2074 | + /** |
|
2075 | + * @return \OC\IntegrityCheck\Checker |
|
2076 | + * @deprecated |
|
2077 | + */ |
|
2078 | + public function getIntegrityCodeChecker() { |
|
2079 | + return $this->query('IntegrityCodeChecker'); |
|
2080 | + } |
|
2081 | + |
|
2082 | + /** |
|
2083 | + * @return \OC\Session\CryptoWrapper |
|
2084 | + * @deprecated |
|
2085 | + */ |
|
2086 | + public function getSessionCryptoWrapper() { |
|
2087 | + return $this->query('CryptoWrapper'); |
|
2088 | + } |
|
2089 | + |
|
2090 | + /** |
|
2091 | + * @return CsrfTokenManager |
|
2092 | + * @deprecated |
|
2093 | + */ |
|
2094 | + public function getCsrfTokenManager() { |
|
2095 | + return $this->query(CsrfTokenManager::class); |
|
2096 | + } |
|
2097 | + |
|
2098 | + /** |
|
2099 | + * @return Throttler |
|
2100 | + * @deprecated |
|
2101 | + */ |
|
2102 | + public function getBruteForceThrottler() { |
|
2103 | + return $this->query(Throttler::class); |
|
2104 | + } |
|
2105 | + |
|
2106 | + /** |
|
2107 | + * @return IContentSecurityPolicyManager |
|
2108 | + * @deprecated |
|
2109 | + */ |
|
2110 | + public function getContentSecurityPolicyManager() { |
|
2111 | + return $this->query(ContentSecurityPolicyManager::class); |
|
2112 | + } |
|
2113 | + |
|
2114 | + /** |
|
2115 | + * @return ContentSecurityPolicyNonceManager |
|
2116 | + * @deprecated |
|
2117 | + */ |
|
2118 | + public function getContentSecurityPolicyNonceManager() { |
|
2119 | + return $this->query(ContentSecurityPolicyNonceManager::class); |
|
2120 | + } |
|
2121 | + |
|
2122 | + /** |
|
2123 | + * Not a public API as of 8.2, wait for 9.0 |
|
2124 | + * |
|
2125 | + * @return \OCA\Files_External\Service\BackendService |
|
2126 | + * @deprecated |
|
2127 | + */ |
|
2128 | + public function getStoragesBackendService() { |
|
2129 | + return $this->query(BackendService::class); |
|
2130 | + } |
|
2131 | + |
|
2132 | + /** |
|
2133 | + * Not a public API as of 8.2, wait for 9.0 |
|
2134 | + * |
|
2135 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2136 | + * @deprecated |
|
2137 | + */ |
|
2138 | + public function getGlobalStoragesService() { |
|
2139 | + return $this->query(GlobalStoragesService::class); |
|
2140 | + } |
|
2141 | + |
|
2142 | + /** |
|
2143 | + * Not a public API as of 8.2, wait for 9.0 |
|
2144 | + * |
|
2145 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2146 | + * @deprecated |
|
2147 | + */ |
|
2148 | + public function getUserGlobalStoragesService() { |
|
2149 | + return $this->query(UserGlobalStoragesService::class); |
|
2150 | + } |
|
2151 | + |
|
2152 | + /** |
|
2153 | + * Not a public API as of 8.2, wait for 9.0 |
|
2154 | + * |
|
2155 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
2156 | + * @deprecated |
|
2157 | + */ |
|
2158 | + public function getUserStoragesService() { |
|
2159 | + return $this->query(UserStoragesService::class); |
|
2160 | + } |
|
2161 | + |
|
2162 | + /** |
|
2163 | + * @return \OCP\Share\IManager |
|
2164 | + * @deprecated |
|
2165 | + */ |
|
2166 | + public function getShareManager() { |
|
2167 | + return $this->query(\OCP\Share\IManager::class); |
|
2168 | + } |
|
2169 | + |
|
2170 | + /** |
|
2171 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
2172 | + * @deprecated |
|
2173 | + */ |
|
2174 | + public function getCollaboratorSearch() { |
|
2175 | + return $this->query(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2176 | + } |
|
2177 | + |
|
2178 | + /** |
|
2179 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
2180 | + * @deprecated |
|
2181 | + */ |
|
2182 | + public function getAutoCompleteManager() { |
|
2183 | + return $this->query(IManager::class); |
|
2184 | + } |
|
2185 | + |
|
2186 | + /** |
|
2187 | + * Returns the LDAP Provider |
|
2188 | + * |
|
2189 | + * @return \OCP\LDAP\ILDAPProvider |
|
2190 | + * @deprecated |
|
2191 | + */ |
|
2192 | + public function getLDAPProvider() { |
|
2193 | + return $this->query('LDAPProvider'); |
|
2194 | + } |
|
2195 | + |
|
2196 | + /** |
|
2197 | + * @return \OCP\Settings\IManager |
|
2198 | + * @deprecated |
|
2199 | + */ |
|
2200 | + public function getSettingsManager() { |
|
2201 | + return $this->query('SettingsManager'); |
|
2202 | + } |
|
2203 | + |
|
2204 | + /** |
|
2205 | + * @return \OCP\Files\IAppData |
|
2206 | + * @deprecated |
|
2207 | + */ |
|
2208 | + public function getAppDataDir($app) { |
|
2209 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
2210 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
2211 | + return $factory->get($app); |
|
2212 | + } |
|
2213 | + |
|
2214 | + /** |
|
2215 | + * @return \OCP\Lockdown\ILockdownManager |
|
2216 | + * @deprecated |
|
2217 | + */ |
|
2218 | + public function getLockdownManager() { |
|
2219 | + return $this->query('LockdownManager'); |
|
2220 | + } |
|
2221 | + |
|
2222 | + /** |
|
2223 | + * @return \OCP\Federation\ICloudIdManager |
|
2224 | + * @deprecated |
|
2225 | + */ |
|
2226 | + public function getCloudIdManager() { |
|
2227 | + return $this->query(ICloudIdManager::class); |
|
2228 | + } |
|
2229 | + |
|
2230 | + /** |
|
2231 | + * @return \OCP\GlobalScale\IConfig |
|
2232 | + * @deprecated |
|
2233 | + */ |
|
2234 | + public function getGlobalScaleConfig() { |
|
2235 | + return $this->query(IConfig::class); |
|
2236 | + } |
|
2237 | + |
|
2238 | + /** |
|
2239 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2240 | + * @deprecated |
|
2241 | + */ |
|
2242 | + public function getCloudFederationProviderManager() { |
|
2243 | + return $this->query(ICloudFederationProviderManager::class); |
|
2244 | + } |
|
2245 | + |
|
2246 | + /** |
|
2247 | + * @return \OCP\Remote\Api\IApiFactory |
|
2248 | + * @deprecated |
|
2249 | + */ |
|
2250 | + public function getRemoteApiFactory() { |
|
2251 | + return $this->query(IApiFactory::class); |
|
2252 | + } |
|
2253 | + |
|
2254 | + /** |
|
2255 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2256 | + * @deprecated |
|
2257 | + */ |
|
2258 | + public function getCloudFederationFactory() { |
|
2259 | + return $this->query(ICloudFederationFactory::class); |
|
2260 | + } |
|
2261 | + |
|
2262 | + /** |
|
2263 | + * @return \OCP\Remote\IInstanceFactory |
|
2264 | + * @deprecated |
|
2265 | + */ |
|
2266 | + public function getRemoteInstanceFactory() { |
|
2267 | + return $this->query(IInstanceFactory::class); |
|
2268 | + } |
|
2269 | + |
|
2270 | + /** |
|
2271 | + * @return IStorageFactory |
|
2272 | + * @deprecated |
|
2273 | + */ |
|
2274 | + public function getStorageFactory() { |
|
2275 | + return $this->query(IStorageFactory::class); |
|
2276 | + } |
|
2277 | + |
|
2278 | + /** |
|
2279 | + * Get the Preview GeneratorHelper |
|
2280 | + * |
|
2281 | + * @return GeneratorHelper |
|
2282 | + * @since 17.0.0 |
|
2283 | + * @deprecated |
|
2284 | + */ |
|
2285 | + public function getGeneratorHelper() { |
|
2286 | + return $this->query(\OC\Preview\GeneratorHelper::class); |
|
2287 | + } |
|
2288 | + |
|
2289 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
2290 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2291 | + try { |
|
2292 | + /** @var ILogger $logger */ |
|
2293 | + $logger = $container->get(ILogger::class); |
|
2294 | + $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2295 | + } catch (ContainerExceptionInterface $e) { |
|
2296 | + // Could not get logger. Continue |
|
2297 | + } |
|
2298 | + |
|
2299 | + return $container->get($target); |
|
2300 | + }, false); |
|
2301 | + } |
|
2302 | 2302 | } |
@@ -32,23 +32,23 @@ |
||
32 | 32 | |
33 | 33 | class UserLoggedInListener implements IEventListener { |
34 | 34 | |
35 | - /** @var Manager */ |
|
36 | - private $manager; |
|
35 | + /** @var Manager */ |
|
36 | + private $manager; |
|
37 | 37 | |
38 | - public function __construct(Manager $manager) { |
|
39 | - $this->manager = $manager; |
|
40 | - } |
|
38 | + public function __construct(Manager $manager) { |
|
39 | + $this->manager = $manager; |
|
40 | + } |
|
41 | 41 | |
42 | - public function handle(Event $event): void { |
|
43 | - if (!($event instanceof PostLoginEvent)) { |
|
44 | - return; |
|
45 | - } |
|
42 | + public function handle(Event $event): void { |
|
43 | + if (!($event instanceof PostLoginEvent)) { |
|
44 | + return; |
|
45 | + } |
|
46 | 46 | |
47 | - // If this is already a token login there is nothing to do |
|
48 | - if ($event->isTokenLogin()) { |
|
49 | - return; |
|
50 | - } |
|
47 | + // If this is already a token login there is nothing to do |
|
48 | + if ($event->isTokenLogin()) { |
|
49 | + return; |
|
50 | + } |
|
51 | 51 | |
52 | - $this->manager->updatePasswords($event->getUser()->getUID(), $event->getPassword()); |
|
53 | - } |
|
52 | + $this->manager->updatePasswords($event->getUser()->getUID(), $event->getPassword()); |
|
53 | + } |
|
54 | 54 | } |
@@ -43,393 +43,393 @@ |
||
43 | 43 | use OCP\Security\ICrypto; |
44 | 44 | |
45 | 45 | class PublicKeyTokenProvider implements IProvider { |
46 | - /** @var PublicKeyTokenMapper */ |
|
47 | - private $mapper; |
|
48 | - |
|
49 | - /** @var ICrypto */ |
|
50 | - private $crypto; |
|
51 | - |
|
52 | - /** @var IConfig */ |
|
53 | - private $config; |
|
54 | - |
|
55 | - /** @var ILogger $logger */ |
|
56 | - private $logger; |
|
57 | - |
|
58 | - /** @var ITimeFactory $time */ |
|
59 | - private $time; |
|
60 | - |
|
61 | - /** @var CappedMemoryCache */ |
|
62 | - private $cache; |
|
63 | - |
|
64 | - public function __construct(PublicKeyTokenMapper $mapper, |
|
65 | - ICrypto $crypto, |
|
66 | - IConfig $config, |
|
67 | - ILogger $logger, |
|
68 | - ITimeFactory $time) { |
|
69 | - $this->mapper = $mapper; |
|
70 | - $this->crypto = $crypto; |
|
71 | - $this->config = $config; |
|
72 | - $this->logger = $logger; |
|
73 | - $this->time = $time; |
|
74 | - |
|
75 | - $this->cache = new CappedMemoryCache(); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritDoc} |
|
80 | - */ |
|
81 | - public function generateToken(string $token, |
|
82 | - string $uid, |
|
83 | - string $loginName, |
|
84 | - $password, |
|
85 | - string $name, |
|
86 | - int $type = IToken::TEMPORARY_TOKEN, |
|
87 | - int $remember = IToken::DO_NOT_REMEMBER): IToken { |
|
88 | - $dbToken = $this->newToken($token, $uid, $loginName, $password, $name, $type, $remember); |
|
89 | - $this->mapper->insert($dbToken); |
|
90 | - |
|
91 | - // Add the token to the cache |
|
92 | - $this->cache[$dbToken->getToken()] = $dbToken; |
|
93 | - |
|
94 | - return $dbToken; |
|
95 | - } |
|
96 | - |
|
97 | - public function getToken(string $tokenId): IToken { |
|
98 | - $tokenHash = $this->hashToken($tokenId); |
|
99 | - |
|
100 | - if (isset($this->cache[$tokenHash])) { |
|
101 | - $token = $this->cache[$tokenHash]; |
|
102 | - } else { |
|
103 | - try { |
|
104 | - $token = $this->mapper->getToken($this->hashToken($tokenId)); |
|
105 | - $this->cache[$token->getToken()] = $token; |
|
106 | - } catch (DoesNotExistException $ex) { |
|
107 | - throw new InvalidTokenException("Token does not exist: " . $ex->getMessage(), 0, $ex); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - if ((int)$token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
112 | - throw new ExpiredTokenException($token); |
|
113 | - } |
|
114 | - |
|
115 | - if ($token->getType() === IToken::WIPE_TOKEN) { |
|
116 | - throw new WipeTokenException($token); |
|
117 | - } |
|
118 | - |
|
119 | - if ($token->getPasswordInvalid() === true) { |
|
120 | - //The password is invalid we should throw an TokenPasswordExpiredException |
|
121 | - throw new TokenPasswordExpiredException($token); |
|
122 | - } |
|
123 | - |
|
124 | - return $token; |
|
125 | - } |
|
126 | - |
|
127 | - public function getTokenById(int $tokenId): IToken { |
|
128 | - try { |
|
129 | - $token = $this->mapper->getTokenById($tokenId); |
|
130 | - } catch (DoesNotExistException $ex) { |
|
131 | - throw new InvalidTokenException("Token with ID $tokenId does not exist: " . $ex->getMessage(), 0, $ex); |
|
132 | - } |
|
133 | - |
|
134 | - if ((int)$token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
135 | - throw new ExpiredTokenException($token); |
|
136 | - } |
|
137 | - |
|
138 | - if ($token->getType() === IToken::WIPE_TOKEN) { |
|
139 | - throw new WipeTokenException($token); |
|
140 | - } |
|
141 | - |
|
142 | - if ($token->getPasswordInvalid() === true) { |
|
143 | - //The password is invalid we should throw an TokenPasswordExpiredException |
|
144 | - throw new TokenPasswordExpiredException($token); |
|
145 | - } |
|
146 | - |
|
147 | - return $token; |
|
148 | - } |
|
149 | - |
|
150 | - public function renewSessionToken(string $oldSessionId, string $sessionId): IToken { |
|
151 | - $this->cache->clear(); |
|
152 | - |
|
153 | - $token = $this->getToken($oldSessionId); |
|
154 | - |
|
155 | - if (!($token instanceof PublicKeyToken)) { |
|
156 | - throw new InvalidTokenException("Invalid token type"); |
|
157 | - } |
|
158 | - |
|
159 | - $password = null; |
|
160 | - if (!is_null($token->getPassword())) { |
|
161 | - $privateKey = $this->decrypt($token->getPrivateKey(), $oldSessionId); |
|
162 | - $password = $this->decryptPassword($token->getPassword(), $privateKey); |
|
163 | - } |
|
164 | - |
|
165 | - $newToken = $this->generateToken( |
|
166 | - $sessionId, |
|
167 | - $token->getUID(), |
|
168 | - $token->getLoginName(), |
|
169 | - $password, |
|
170 | - $token->getName(), |
|
171 | - IToken::TEMPORARY_TOKEN, |
|
172 | - $token->getRemember() |
|
173 | - ); |
|
174 | - |
|
175 | - $this->mapper->delete($token); |
|
176 | - |
|
177 | - return $newToken; |
|
178 | - } |
|
179 | - |
|
180 | - public function invalidateToken(string $token) { |
|
181 | - $this->cache->clear(); |
|
182 | - |
|
183 | - $this->mapper->invalidate($this->hashToken($token)); |
|
184 | - } |
|
185 | - |
|
186 | - public function invalidateTokenById(string $uid, int $id) { |
|
187 | - $this->cache->clear(); |
|
188 | - |
|
189 | - $this->mapper->deleteById($uid, $id); |
|
190 | - } |
|
191 | - |
|
192 | - public function invalidateOldTokens() { |
|
193 | - $this->cache->clear(); |
|
194 | - |
|
195 | - $olderThan = $this->time->getTime() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
196 | - $this->logger->debug('Invalidating session tokens older than ' . date('c', $olderThan), ['app' => 'cron']); |
|
197 | - $this->mapper->invalidateOld($olderThan, IToken::DO_NOT_REMEMBER); |
|
198 | - $rememberThreshold = $this->time->getTime() - (int) $this->config->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); |
|
199 | - $this->logger->debug('Invalidating remembered session tokens older than ' . date('c', $rememberThreshold), ['app' => 'cron']); |
|
200 | - $this->mapper->invalidateOld($rememberThreshold, IToken::REMEMBER); |
|
201 | - } |
|
202 | - |
|
203 | - public function updateToken(IToken $token) { |
|
204 | - $this->cache->clear(); |
|
205 | - |
|
206 | - if (!($token instanceof PublicKeyToken)) { |
|
207 | - throw new InvalidTokenException("Invalid token type"); |
|
208 | - } |
|
209 | - $this->mapper->update($token); |
|
210 | - } |
|
211 | - |
|
212 | - public function updateTokenActivity(IToken $token) { |
|
213 | - $this->cache->clear(); |
|
214 | - |
|
215 | - if (!($token instanceof PublicKeyToken)) { |
|
216 | - throw new InvalidTokenException("Invalid token type"); |
|
217 | - } |
|
218 | - /** @var DefaultToken $token */ |
|
219 | - $now = $this->time->getTime(); |
|
220 | - if ($token->getLastActivity() < ($now - 60)) { |
|
221 | - // Update token only once per minute |
|
222 | - $token->setLastActivity($now); |
|
223 | - $this->mapper->update($token); |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - public function getTokenByUser(string $uid): array { |
|
228 | - return $this->mapper->getTokenByUser($uid); |
|
229 | - } |
|
230 | - |
|
231 | - public function getPassword(IToken $savedToken, string $tokenId): string { |
|
232 | - if (!($savedToken instanceof PublicKeyToken)) { |
|
233 | - throw new InvalidTokenException("Invalid token type"); |
|
234 | - } |
|
235 | - |
|
236 | - if ($savedToken->getPassword() === null) { |
|
237 | - throw new PasswordlessTokenException(); |
|
238 | - } |
|
239 | - |
|
240 | - // Decrypt private key with tokenId |
|
241 | - $privateKey = $this->decrypt($savedToken->getPrivateKey(), $tokenId); |
|
242 | - |
|
243 | - // Decrypt password with private key |
|
244 | - return $this->decryptPassword($savedToken->getPassword(), $privateKey); |
|
245 | - } |
|
246 | - |
|
247 | - public function setPassword(IToken $token, string $tokenId, string $password) { |
|
248 | - $this->cache->clear(); |
|
249 | - |
|
250 | - if (!($token instanceof PublicKeyToken)) { |
|
251 | - throw new InvalidTokenException("Invalid token type"); |
|
252 | - } |
|
253 | - |
|
254 | - // When changing passwords all temp tokens are deleted |
|
255 | - $this->mapper->deleteTempToken($token); |
|
256 | - |
|
257 | - // Update the password for all tokens |
|
258 | - $tokens = $this->mapper->getTokenByUser($token->getUID()); |
|
259 | - foreach ($tokens as $t) { |
|
260 | - $publicKey = $t->getPublicKey(); |
|
261 | - $t->setPassword($this->encryptPassword($password, $publicKey)); |
|
262 | - $this->updateToken($t); |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken { |
|
267 | - $this->cache->clear(); |
|
268 | - |
|
269 | - if (!($token instanceof PublicKeyToken)) { |
|
270 | - throw new InvalidTokenException("Invalid token type"); |
|
271 | - } |
|
272 | - |
|
273 | - // Decrypt private key with oldTokenId |
|
274 | - $privateKey = $this->decrypt($token->getPrivateKey(), $oldTokenId); |
|
275 | - // Encrypt with the new token |
|
276 | - $token->setPrivateKey($this->encrypt($privateKey, $newTokenId)); |
|
277 | - |
|
278 | - $token->setToken($this->hashToken($newTokenId)); |
|
279 | - $this->updateToken($token); |
|
280 | - |
|
281 | - return $token; |
|
282 | - } |
|
283 | - |
|
284 | - private function encrypt(string $plaintext, string $token): string { |
|
285 | - $secret = $this->config->getSystemValue('secret'); |
|
286 | - return $this->crypto->encrypt($plaintext, $token . $secret); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @throws InvalidTokenException |
|
291 | - */ |
|
292 | - private function decrypt(string $cipherText, string $token): string { |
|
293 | - $secret = $this->config->getSystemValue('secret'); |
|
294 | - try { |
|
295 | - return $this->crypto->decrypt($cipherText, $token . $secret); |
|
296 | - } catch (\Exception $ex) { |
|
297 | - // Delete the invalid token |
|
298 | - $this->invalidateToken($token); |
|
299 | - throw new InvalidTokenException("Could not decrypt token password: " . $ex->getMessage(), 0, $ex); |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - private function encryptPassword(string $password, string $publicKey): string { |
|
304 | - openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
305 | - $encryptedPassword = base64_encode($encryptedPassword); |
|
306 | - |
|
307 | - return $encryptedPassword; |
|
308 | - } |
|
309 | - |
|
310 | - private function decryptPassword(string $encryptedPassword, string $privateKey): string { |
|
311 | - $encryptedPassword = base64_decode($encryptedPassword); |
|
312 | - openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
313 | - |
|
314 | - return $password; |
|
315 | - } |
|
316 | - |
|
317 | - private function hashToken(string $token): string { |
|
318 | - $secret = $this->config->getSystemValue('secret'); |
|
319 | - return hash('sha512', $token . $secret); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Convert a DefaultToken to a publicKeyToken |
|
324 | - * This will also be updated directly in the Database |
|
325 | - * @throws \RuntimeException when OpenSSL reports a problem |
|
326 | - */ |
|
327 | - public function convertToken(DefaultToken $defaultToken, string $token, $password): PublicKeyToken { |
|
328 | - $this->cache->clear(); |
|
329 | - |
|
330 | - $pkToken = $this->newToken( |
|
331 | - $token, |
|
332 | - $defaultToken->getUID(), |
|
333 | - $defaultToken->getLoginName(), |
|
334 | - $password, |
|
335 | - $defaultToken->getName(), |
|
336 | - $defaultToken->getType(), |
|
337 | - $defaultToken->getRemember() |
|
338 | - ); |
|
339 | - |
|
340 | - $pkToken->setExpires($defaultToken->getExpires()); |
|
341 | - $pkToken->setId($defaultToken->getId()); |
|
342 | - |
|
343 | - return $this->mapper->update($pkToken); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * @throws \RuntimeException when OpenSSL reports a problem |
|
348 | - */ |
|
349 | - private function newToken(string $token, |
|
350 | - string $uid, |
|
351 | - string $loginName, |
|
352 | - $password, |
|
353 | - string $name, |
|
354 | - int $type, |
|
355 | - int $remember): PublicKeyToken { |
|
356 | - $dbToken = new PublicKeyToken(); |
|
357 | - $dbToken->setUid($uid); |
|
358 | - $dbToken->setLoginName($loginName); |
|
359 | - |
|
360 | - $config = array_merge([ |
|
361 | - 'digest_alg' => 'sha512', |
|
362 | - 'private_key_bits' => 2048, |
|
363 | - ], $this->config->getSystemValue('openssl', [])); |
|
364 | - |
|
365 | - // Generate new key |
|
366 | - $res = openssl_pkey_new($config); |
|
367 | - if ($res === false) { |
|
368 | - $this->logOpensslError(); |
|
369 | - throw new \RuntimeException('OpenSSL reported a problem'); |
|
370 | - } |
|
371 | - |
|
372 | - if (openssl_pkey_export($res, $privateKey, null, $config) === false) { |
|
373 | - $this->logOpensslError(); |
|
374 | - throw new \RuntimeException('OpenSSL reported a problem'); |
|
375 | - } |
|
376 | - |
|
377 | - // Extract the public key from $res to $pubKey |
|
378 | - $publicKey = openssl_pkey_get_details($res); |
|
379 | - $publicKey = $publicKey['key']; |
|
380 | - |
|
381 | - $dbToken->setPublicKey($publicKey); |
|
382 | - $dbToken->setPrivateKey($this->encrypt($privateKey, $token)); |
|
383 | - |
|
384 | - if (!is_null($password)) { |
|
385 | - $dbToken->setPassword($this->encryptPassword($password, $publicKey)); |
|
386 | - } |
|
387 | - |
|
388 | - $dbToken->setName($name); |
|
389 | - $dbToken->setToken($this->hashToken($token)); |
|
390 | - $dbToken->setType($type); |
|
391 | - $dbToken->setRemember($remember); |
|
392 | - $dbToken->setLastActivity($this->time->getTime()); |
|
393 | - $dbToken->setLastCheck($this->time->getTime()); |
|
394 | - $dbToken->setVersion(PublicKeyToken::VERSION); |
|
395 | - |
|
396 | - return $dbToken; |
|
397 | - } |
|
398 | - |
|
399 | - public function markPasswordInvalid(IToken $token, string $tokenId) { |
|
400 | - $this->cache->clear(); |
|
401 | - |
|
402 | - if (!($token instanceof PublicKeyToken)) { |
|
403 | - throw new InvalidTokenException("Invalid token type"); |
|
404 | - } |
|
405 | - |
|
406 | - $token->setPasswordInvalid(true); |
|
407 | - $this->mapper->update($token); |
|
408 | - } |
|
409 | - |
|
410 | - public function updatePasswords(string $uid, string $password) { |
|
411 | - $this->cache->clear(); |
|
412 | - |
|
413 | - if (!$this->mapper->hasExpiredTokens($uid)) { |
|
414 | - // Nothing to do here |
|
415 | - return; |
|
416 | - } |
|
417 | - |
|
418 | - // Update the password for all tokens |
|
419 | - $tokens = $this->mapper->getTokenByUser($uid); |
|
420 | - foreach ($tokens as $t) { |
|
421 | - $publicKey = $t->getPublicKey(); |
|
422 | - $t->setPassword($this->encryptPassword($password, $publicKey)); |
|
423 | - $t->setPasswordInvalid(false); |
|
424 | - $this->updateToken($t); |
|
425 | - } |
|
426 | - } |
|
427 | - |
|
428 | - private function logOpensslError() { |
|
429 | - $errors = []; |
|
430 | - while ($error = openssl_error_string()) { |
|
431 | - $errors[] = $error; |
|
432 | - } |
|
433 | - $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors)); |
|
434 | - } |
|
46 | + /** @var PublicKeyTokenMapper */ |
|
47 | + private $mapper; |
|
48 | + |
|
49 | + /** @var ICrypto */ |
|
50 | + private $crypto; |
|
51 | + |
|
52 | + /** @var IConfig */ |
|
53 | + private $config; |
|
54 | + |
|
55 | + /** @var ILogger $logger */ |
|
56 | + private $logger; |
|
57 | + |
|
58 | + /** @var ITimeFactory $time */ |
|
59 | + private $time; |
|
60 | + |
|
61 | + /** @var CappedMemoryCache */ |
|
62 | + private $cache; |
|
63 | + |
|
64 | + public function __construct(PublicKeyTokenMapper $mapper, |
|
65 | + ICrypto $crypto, |
|
66 | + IConfig $config, |
|
67 | + ILogger $logger, |
|
68 | + ITimeFactory $time) { |
|
69 | + $this->mapper = $mapper; |
|
70 | + $this->crypto = $crypto; |
|
71 | + $this->config = $config; |
|
72 | + $this->logger = $logger; |
|
73 | + $this->time = $time; |
|
74 | + |
|
75 | + $this->cache = new CappedMemoryCache(); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritDoc} |
|
80 | + */ |
|
81 | + public function generateToken(string $token, |
|
82 | + string $uid, |
|
83 | + string $loginName, |
|
84 | + $password, |
|
85 | + string $name, |
|
86 | + int $type = IToken::TEMPORARY_TOKEN, |
|
87 | + int $remember = IToken::DO_NOT_REMEMBER): IToken { |
|
88 | + $dbToken = $this->newToken($token, $uid, $loginName, $password, $name, $type, $remember); |
|
89 | + $this->mapper->insert($dbToken); |
|
90 | + |
|
91 | + // Add the token to the cache |
|
92 | + $this->cache[$dbToken->getToken()] = $dbToken; |
|
93 | + |
|
94 | + return $dbToken; |
|
95 | + } |
|
96 | + |
|
97 | + public function getToken(string $tokenId): IToken { |
|
98 | + $tokenHash = $this->hashToken($tokenId); |
|
99 | + |
|
100 | + if (isset($this->cache[$tokenHash])) { |
|
101 | + $token = $this->cache[$tokenHash]; |
|
102 | + } else { |
|
103 | + try { |
|
104 | + $token = $this->mapper->getToken($this->hashToken($tokenId)); |
|
105 | + $this->cache[$token->getToken()] = $token; |
|
106 | + } catch (DoesNotExistException $ex) { |
|
107 | + throw new InvalidTokenException("Token does not exist: " . $ex->getMessage(), 0, $ex); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + if ((int)$token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
112 | + throw new ExpiredTokenException($token); |
|
113 | + } |
|
114 | + |
|
115 | + if ($token->getType() === IToken::WIPE_TOKEN) { |
|
116 | + throw new WipeTokenException($token); |
|
117 | + } |
|
118 | + |
|
119 | + if ($token->getPasswordInvalid() === true) { |
|
120 | + //The password is invalid we should throw an TokenPasswordExpiredException |
|
121 | + throw new TokenPasswordExpiredException($token); |
|
122 | + } |
|
123 | + |
|
124 | + return $token; |
|
125 | + } |
|
126 | + |
|
127 | + public function getTokenById(int $tokenId): IToken { |
|
128 | + try { |
|
129 | + $token = $this->mapper->getTokenById($tokenId); |
|
130 | + } catch (DoesNotExistException $ex) { |
|
131 | + throw new InvalidTokenException("Token with ID $tokenId does not exist: " . $ex->getMessage(), 0, $ex); |
|
132 | + } |
|
133 | + |
|
134 | + if ((int)$token->getExpires() !== 0 && $token->getExpires() < $this->time->getTime()) { |
|
135 | + throw new ExpiredTokenException($token); |
|
136 | + } |
|
137 | + |
|
138 | + if ($token->getType() === IToken::WIPE_TOKEN) { |
|
139 | + throw new WipeTokenException($token); |
|
140 | + } |
|
141 | + |
|
142 | + if ($token->getPasswordInvalid() === true) { |
|
143 | + //The password is invalid we should throw an TokenPasswordExpiredException |
|
144 | + throw new TokenPasswordExpiredException($token); |
|
145 | + } |
|
146 | + |
|
147 | + return $token; |
|
148 | + } |
|
149 | + |
|
150 | + public function renewSessionToken(string $oldSessionId, string $sessionId): IToken { |
|
151 | + $this->cache->clear(); |
|
152 | + |
|
153 | + $token = $this->getToken($oldSessionId); |
|
154 | + |
|
155 | + if (!($token instanceof PublicKeyToken)) { |
|
156 | + throw new InvalidTokenException("Invalid token type"); |
|
157 | + } |
|
158 | + |
|
159 | + $password = null; |
|
160 | + if (!is_null($token->getPassword())) { |
|
161 | + $privateKey = $this->decrypt($token->getPrivateKey(), $oldSessionId); |
|
162 | + $password = $this->decryptPassword($token->getPassword(), $privateKey); |
|
163 | + } |
|
164 | + |
|
165 | + $newToken = $this->generateToken( |
|
166 | + $sessionId, |
|
167 | + $token->getUID(), |
|
168 | + $token->getLoginName(), |
|
169 | + $password, |
|
170 | + $token->getName(), |
|
171 | + IToken::TEMPORARY_TOKEN, |
|
172 | + $token->getRemember() |
|
173 | + ); |
|
174 | + |
|
175 | + $this->mapper->delete($token); |
|
176 | + |
|
177 | + return $newToken; |
|
178 | + } |
|
179 | + |
|
180 | + public function invalidateToken(string $token) { |
|
181 | + $this->cache->clear(); |
|
182 | + |
|
183 | + $this->mapper->invalidate($this->hashToken($token)); |
|
184 | + } |
|
185 | + |
|
186 | + public function invalidateTokenById(string $uid, int $id) { |
|
187 | + $this->cache->clear(); |
|
188 | + |
|
189 | + $this->mapper->deleteById($uid, $id); |
|
190 | + } |
|
191 | + |
|
192 | + public function invalidateOldTokens() { |
|
193 | + $this->cache->clear(); |
|
194 | + |
|
195 | + $olderThan = $this->time->getTime() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
196 | + $this->logger->debug('Invalidating session tokens older than ' . date('c', $olderThan), ['app' => 'cron']); |
|
197 | + $this->mapper->invalidateOld($olderThan, IToken::DO_NOT_REMEMBER); |
|
198 | + $rememberThreshold = $this->time->getTime() - (int) $this->config->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); |
|
199 | + $this->logger->debug('Invalidating remembered session tokens older than ' . date('c', $rememberThreshold), ['app' => 'cron']); |
|
200 | + $this->mapper->invalidateOld($rememberThreshold, IToken::REMEMBER); |
|
201 | + } |
|
202 | + |
|
203 | + public function updateToken(IToken $token) { |
|
204 | + $this->cache->clear(); |
|
205 | + |
|
206 | + if (!($token instanceof PublicKeyToken)) { |
|
207 | + throw new InvalidTokenException("Invalid token type"); |
|
208 | + } |
|
209 | + $this->mapper->update($token); |
|
210 | + } |
|
211 | + |
|
212 | + public function updateTokenActivity(IToken $token) { |
|
213 | + $this->cache->clear(); |
|
214 | + |
|
215 | + if (!($token instanceof PublicKeyToken)) { |
|
216 | + throw new InvalidTokenException("Invalid token type"); |
|
217 | + } |
|
218 | + /** @var DefaultToken $token */ |
|
219 | + $now = $this->time->getTime(); |
|
220 | + if ($token->getLastActivity() < ($now - 60)) { |
|
221 | + // Update token only once per minute |
|
222 | + $token->setLastActivity($now); |
|
223 | + $this->mapper->update($token); |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + public function getTokenByUser(string $uid): array { |
|
228 | + return $this->mapper->getTokenByUser($uid); |
|
229 | + } |
|
230 | + |
|
231 | + public function getPassword(IToken $savedToken, string $tokenId): string { |
|
232 | + if (!($savedToken instanceof PublicKeyToken)) { |
|
233 | + throw new InvalidTokenException("Invalid token type"); |
|
234 | + } |
|
235 | + |
|
236 | + if ($savedToken->getPassword() === null) { |
|
237 | + throw new PasswordlessTokenException(); |
|
238 | + } |
|
239 | + |
|
240 | + // Decrypt private key with tokenId |
|
241 | + $privateKey = $this->decrypt($savedToken->getPrivateKey(), $tokenId); |
|
242 | + |
|
243 | + // Decrypt password with private key |
|
244 | + return $this->decryptPassword($savedToken->getPassword(), $privateKey); |
|
245 | + } |
|
246 | + |
|
247 | + public function setPassword(IToken $token, string $tokenId, string $password) { |
|
248 | + $this->cache->clear(); |
|
249 | + |
|
250 | + if (!($token instanceof PublicKeyToken)) { |
|
251 | + throw new InvalidTokenException("Invalid token type"); |
|
252 | + } |
|
253 | + |
|
254 | + // When changing passwords all temp tokens are deleted |
|
255 | + $this->mapper->deleteTempToken($token); |
|
256 | + |
|
257 | + // Update the password for all tokens |
|
258 | + $tokens = $this->mapper->getTokenByUser($token->getUID()); |
|
259 | + foreach ($tokens as $t) { |
|
260 | + $publicKey = $t->getPublicKey(); |
|
261 | + $t->setPassword($this->encryptPassword($password, $publicKey)); |
|
262 | + $this->updateToken($t); |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken { |
|
267 | + $this->cache->clear(); |
|
268 | + |
|
269 | + if (!($token instanceof PublicKeyToken)) { |
|
270 | + throw new InvalidTokenException("Invalid token type"); |
|
271 | + } |
|
272 | + |
|
273 | + // Decrypt private key with oldTokenId |
|
274 | + $privateKey = $this->decrypt($token->getPrivateKey(), $oldTokenId); |
|
275 | + // Encrypt with the new token |
|
276 | + $token->setPrivateKey($this->encrypt($privateKey, $newTokenId)); |
|
277 | + |
|
278 | + $token->setToken($this->hashToken($newTokenId)); |
|
279 | + $this->updateToken($token); |
|
280 | + |
|
281 | + return $token; |
|
282 | + } |
|
283 | + |
|
284 | + private function encrypt(string $plaintext, string $token): string { |
|
285 | + $secret = $this->config->getSystemValue('secret'); |
|
286 | + return $this->crypto->encrypt($plaintext, $token . $secret); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @throws InvalidTokenException |
|
291 | + */ |
|
292 | + private function decrypt(string $cipherText, string $token): string { |
|
293 | + $secret = $this->config->getSystemValue('secret'); |
|
294 | + try { |
|
295 | + return $this->crypto->decrypt($cipherText, $token . $secret); |
|
296 | + } catch (\Exception $ex) { |
|
297 | + // Delete the invalid token |
|
298 | + $this->invalidateToken($token); |
|
299 | + throw new InvalidTokenException("Could not decrypt token password: " . $ex->getMessage(), 0, $ex); |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + private function encryptPassword(string $password, string $publicKey): string { |
|
304 | + openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
305 | + $encryptedPassword = base64_encode($encryptedPassword); |
|
306 | + |
|
307 | + return $encryptedPassword; |
|
308 | + } |
|
309 | + |
|
310 | + private function decryptPassword(string $encryptedPassword, string $privateKey): string { |
|
311 | + $encryptedPassword = base64_decode($encryptedPassword); |
|
312 | + openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
313 | + |
|
314 | + return $password; |
|
315 | + } |
|
316 | + |
|
317 | + private function hashToken(string $token): string { |
|
318 | + $secret = $this->config->getSystemValue('secret'); |
|
319 | + return hash('sha512', $token . $secret); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Convert a DefaultToken to a publicKeyToken |
|
324 | + * This will also be updated directly in the Database |
|
325 | + * @throws \RuntimeException when OpenSSL reports a problem |
|
326 | + */ |
|
327 | + public function convertToken(DefaultToken $defaultToken, string $token, $password): PublicKeyToken { |
|
328 | + $this->cache->clear(); |
|
329 | + |
|
330 | + $pkToken = $this->newToken( |
|
331 | + $token, |
|
332 | + $defaultToken->getUID(), |
|
333 | + $defaultToken->getLoginName(), |
|
334 | + $password, |
|
335 | + $defaultToken->getName(), |
|
336 | + $defaultToken->getType(), |
|
337 | + $defaultToken->getRemember() |
|
338 | + ); |
|
339 | + |
|
340 | + $pkToken->setExpires($defaultToken->getExpires()); |
|
341 | + $pkToken->setId($defaultToken->getId()); |
|
342 | + |
|
343 | + return $this->mapper->update($pkToken); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * @throws \RuntimeException when OpenSSL reports a problem |
|
348 | + */ |
|
349 | + private function newToken(string $token, |
|
350 | + string $uid, |
|
351 | + string $loginName, |
|
352 | + $password, |
|
353 | + string $name, |
|
354 | + int $type, |
|
355 | + int $remember): PublicKeyToken { |
|
356 | + $dbToken = new PublicKeyToken(); |
|
357 | + $dbToken->setUid($uid); |
|
358 | + $dbToken->setLoginName($loginName); |
|
359 | + |
|
360 | + $config = array_merge([ |
|
361 | + 'digest_alg' => 'sha512', |
|
362 | + 'private_key_bits' => 2048, |
|
363 | + ], $this->config->getSystemValue('openssl', [])); |
|
364 | + |
|
365 | + // Generate new key |
|
366 | + $res = openssl_pkey_new($config); |
|
367 | + if ($res === false) { |
|
368 | + $this->logOpensslError(); |
|
369 | + throw new \RuntimeException('OpenSSL reported a problem'); |
|
370 | + } |
|
371 | + |
|
372 | + if (openssl_pkey_export($res, $privateKey, null, $config) === false) { |
|
373 | + $this->logOpensslError(); |
|
374 | + throw new \RuntimeException('OpenSSL reported a problem'); |
|
375 | + } |
|
376 | + |
|
377 | + // Extract the public key from $res to $pubKey |
|
378 | + $publicKey = openssl_pkey_get_details($res); |
|
379 | + $publicKey = $publicKey['key']; |
|
380 | + |
|
381 | + $dbToken->setPublicKey($publicKey); |
|
382 | + $dbToken->setPrivateKey($this->encrypt($privateKey, $token)); |
|
383 | + |
|
384 | + if (!is_null($password)) { |
|
385 | + $dbToken->setPassword($this->encryptPassword($password, $publicKey)); |
|
386 | + } |
|
387 | + |
|
388 | + $dbToken->setName($name); |
|
389 | + $dbToken->setToken($this->hashToken($token)); |
|
390 | + $dbToken->setType($type); |
|
391 | + $dbToken->setRemember($remember); |
|
392 | + $dbToken->setLastActivity($this->time->getTime()); |
|
393 | + $dbToken->setLastCheck($this->time->getTime()); |
|
394 | + $dbToken->setVersion(PublicKeyToken::VERSION); |
|
395 | + |
|
396 | + return $dbToken; |
|
397 | + } |
|
398 | + |
|
399 | + public function markPasswordInvalid(IToken $token, string $tokenId) { |
|
400 | + $this->cache->clear(); |
|
401 | + |
|
402 | + if (!($token instanceof PublicKeyToken)) { |
|
403 | + throw new InvalidTokenException("Invalid token type"); |
|
404 | + } |
|
405 | + |
|
406 | + $token->setPasswordInvalid(true); |
|
407 | + $this->mapper->update($token); |
|
408 | + } |
|
409 | + |
|
410 | + public function updatePasswords(string $uid, string $password) { |
|
411 | + $this->cache->clear(); |
|
412 | + |
|
413 | + if (!$this->mapper->hasExpiredTokens($uid)) { |
|
414 | + // Nothing to do here |
|
415 | + return; |
|
416 | + } |
|
417 | + |
|
418 | + // Update the password for all tokens |
|
419 | + $tokens = $this->mapper->getTokenByUser($uid); |
|
420 | + foreach ($tokens as $t) { |
|
421 | + $publicKey = $t->getPublicKey(); |
|
422 | + $t->setPassword($this->encryptPassword($password, $publicKey)); |
|
423 | + $t->setPasswordInvalid(false); |
|
424 | + $this->updateToken($t); |
|
425 | + } |
|
426 | + } |
|
427 | + |
|
428 | + private function logOpensslError() { |
|
429 | + $errors = []; |
|
430 | + while ($error = openssl_error_string()) { |
|
431 | + $errors[] = $error; |
|
432 | + } |
|
433 | + $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors)); |
|
434 | + } |
|
435 | 435 | } |