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