Completed
Pull Request — master (#9632)
by Christoph
20:58
created
lib/private/Server.php 1 patch
Indentation   +1816 added lines, -1816 removed lines patch added patch discarded remove patch
@@ -153,1825 +153,1825 @@
 block discarded – undo
153 153
  * TODO: hookup all manager classes
154 154
  */
155 155
 class Server extends ServerContainer implements IServerContainer {
156
-	/** @var string */
157
-	private $webRoot;
158
-
159
-	/**
160
-	 * @param string $webRoot
161
-	 * @param \OC\Config $config
162
-	 */
163
-	public function __construct($webRoot, \OC\Config $config) {
164
-		parent::__construct();
165
-		$this->webRoot = $webRoot;
166
-
167
-		// To find out if we are running from CLI or not
168
-		$this->registerParameter('isCLI', \OC::$CLI);
169
-
170
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
171
-			return $c;
172
-		});
173
-
174
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
175
-		$this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
176
-
177
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
178
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
179
-
180
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
181
-
182
-
183
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
184
-			return new PreviewManager(
185
-				$c->getConfig(),
186
-				$c->getRootFolder(),
187
-				$c->getAppDataDir('preview'),
188
-				$c->getEventDispatcher(),
189
-				$c->getSession()->get('user_id')
190
-			);
191
-		});
192
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
193
-
194
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
195
-			return new \OC\Preview\Watcher(
196
-				$c->getAppDataDir('preview')
197
-			);
198
-		});
199
-
200
-		$this->registerService('EncryptionManager', function (Server $c) {
201
-			$view = new View();
202
-			$util = new Encryption\Util(
203
-				$view,
204
-				$c->getUserManager(),
205
-				$c->getGroupManager(),
206
-				$c->getConfig()
207
-			);
208
-			return new Encryption\Manager(
209
-				$c->getConfig(),
210
-				$c->getLogger(),
211
-				$c->getL10N('core'),
212
-				new View(),
213
-				$util,
214
-				new ArrayCache()
215
-			);
216
-		});
217
-
218
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
219
-			$util = new Encryption\Util(
220
-				new View(),
221
-				$c->getUserManager(),
222
-				$c->getGroupManager(),
223
-				$c->getConfig()
224
-			);
225
-			return new Encryption\File(
226
-				$util,
227
-				$c->getRootFolder(),
228
-				$c->getShareManager()
229
-			);
230
-		});
231
-
232
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
233
-			$view = new View();
234
-			$util = new Encryption\Util(
235
-				$view,
236
-				$c->getUserManager(),
237
-				$c->getGroupManager(),
238
-				$c->getConfig()
239
-			);
240
-
241
-			return new Encryption\Keys\Storage($view, $util);
242
-		});
243
-		$this->registerService('TagMapper', function (Server $c) {
244
-			return new TagMapper($c->getDatabaseConnection());
245
-		});
246
-
247
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
248
-			$tagMapper = $c->query('TagMapper');
249
-			return new TagManager($tagMapper, $c->getUserSession());
250
-		});
251
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
252
-
253
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
254
-			$config = $c->getConfig();
255
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
256
-			return new $factoryClass($this);
257
-		});
258
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
259
-			return $c->query('SystemTagManagerFactory')->getManager();
260
-		});
261
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
262
-
263
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
264
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
265
-		});
266
-		$this->registerService('RootFolder', function (Server $c) {
267
-			$manager = \OC\Files\Filesystem::getMountManager(null);
268
-			$view = new View();
269
-			$root = new Root(
270
-				$manager,
271
-				$view,
272
-				null,
273
-				$c->getUserMountCache(),
274
-				$this->getLogger(),
275
-				$this->getUserManager()
276
-			);
277
-			$connector = new HookConnector($root, $view);
278
-			$connector->viewToNode();
279
-
280
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
281
-			$previewConnector->connectWatcher();
282
-
283
-			return $root;
284
-		});
285
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
286
-
287
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
288
-			return new LazyRoot(function () use ($c) {
289
-				return $c->query('RootFolder');
290
-			});
291
-		});
292
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
293
-
294
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
295
-			$config = $c->getConfig();
296
-			return new \OC\User\Manager($config);
297
-		});
298
-		$this->registerAlias('UserManager', \OC\User\Manager::class);
299
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
300
-
301
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
302
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
303
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
304
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
305
-			});
306
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
307
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
308
-			});
309
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
310
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
311
-			});
312
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
313
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
314
-			});
315
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
316
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
317
-			});
318
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
319
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
320
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
321
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
322
-			});
323
-			return $groupManager;
324
-		});
325
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
326
-
327
-		$this->registerService(Store::class, function (Server $c) {
328
-			$session = $c->getSession();
329
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
330
-				$tokenProvider = $c->query(IProvider::class);
331
-			} else {
332
-				$tokenProvider = null;
333
-			}
334
-			$logger = $c->getLogger();
335
-			return new Store($session, $logger, $tokenProvider);
336
-		});
337
-		$this->registerAlias(IStore::class, Store::class);
338
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
339
-			$dbConnection = $c->getDatabaseConnection();
340
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
341
-		});
342
-		$this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) {
343
-			$mapper = $c->query(Authentication\Token\DefaultTokenMapper::class);
344
-			$crypto = $c->getCrypto();
345
-			$config = $c->getConfig();
346
-			$logger = $c->getLogger();
347
-			$timeFactory = new TimeFactory();
348
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
349
-		});
350
-		$this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class);
351
-
352
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
353
-			$manager = $c->getUserManager();
354
-			$session = new \OC\Session\Memory('');
355
-			$timeFactory = new TimeFactory();
356
-			// Token providers might require a working database. This code
357
-			// might however be called when ownCloud is not yet setup.
358
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
359
-				$defaultTokenProvider = $c->query(IProvider::class);
360
-			} else {
361
-				$defaultTokenProvider = null;
362
-			}
363
-
364
-			$dispatcher = $c->getEventDispatcher();
365
-
366
-			$userSession = new \OC\User\Session(
367
-				$manager,
368
-				$session,
369
-				$timeFactory,
370
-				$defaultTokenProvider,
371
-				$c->getConfig(),
372
-				$c->getSecureRandom(),
373
-				$c->getLockdownManager(),
374
-				$c->getLogger()
375
-			);
376
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
377
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
378
-			});
379
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
380
-				/** @var $user \OC\User\User */
381
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
382
-			});
383
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
384
-				/** @var $user \OC\User\User */
385
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
386
-				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
387
-			});
388
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
389
-				/** @var $user \OC\User\User */
390
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
391
-			});
392
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
393
-				/** @var $user \OC\User\User */
394
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
395
-			});
396
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
397
-				/** @var $user \OC\User\User */
398
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
399
-			});
400
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
401
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
402
-			});
403
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
404
-				/** @var $user \OC\User\User */
405
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
406
-			});
407
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
408
-				/** @var $user \OC\User\User */
409
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
410
-			});
411
-			$userSession->listen('\OC\User', 'logout', function () {
412
-				\OC_Hook::emit('OC_User', 'logout', array());
413
-			});
414
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
415
-				/** @var $user \OC\User\User */
416
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
417
-				$dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
418
-			});
419
-			return $userSession;
420
-		});
421
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
422
-
423
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
424
-
425
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
426
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
427
-
428
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
429
-			return new \OC\AllConfig(
430
-				$c->getSystemConfig()
431
-			);
432
-		});
433
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
434
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
435
-
436
-		$this->registerService('SystemConfig', function ($c) use ($config) {
437
-			return new \OC\SystemConfig($config);
438
-		});
439
-
440
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
441
-			return new \OC\AppConfig($c->getDatabaseConnection());
442
-		});
443
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
444
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
445
-
446
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
447
-			return new \OC\L10N\Factory(
448
-				$c->getConfig(),
449
-				$c->getRequest(),
450
-				$c->getUserSession(),
451
-				\OC::$SERVERROOT
452
-			);
453
-		});
454
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
455
-
456
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
457
-			$config = $c->getConfig();
458
-			$cacheFactory = $c->getMemCacheFactory();
459
-			$request = $c->getRequest();
460
-			return new \OC\URLGenerator(
461
-				$config,
462
-				$cacheFactory,
463
-				$request
464
-			);
465
-		});
466
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
467
-
468
-		$this->registerAlias('AppFetcher', AppFetcher::class);
469
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
470
-
471
-		$this->registerService(\OCP\ICache::class, function ($c) {
472
-			return new Cache\File();
473
-		});
474
-		$this->registerAlias('UserCache', \OCP\ICache::class);
475
-
476
-		$this->registerService(Factory::class, function (Server $c) {
477
-
478
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
479
-				ArrayCache::class,
480
-				ArrayCache::class,
481
-				ArrayCache::class
482
-			);
483
-			$config = $c->getConfig();
484
-			$request = $c->getRequest();
485
-			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
486
-
487
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
488
-				$v = \OC_App::getAppVersions();
489
-				$v['core'] = implode(',', \OC_Util::getVersion());
490
-				$version = implode(',', $v);
491
-				$instanceId = \OC_Util::getInstanceId();
492
-				$path = \OC::$SERVERROOT;
493
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
494
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
495
-					$config->getSystemValue('memcache.local', null),
496
-					$config->getSystemValue('memcache.distributed', null),
497
-					$config->getSystemValue('memcache.locking', null)
498
-				);
499
-			}
500
-			return $arrayCacheFactory;
501
-
502
-		});
503
-		$this->registerAlias('MemCacheFactory', Factory::class);
504
-		$this->registerAlias(ICacheFactory::class, Factory::class);
505
-
506
-		$this->registerService('RedisFactory', function (Server $c) {
507
-			$systemConfig = $c->getSystemConfig();
508
-			return new RedisFactory($systemConfig);
509
-		});
510
-
511
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
512
-			return new \OC\Activity\Manager(
513
-				$c->getRequest(),
514
-				$c->getUserSession(),
515
-				$c->getConfig(),
516
-				$c->query(IValidator::class)
517
-			);
518
-		});
519
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
520
-
521
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
522
-			return new \OC\Activity\EventMerger(
523
-				$c->getL10N('lib')
524
-			);
525
-		});
526
-		$this->registerAlias(IValidator::class, Validator::class);
527
-
528
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
529
-			return new AvatarManager(
530
-				$c->query(\OC\User\Manager::class),
531
-				$c->getAppDataDir('avatar'),
532
-				$c->getL10N('lib'),
533
-				$c->getLogger(),
534
-				$c->getConfig()
535
-			);
536
-		});
537
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
538
-
539
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
540
-
541
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
542
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
543
-			$factory = new LogFactory($c, $this->getSystemConfig());
544
-			$logger = $factory->get($logType);
545
-			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
546
-
547
-			return new Log($logger, $this->getSystemConfig(), null, $registry);
548
-		});
549
-		$this->registerAlias('Logger', \OCP\ILogger::class);
550
-
551
-		$this->registerService(ILogFactory::class, function (Server $c) {
552
-			return new LogFactory($c, $this->getSystemConfig());
553
-		});
554
-
555
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
556
-			$config = $c->getConfig();
557
-			return new \OC\BackgroundJob\JobList(
558
-				$c->getDatabaseConnection(),
559
-				$config,
560
-				new TimeFactory()
561
-			);
562
-		});
563
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
564
-
565
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
566
-			$cacheFactory = $c->getMemCacheFactory();
567
-			$logger = $c->getLogger();
568
-			if ($cacheFactory->isLocalCacheAvailable()) {
569
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
570
-			} else {
571
-				$router = new \OC\Route\Router($logger);
572
-			}
573
-			return $router;
574
-		});
575
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
576
-
577
-		$this->registerService(\OCP\ISearch::class, function ($c) {
578
-			return new Search();
579
-		});
580
-		$this->registerAlias('Search', \OCP\ISearch::class);
581
-
582
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
583
-			return new \OC\Security\RateLimiting\Limiter(
584
-				$this->getUserSession(),
585
-				$this->getRequest(),
586
-				new \OC\AppFramework\Utility\TimeFactory(),
587
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
588
-			);
589
-		});
590
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
591
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
592
-				$this->getMemCacheFactory(),
593
-				new \OC\AppFramework\Utility\TimeFactory()
594
-			);
595
-		});
596
-
597
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
598
-			return new SecureRandom();
599
-		});
600
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
601
-
602
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
603
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
604
-		});
605
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
606
-
607
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
608
-			return new Hasher($c->getConfig());
609
-		});
610
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
611
-
612
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
613
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
614
-		});
615
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
616
-
617
-		$this->registerService(IDBConnection::class, function (Server $c) {
618
-			$systemConfig = $c->getSystemConfig();
619
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
620
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
621
-			if (!$factory->isValidType($type)) {
622
-				throw new \OC\DatabaseException('Invalid database type');
623
-			}
624
-			$connectionParams = $factory->createConnectionParams();
625
-			$connection = $factory->getConnection($type, $connectionParams);
626
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
627
-			return $connection;
628
-		});
629
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
630
-
631
-
632
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
633
-			$user = \OC_User::getUser();
634
-			$uid = $user ? $user : null;
635
-			return new ClientService(
636
-				$c->getConfig(),
637
-				new \OC\Security\CertificateManager(
638
-					$uid,
639
-					new View(),
640
-					$c->getConfig(),
641
-					$c->getLogger(),
642
-					$c->getSecureRandom()
643
-				)
644
-			);
645
-		});
646
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
647
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
648
-			$eventLogger = new EventLogger();
649
-			if ($c->getSystemConfig()->getValue('debug', false)) {
650
-				// In debug mode, module is being activated by default
651
-				$eventLogger->activate();
652
-			}
653
-			return $eventLogger;
654
-		});
655
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
656
-
657
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
658
-			$queryLogger = new QueryLogger();
659
-			if ($c->getSystemConfig()->getValue('debug', false)) {
660
-				// In debug mode, module is being activated by default
661
-				$queryLogger->activate();
662
-			}
663
-			return $queryLogger;
664
-		});
665
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
666
-
667
-		$this->registerService(TempManager::class, function (Server $c) {
668
-			return new TempManager(
669
-				$c->getLogger(),
670
-				$c->getConfig()
671
-			);
672
-		});
673
-		$this->registerAlias('TempManager', TempManager::class);
674
-		$this->registerAlias(ITempManager::class, TempManager::class);
675
-
676
-		$this->registerService(AppManager::class, function (Server $c) {
677
-			return new \OC\App\AppManager(
678
-				$c->getUserSession(),
679
-				$c->query(\OC\AppConfig::class),
680
-				$c->getGroupManager(),
681
-				$c->getMemCacheFactory(),
682
-				$c->getEventDispatcher()
683
-			);
684
-		});
685
-		$this->registerAlias('AppManager', AppManager::class);
686
-		$this->registerAlias(IAppManager::class, AppManager::class);
687
-
688
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
689
-			return new DateTimeZone(
690
-				$c->getConfig(),
691
-				$c->getSession()
692
-			);
693
-		});
694
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
695
-
696
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
697
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
698
-
699
-			return new DateTimeFormatter(
700
-				$c->getDateTimeZone()->getTimeZone(),
701
-				$c->getL10N('lib', $language)
702
-			);
703
-		});
704
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
705
-
706
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
707
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
708
-			$listener = new UserMountCacheListener($mountCache);
709
-			$listener->listen($c->getUserManager());
710
-			return $mountCache;
711
-		});
712
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
713
-
714
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
715
-			$loader = \OC\Files\Filesystem::getLoader();
716
-			$mountCache = $c->query('UserMountCache');
717
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
718
-
719
-			// builtin providers
720
-
721
-			$config = $c->getConfig();
722
-			$manager->registerProvider(new CacheMountProvider($config));
723
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
724
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
725
-
726
-			return $manager;
727
-		});
728
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
729
-
730
-		$this->registerService('IniWrapper', function ($c) {
731
-			return new IniGetWrapper();
732
-		});
733
-		$this->registerService('AsyncCommandBus', function (Server $c) {
734
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
735
-			if ($busClass) {
736
-				list($app, $class) = explode('::', $busClass, 2);
737
-				if ($c->getAppManager()->isInstalled($app)) {
738
-					\OC_App::loadApp($app);
739
-					return $c->query($class);
740
-				} else {
741
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
742
-				}
743
-			} else {
744
-				$jobList = $c->getJobList();
745
-				return new CronBus($jobList);
746
-			}
747
-		});
748
-		$this->registerService('TrustedDomainHelper', function ($c) {
749
-			return new TrustedDomainHelper($this->getConfig());
750
-		});
751
-		$this->registerService('Throttler', function (Server $c) {
752
-			return new Throttler(
753
-				$c->getDatabaseConnection(),
754
-				new TimeFactory(),
755
-				$c->getLogger(),
756
-				$c->getConfig()
757
-			);
758
-		});
759
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
760
-			// IConfig and IAppManager requires a working database. This code
761
-			// might however be called when ownCloud is not yet setup.
762
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
763
-				$config = $c->getConfig();
764
-				$appManager = $c->getAppManager();
765
-			} else {
766
-				$config = null;
767
-				$appManager = null;
768
-			}
769
-
770
-			return new Checker(
771
-				new EnvironmentHelper(),
772
-				new FileAccessHelper(),
773
-				new AppLocator(),
774
-				$config,
775
-				$c->getMemCacheFactory(),
776
-				$appManager,
777
-				$c->getTempManager()
778
-			);
779
-		});
780
-		$this->registerService(\OCP\IRequest::class, function ($c) {
781
-			if (isset($this['urlParams'])) {
782
-				$urlParams = $this['urlParams'];
783
-			} else {
784
-				$urlParams = [];
785
-			}
786
-
787
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
788
-				&& in_array('fakeinput', stream_get_wrappers())
789
-			) {
790
-				$stream = 'fakeinput://data';
791
-			} else {
792
-				$stream = 'php://input';
793
-			}
794
-
795
-			return new Request(
796
-				[
797
-					'get' => $_GET,
798
-					'post' => $_POST,
799
-					'files' => $_FILES,
800
-					'server' => $_SERVER,
801
-					'env' => $_ENV,
802
-					'cookies' => $_COOKIE,
803
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
804
-						? $_SERVER['REQUEST_METHOD']
805
-						: '',
806
-					'urlParams' => $urlParams,
807
-				],
808
-				$this->getSecureRandom(),
809
-				$this->getConfig(),
810
-				$this->getCsrfTokenManager(),
811
-				$stream
812
-			);
813
-		});
814
-		$this->registerAlias('Request', \OCP\IRequest::class);
815
-
816
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
817
-			return new Mailer(
818
-				$c->getConfig(),
819
-				$c->getLogger(),
820
-				$c->query(Defaults::class),
821
-				$c->getURLGenerator(),
822
-				$c->getL10N('lib')
823
-			);
824
-		});
825
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
826
-
827
-		$this->registerService('LDAPProvider', function (Server $c) {
828
-			$config = $c->getConfig();
829
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
830
-			if (is_null($factoryClass)) {
831
-				throw new \Exception('ldapProviderFactory not set');
832
-			}
833
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
834
-			$factory = new $factoryClass($this);
835
-			return $factory->getLDAPProvider();
836
-		});
837
-		$this->registerService(ILockingProvider::class, function (Server $c) {
838
-			$ini = $c->getIniWrapper();
839
-			$config = $c->getConfig();
840
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
841
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
842
-				/** @var \OC\Memcache\Factory $memcacheFactory */
843
-				$memcacheFactory = $c->getMemCacheFactory();
844
-				$memcache = $memcacheFactory->createLocking('lock');
845
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
846
-					return new MemcacheLockingProvider($memcache, $ttl);
847
-				}
848
-				return new DBLockingProvider(
849
-					$c->getDatabaseConnection(),
850
-					$c->getLogger(),
851
-					new TimeFactory(),
852
-					$ttl,
853
-					!\OC::$CLI
854
-				);
855
-			}
856
-			return new NoopLockingProvider();
857
-		});
858
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
859
-
860
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
861
-			return new \OC\Files\Mount\Manager();
862
-		});
863
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
864
-
865
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
866
-			return new \OC\Files\Type\Detection(
867
-				$c->getURLGenerator(),
868
-				\OC::$configDir,
869
-				\OC::$SERVERROOT . '/resources/config/'
870
-			);
871
-		});
872
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
873
-
874
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
875
-			return new \OC\Files\Type\Loader(
876
-				$c->getDatabaseConnection()
877
-			);
878
-		});
879
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
880
-		$this->registerService(BundleFetcher::class, function () {
881
-			return new BundleFetcher($this->getL10N('lib'));
882
-		});
883
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
884
-			return new Manager(
885
-				$c->query(IValidator::class)
886
-			);
887
-		});
888
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
889
-
890
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
891
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
892
-			$manager->registerCapability(function () use ($c) {
893
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
894
-			});
895
-			$manager->registerCapability(function () use ($c) {
896
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
897
-			});
898
-			return $manager;
899
-		});
900
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
901
-
902
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
903
-			$config = $c->getConfig();
904
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
905
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
906
-			$factory = new $factoryClass($this);
907
-			$manager = $factory->getManager();
908
-
909
-			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
910
-				$manager = $c->getUserManager();
911
-				$user = $manager->get($id);
912
-				if(is_null($user)) {
913
-					$l = $c->getL10N('core');
914
-					$displayName = $l->t('Unknown user');
915
-				} else {
916
-					$displayName = $user->getDisplayName();
917
-				}
918
-				return $displayName;
919
-			});
920
-
921
-			return $manager;
922
-		});
923
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
924
-
925
-		$this->registerService('ThemingDefaults', function (Server $c) {
926
-			/*
156
+    /** @var string */
157
+    private $webRoot;
158
+
159
+    /**
160
+     * @param string $webRoot
161
+     * @param \OC\Config $config
162
+     */
163
+    public function __construct($webRoot, \OC\Config $config) {
164
+        parent::__construct();
165
+        $this->webRoot = $webRoot;
166
+
167
+        // To find out if we are running from CLI or not
168
+        $this->registerParameter('isCLI', \OC::$CLI);
169
+
170
+        $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
171
+            return $c;
172
+        });
173
+
174
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
175
+        $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
176
+
177
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
178
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
179
+
180
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
181
+
182
+
183
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
184
+            return new PreviewManager(
185
+                $c->getConfig(),
186
+                $c->getRootFolder(),
187
+                $c->getAppDataDir('preview'),
188
+                $c->getEventDispatcher(),
189
+                $c->getSession()->get('user_id')
190
+            );
191
+        });
192
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
193
+
194
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
195
+            return new \OC\Preview\Watcher(
196
+                $c->getAppDataDir('preview')
197
+            );
198
+        });
199
+
200
+        $this->registerService('EncryptionManager', function (Server $c) {
201
+            $view = new View();
202
+            $util = new Encryption\Util(
203
+                $view,
204
+                $c->getUserManager(),
205
+                $c->getGroupManager(),
206
+                $c->getConfig()
207
+            );
208
+            return new Encryption\Manager(
209
+                $c->getConfig(),
210
+                $c->getLogger(),
211
+                $c->getL10N('core'),
212
+                new View(),
213
+                $util,
214
+                new ArrayCache()
215
+            );
216
+        });
217
+
218
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
219
+            $util = new Encryption\Util(
220
+                new View(),
221
+                $c->getUserManager(),
222
+                $c->getGroupManager(),
223
+                $c->getConfig()
224
+            );
225
+            return new Encryption\File(
226
+                $util,
227
+                $c->getRootFolder(),
228
+                $c->getShareManager()
229
+            );
230
+        });
231
+
232
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
233
+            $view = new View();
234
+            $util = new Encryption\Util(
235
+                $view,
236
+                $c->getUserManager(),
237
+                $c->getGroupManager(),
238
+                $c->getConfig()
239
+            );
240
+
241
+            return new Encryption\Keys\Storage($view, $util);
242
+        });
243
+        $this->registerService('TagMapper', function (Server $c) {
244
+            return new TagMapper($c->getDatabaseConnection());
245
+        });
246
+
247
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
248
+            $tagMapper = $c->query('TagMapper');
249
+            return new TagManager($tagMapper, $c->getUserSession());
250
+        });
251
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
252
+
253
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
254
+            $config = $c->getConfig();
255
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
256
+            return new $factoryClass($this);
257
+        });
258
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
259
+            return $c->query('SystemTagManagerFactory')->getManager();
260
+        });
261
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
262
+
263
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
264
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
265
+        });
266
+        $this->registerService('RootFolder', function (Server $c) {
267
+            $manager = \OC\Files\Filesystem::getMountManager(null);
268
+            $view = new View();
269
+            $root = new Root(
270
+                $manager,
271
+                $view,
272
+                null,
273
+                $c->getUserMountCache(),
274
+                $this->getLogger(),
275
+                $this->getUserManager()
276
+            );
277
+            $connector = new HookConnector($root, $view);
278
+            $connector->viewToNode();
279
+
280
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
281
+            $previewConnector->connectWatcher();
282
+
283
+            return $root;
284
+        });
285
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
286
+
287
+        $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
288
+            return new LazyRoot(function () use ($c) {
289
+                return $c->query('RootFolder');
290
+            });
291
+        });
292
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
293
+
294
+        $this->registerService(\OC\User\Manager::class, function (Server $c) {
295
+            $config = $c->getConfig();
296
+            return new \OC\User\Manager($config);
297
+        });
298
+        $this->registerAlias('UserManager', \OC\User\Manager::class);
299
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
300
+
301
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
302
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
303
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
304
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
305
+            });
306
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
307
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
308
+            });
309
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
310
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
311
+            });
312
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
313
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
314
+            });
315
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
316
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
317
+            });
318
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
319
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
320
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
321
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
322
+            });
323
+            return $groupManager;
324
+        });
325
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
326
+
327
+        $this->registerService(Store::class, function (Server $c) {
328
+            $session = $c->getSession();
329
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
330
+                $tokenProvider = $c->query(IProvider::class);
331
+            } else {
332
+                $tokenProvider = null;
333
+            }
334
+            $logger = $c->getLogger();
335
+            return new Store($session, $logger, $tokenProvider);
336
+        });
337
+        $this->registerAlias(IStore::class, Store::class);
338
+        $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
339
+            $dbConnection = $c->getDatabaseConnection();
340
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
341
+        });
342
+        $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) {
343
+            $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class);
344
+            $crypto = $c->getCrypto();
345
+            $config = $c->getConfig();
346
+            $logger = $c->getLogger();
347
+            $timeFactory = new TimeFactory();
348
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
349
+        });
350
+        $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class);
351
+
352
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
353
+            $manager = $c->getUserManager();
354
+            $session = new \OC\Session\Memory('');
355
+            $timeFactory = new TimeFactory();
356
+            // Token providers might require a working database. This code
357
+            // might however be called when ownCloud is not yet setup.
358
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
359
+                $defaultTokenProvider = $c->query(IProvider::class);
360
+            } else {
361
+                $defaultTokenProvider = null;
362
+            }
363
+
364
+            $dispatcher = $c->getEventDispatcher();
365
+
366
+            $userSession = new \OC\User\Session(
367
+                $manager,
368
+                $session,
369
+                $timeFactory,
370
+                $defaultTokenProvider,
371
+                $c->getConfig(),
372
+                $c->getSecureRandom(),
373
+                $c->getLockdownManager(),
374
+                $c->getLogger()
375
+            );
376
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
377
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
378
+            });
379
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
380
+                /** @var $user \OC\User\User */
381
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
382
+            });
383
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
384
+                /** @var $user \OC\User\User */
385
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
386
+                $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
387
+            });
388
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
389
+                /** @var $user \OC\User\User */
390
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
391
+            });
392
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
393
+                /** @var $user \OC\User\User */
394
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
395
+            });
396
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
397
+                /** @var $user \OC\User\User */
398
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
399
+            });
400
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
401
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
402
+            });
403
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
404
+                /** @var $user \OC\User\User */
405
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
406
+            });
407
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
408
+                /** @var $user \OC\User\User */
409
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
410
+            });
411
+            $userSession->listen('\OC\User', 'logout', function () {
412
+                \OC_Hook::emit('OC_User', 'logout', array());
413
+            });
414
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
415
+                /** @var $user \OC\User\User */
416
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
417
+                $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
418
+            });
419
+            return $userSession;
420
+        });
421
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
422
+
423
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
424
+
425
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
426
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
427
+
428
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
429
+            return new \OC\AllConfig(
430
+                $c->getSystemConfig()
431
+            );
432
+        });
433
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
434
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
435
+
436
+        $this->registerService('SystemConfig', function ($c) use ($config) {
437
+            return new \OC\SystemConfig($config);
438
+        });
439
+
440
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
441
+            return new \OC\AppConfig($c->getDatabaseConnection());
442
+        });
443
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
444
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
445
+
446
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
447
+            return new \OC\L10N\Factory(
448
+                $c->getConfig(),
449
+                $c->getRequest(),
450
+                $c->getUserSession(),
451
+                \OC::$SERVERROOT
452
+            );
453
+        });
454
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
455
+
456
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
457
+            $config = $c->getConfig();
458
+            $cacheFactory = $c->getMemCacheFactory();
459
+            $request = $c->getRequest();
460
+            return new \OC\URLGenerator(
461
+                $config,
462
+                $cacheFactory,
463
+                $request
464
+            );
465
+        });
466
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
467
+
468
+        $this->registerAlias('AppFetcher', AppFetcher::class);
469
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
470
+
471
+        $this->registerService(\OCP\ICache::class, function ($c) {
472
+            return new Cache\File();
473
+        });
474
+        $this->registerAlias('UserCache', \OCP\ICache::class);
475
+
476
+        $this->registerService(Factory::class, function (Server $c) {
477
+
478
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
479
+                ArrayCache::class,
480
+                ArrayCache::class,
481
+                ArrayCache::class
482
+            );
483
+            $config = $c->getConfig();
484
+            $request = $c->getRequest();
485
+            $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
486
+
487
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
488
+                $v = \OC_App::getAppVersions();
489
+                $v['core'] = implode(',', \OC_Util::getVersion());
490
+                $version = implode(',', $v);
491
+                $instanceId = \OC_Util::getInstanceId();
492
+                $path = \OC::$SERVERROOT;
493
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
494
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
495
+                    $config->getSystemValue('memcache.local', null),
496
+                    $config->getSystemValue('memcache.distributed', null),
497
+                    $config->getSystemValue('memcache.locking', null)
498
+                );
499
+            }
500
+            return $arrayCacheFactory;
501
+
502
+        });
503
+        $this->registerAlias('MemCacheFactory', Factory::class);
504
+        $this->registerAlias(ICacheFactory::class, Factory::class);
505
+
506
+        $this->registerService('RedisFactory', function (Server $c) {
507
+            $systemConfig = $c->getSystemConfig();
508
+            return new RedisFactory($systemConfig);
509
+        });
510
+
511
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
512
+            return new \OC\Activity\Manager(
513
+                $c->getRequest(),
514
+                $c->getUserSession(),
515
+                $c->getConfig(),
516
+                $c->query(IValidator::class)
517
+            );
518
+        });
519
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
520
+
521
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
522
+            return new \OC\Activity\EventMerger(
523
+                $c->getL10N('lib')
524
+            );
525
+        });
526
+        $this->registerAlias(IValidator::class, Validator::class);
527
+
528
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
529
+            return new AvatarManager(
530
+                $c->query(\OC\User\Manager::class),
531
+                $c->getAppDataDir('avatar'),
532
+                $c->getL10N('lib'),
533
+                $c->getLogger(),
534
+                $c->getConfig()
535
+            );
536
+        });
537
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
538
+
539
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
540
+
541
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
542
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
543
+            $factory = new LogFactory($c, $this->getSystemConfig());
544
+            $logger = $factory->get($logType);
545
+            $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
546
+
547
+            return new Log($logger, $this->getSystemConfig(), null, $registry);
548
+        });
549
+        $this->registerAlias('Logger', \OCP\ILogger::class);
550
+
551
+        $this->registerService(ILogFactory::class, function (Server $c) {
552
+            return new LogFactory($c, $this->getSystemConfig());
553
+        });
554
+
555
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
556
+            $config = $c->getConfig();
557
+            return new \OC\BackgroundJob\JobList(
558
+                $c->getDatabaseConnection(),
559
+                $config,
560
+                new TimeFactory()
561
+            );
562
+        });
563
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
564
+
565
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
566
+            $cacheFactory = $c->getMemCacheFactory();
567
+            $logger = $c->getLogger();
568
+            if ($cacheFactory->isLocalCacheAvailable()) {
569
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
570
+            } else {
571
+                $router = new \OC\Route\Router($logger);
572
+            }
573
+            return $router;
574
+        });
575
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
576
+
577
+        $this->registerService(\OCP\ISearch::class, function ($c) {
578
+            return new Search();
579
+        });
580
+        $this->registerAlias('Search', \OCP\ISearch::class);
581
+
582
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
583
+            return new \OC\Security\RateLimiting\Limiter(
584
+                $this->getUserSession(),
585
+                $this->getRequest(),
586
+                new \OC\AppFramework\Utility\TimeFactory(),
587
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
588
+            );
589
+        });
590
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
591
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
592
+                $this->getMemCacheFactory(),
593
+                new \OC\AppFramework\Utility\TimeFactory()
594
+            );
595
+        });
596
+
597
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
598
+            return new SecureRandom();
599
+        });
600
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
601
+
602
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
603
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
604
+        });
605
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
606
+
607
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
608
+            return new Hasher($c->getConfig());
609
+        });
610
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
611
+
612
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
613
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
614
+        });
615
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
616
+
617
+        $this->registerService(IDBConnection::class, function (Server $c) {
618
+            $systemConfig = $c->getSystemConfig();
619
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
620
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
621
+            if (!$factory->isValidType($type)) {
622
+                throw new \OC\DatabaseException('Invalid database type');
623
+            }
624
+            $connectionParams = $factory->createConnectionParams();
625
+            $connection = $factory->getConnection($type, $connectionParams);
626
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
627
+            return $connection;
628
+        });
629
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
630
+
631
+
632
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
633
+            $user = \OC_User::getUser();
634
+            $uid = $user ? $user : null;
635
+            return new ClientService(
636
+                $c->getConfig(),
637
+                new \OC\Security\CertificateManager(
638
+                    $uid,
639
+                    new View(),
640
+                    $c->getConfig(),
641
+                    $c->getLogger(),
642
+                    $c->getSecureRandom()
643
+                )
644
+            );
645
+        });
646
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
647
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
648
+            $eventLogger = new EventLogger();
649
+            if ($c->getSystemConfig()->getValue('debug', false)) {
650
+                // In debug mode, module is being activated by default
651
+                $eventLogger->activate();
652
+            }
653
+            return $eventLogger;
654
+        });
655
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
656
+
657
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
658
+            $queryLogger = new QueryLogger();
659
+            if ($c->getSystemConfig()->getValue('debug', false)) {
660
+                // In debug mode, module is being activated by default
661
+                $queryLogger->activate();
662
+            }
663
+            return $queryLogger;
664
+        });
665
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
666
+
667
+        $this->registerService(TempManager::class, function (Server $c) {
668
+            return new TempManager(
669
+                $c->getLogger(),
670
+                $c->getConfig()
671
+            );
672
+        });
673
+        $this->registerAlias('TempManager', TempManager::class);
674
+        $this->registerAlias(ITempManager::class, TempManager::class);
675
+
676
+        $this->registerService(AppManager::class, function (Server $c) {
677
+            return new \OC\App\AppManager(
678
+                $c->getUserSession(),
679
+                $c->query(\OC\AppConfig::class),
680
+                $c->getGroupManager(),
681
+                $c->getMemCacheFactory(),
682
+                $c->getEventDispatcher()
683
+            );
684
+        });
685
+        $this->registerAlias('AppManager', AppManager::class);
686
+        $this->registerAlias(IAppManager::class, AppManager::class);
687
+
688
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
689
+            return new DateTimeZone(
690
+                $c->getConfig(),
691
+                $c->getSession()
692
+            );
693
+        });
694
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
695
+
696
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
697
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
698
+
699
+            return new DateTimeFormatter(
700
+                $c->getDateTimeZone()->getTimeZone(),
701
+                $c->getL10N('lib', $language)
702
+            );
703
+        });
704
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
705
+
706
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
707
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
708
+            $listener = new UserMountCacheListener($mountCache);
709
+            $listener->listen($c->getUserManager());
710
+            return $mountCache;
711
+        });
712
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
713
+
714
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
715
+            $loader = \OC\Files\Filesystem::getLoader();
716
+            $mountCache = $c->query('UserMountCache');
717
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
718
+
719
+            // builtin providers
720
+
721
+            $config = $c->getConfig();
722
+            $manager->registerProvider(new CacheMountProvider($config));
723
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
724
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
725
+
726
+            return $manager;
727
+        });
728
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
729
+
730
+        $this->registerService('IniWrapper', function ($c) {
731
+            return new IniGetWrapper();
732
+        });
733
+        $this->registerService('AsyncCommandBus', function (Server $c) {
734
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
735
+            if ($busClass) {
736
+                list($app, $class) = explode('::', $busClass, 2);
737
+                if ($c->getAppManager()->isInstalled($app)) {
738
+                    \OC_App::loadApp($app);
739
+                    return $c->query($class);
740
+                } else {
741
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
742
+                }
743
+            } else {
744
+                $jobList = $c->getJobList();
745
+                return new CronBus($jobList);
746
+            }
747
+        });
748
+        $this->registerService('TrustedDomainHelper', function ($c) {
749
+            return new TrustedDomainHelper($this->getConfig());
750
+        });
751
+        $this->registerService('Throttler', function (Server $c) {
752
+            return new Throttler(
753
+                $c->getDatabaseConnection(),
754
+                new TimeFactory(),
755
+                $c->getLogger(),
756
+                $c->getConfig()
757
+            );
758
+        });
759
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
760
+            // IConfig and IAppManager requires a working database. This code
761
+            // might however be called when ownCloud is not yet setup.
762
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
763
+                $config = $c->getConfig();
764
+                $appManager = $c->getAppManager();
765
+            } else {
766
+                $config = null;
767
+                $appManager = null;
768
+            }
769
+
770
+            return new Checker(
771
+                new EnvironmentHelper(),
772
+                new FileAccessHelper(),
773
+                new AppLocator(),
774
+                $config,
775
+                $c->getMemCacheFactory(),
776
+                $appManager,
777
+                $c->getTempManager()
778
+            );
779
+        });
780
+        $this->registerService(\OCP\IRequest::class, function ($c) {
781
+            if (isset($this['urlParams'])) {
782
+                $urlParams = $this['urlParams'];
783
+            } else {
784
+                $urlParams = [];
785
+            }
786
+
787
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
788
+                && in_array('fakeinput', stream_get_wrappers())
789
+            ) {
790
+                $stream = 'fakeinput://data';
791
+            } else {
792
+                $stream = 'php://input';
793
+            }
794
+
795
+            return new Request(
796
+                [
797
+                    'get' => $_GET,
798
+                    'post' => $_POST,
799
+                    'files' => $_FILES,
800
+                    'server' => $_SERVER,
801
+                    'env' => $_ENV,
802
+                    'cookies' => $_COOKIE,
803
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
804
+                        ? $_SERVER['REQUEST_METHOD']
805
+                        : '',
806
+                    'urlParams' => $urlParams,
807
+                ],
808
+                $this->getSecureRandom(),
809
+                $this->getConfig(),
810
+                $this->getCsrfTokenManager(),
811
+                $stream
812
+            );
813
+        });
814
+        $this->registerAlias('Request', \OCP\IRequest::class);
815
+
816
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
817
+            return new Mailer(
818
+                $c->getConfig(),
819
+                $c->getLogger(),
820
+                $c->query(Defaults::class),
821
+                $c->getURLGenerator(),
822
+                $c->getL10N('lib')
823
+            );
824
+        });
825
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
826
+
827
+        $this->registerService('LDAPProvider', function (Server $c) {
828
+            $config = $c->getConfig();
829
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
830
+            if (is_null($factoryClass)) {
831
+                throw new \Exception('ldapProviderFactory not set');
832
+            }
833
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
834
+            $factory = new $factoryClass($this);
835
+            return $factory->getLDAPProvider();
836
+        });
837
+        $this->registerService(ILockingProvider::class, function (Server $c) {
838
+            $ini = $c->getIniWrapper();
839
+            $config = $c->getConfig();
840
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
841
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
842
+                /** @var \OC\Memcache\Factory $memcacheFactory */
843
+                $memcacheFactory = $c->getMemCacheFactory();
844
+                $memcache = $memcacheFactory->createLocking('lock');
845
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
846
+                    return new MemcacheLockingProvider($memcache, $ttl);
847
+                }
848
+                return new DBLockingProvider(
849
+                    $c->getDatabaseConnection(),
850
+                    $c->getLogger(),
851
+                    new TimeFactory(),
852
+                    $ttl,
853
+                    !\OC::$CLI
854
+                );
855
+            }
856
+            return new NoopLockingProvider();
857
+        });
858
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
859
+
860
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
861
+            return new \OC\Files\Mount\Manager();
862
+        });
863
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
864
+
865
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
866
+            return new \OC\Files\Type\Detection(
867
+                $c->getURLGenerator(),
868
+                \OC::$configDir,
869
+                \OC::$SERVERROOT . '/resources/config/'
870
+            );
871
+        });
872
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
873
+
874
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
875
+            return new \OC\Files\Type\Loader(
876
+                $c->getDatabaseConnection()
877
+            );
878
+        });
879
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
880
+        $this->registerService(BundleFetcher::class, function () {
881
+            return new BundleFetcher($this->getL10N('lib'));
882
+        });
883
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
884
+            return new Manager(
885
+                $c->query(IValidator::class)
886
+            );
887
+        });
888
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
889
+
890
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
891
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
892
+            $manager->registerCapability(function () use ($c) {
893
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
894
+            });
895
+            $manager->registerCapability(function () use ($c) {
896
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
897
+            });
898
+            return $manager;
899
+        });
900
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
901
+
902
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
903
+            $config = $c->getConfig();
904
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
905
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
906
+            $factory = new $factoryClass($this);
907
+            $manager = $factory->getManager();
908
+
909
+            $manager->registerDisplayNameResolver('user', function($id) use ($c) {
910
+                $manager = $c->getUserManager();
911
+                $user = $manager->get($id);
912
+                if(is_null($user)) {
913
+                    $l = $c->getL10N('core');
914
+                    $displayName = $l->t('Unknown user');
915
+                } else {
916
+                    $displayName = $user->getDisplayName();
917
+                }
918
+                return $displayName;
919
+            });
920
+
921
+            return $manager;
922
+        });
923
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
924
+
925
+        $this->registerService('ThemingDefaults', function (Server $c) {
926
+            /*
927 927
 			 * Dark magic for autoloader.
928 928
 			 * If we do a class_exists it will try to load the class which will
929 929
 			 * make composer cache the result. Resulting in errors when enabling
930 930
 			 * the theming app.
931 931
 			 */
932
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
933
-			if (isset($prefixes['OCA\\Theming\\'])) {
934
-				$classExists = true;
935
-			} else {
936
-				$classExists = false;
937
-			}
938
-
939
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
940
-				return new ThemingDefaults(
941
-					$c->getConfig(),
942
-					$c->getL10N('theming'),
943
-					$c->getURLGenerator(),
944
-					$c->getMemCacheFactory(),
945
-					new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
946
-					new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
947
-					$c->getAppManager()
948
-				);
949
-			}
950
-			return new \OC_Defaults();
951
-		});
952
-		$this->registerService(SCSSCacher::class, function (Server $c) {
953
-			/** @var Factory $cacheFactory */
954
-			$cacheFactory = $c->query(Factory::class);
955
-			return new SCSSCacher(
956
-				$c->getLogger(),
957
-				$c->query(\OC\Files\AppData\Factory::class),
958
-				$c->getURLGenerator(),
959
-				$c->getConfig(),
960
-				$c->getThemingDefaults(),
961
-				\OC::$SERVERROOT,
962
-				$this->getMemCacheFactory()
963
-			);
964
-		});
965
-		$this->registerService(JSCombiner::class, function (Server $c) {
966
-			/** @var Factory $cacheFactory */
967
-			$cacheFactory = $c->query(Factory::class);
968
-			return new JSCombiner(
969
-				$c->getAppDataDir('js'),
970
-				$c->getURLGenerator(),
971
-				$this->getMemCacheFactory(),
972
-				$c->getSystemConfig(),
973
-				$c->getLogger()
974
-			);
975
-		});
976
-		$this->registerService(EventDispatcher::class, function () {
977
-			return new EventDispatcher();
978
-		});
979
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
980
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
981
-
982
-		$this->registerService('CryptoWrapper', function (Server $c) {
983
-			// FIXME: Instantiiated here due to cyclic dependency
984
-			$request = new Request(
985
-				[
986
-					'get' => $_GET,
987
-					'post' => $_POST,
988
-					'files' => $_FILES,
989
-					'server' => $_SERVER,
990
-					'env' => $_ENV,
991
-					'cookies' => $_COOKIE,
992
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
993
-						? $_SERVER['REQUEST_METHOD']
994
-						: null,
995
-				],
996
-				$c->getSecureRandom(),
997
-				$c->getConfig()
998
-			);
999
-
1000
-			return new CryptoWrapper(
1001
-				$c->getConfig(),
1002
-				$c->getCrypto(),
1003
-				$c->getSecureRandom(),
1004
-				$request
1005
-			);
1006
-		});
1007
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1008
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1009
-
1010
-			return new CsrfTokenManager(
1011
-				$tokenGenerator,
1012
-				$c->query(SessionStorage::class)
1013
-			);
1014
-		});
1015
-		$this->registerService(SessionStorage::class, function (Server $c) {
1016
-			return new SessionStorage($c->getSession());
1017
-		});
1018
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1019
-			return new ContentSecurityPolicyManager();
1020
-		});
1021
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1022
-
1023
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1024
-			return new ContentSecurityPolicyNonceManager(
1025
-				$c->getCsrfTokenManager(),
1026
-				$c->getRequest()
1027
-			);
1028
-		});
1029
-
1030
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1031
-			$config = $c->getConfig();
1032
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1033
-			/** @var \OCP\Share\IProviderFactory $factory */
1034
-			$factory = new $factoryClass($this);
1035
-
1036
-			$manager = new \OC\Share20\Manager(
1037
-				$c->getLogger(),
1038
-				$c->getConfig(),
1039
-				$c->getSecureRandom(),
1040
-				$c->getHasher(),
1041
-				$c->getMountManager(),
1042
-				$c->getGroupManager(),
1043
-				$c->getL10N('lib'),
1044
-				$c->getL10NFactory(),
1045
-				$factory,
1046
-				$c->getUserManager(),
1047
-				$c->getLazyRootFolder(),
1048
-				$c->getEventDispatcher(),
1049
-				$c->getMailer(),
1050
-				$c->getURLGenerator(),
1051
-				$c->getThemingDefaults()
1052
-			);
1053
-
1054
-			return $manager;
1055
-		});
1056
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1057
-
1058
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1059
-			$instance = new Collaboration\Collaborators\Search($c);
1060
-
1061
-			// register default plugins
1062
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1063
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1064
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1065
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1066
-
1067
-			return $instance;
1068
-		});
1069
-		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1070
-
1071
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1072
-
1073
-		$this->registerService('SettingsManager', function (Server $c) {
1074
-			$manager = new \OC\Settings\Manager(
1075
-				$c->getLogger(),
1076
-				$c->getDatabaseConnection(),
1077
-				$c->getL10N('lib'),
1078
-				$c->getConfig(),
1079
-				$c->getEncryptionManager(),
1080
-				$c->getUserManager(),
1081
-				$c->getLockingProvider(),
1082
-				$c->getRequest(),
1083
-				$c->getURLGenerator(),
1084
-				$c->query(AccountManager::class),
1085
-				$c->getGroupManager(),
1086
-				$c->getL10NFactory(),
1087
-				$c->getAppManager()
1088
-			);
1089
-			return $manager;
1090
-		});
1091
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1092
-			return new \OC\Files\AppData\Factory(
1093
-				$c->getRootFolder(),
1094
-				$c->getSystemConfig()
1095
-			);
1096
-		});
1097
-
1098
-		$this->registerService('LockdownManager', function (Server $c) {
1099
-			return new LockdownManager(function () use ($c) {
1100
-				return $c->getSession();
1101
-			});
1102
-		});
1103
-
1104
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1105
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1106
-		});
1107
-
1108
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1109
-			return new CloudIdManager();
1110
-		});
1111
-
1112
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1113
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1114
-
1115
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1116
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1117
-
1118
-		$this->registerService(Defaults::class, function (Server $c) {
1119
-			return new Defaults(
1120
-				$c->getThemingDefaults()
1121
-			);
1122
-		});
1123
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1124
-
1125
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1126
-			return $c->query(\OCP\IUserSession::class)->getSession();
1127
-		});
1128
-
1129
-		$this->registerService(IShareHelper::class, function (Server $c) {
1130
-			return new ShareHelper(
1131
-				$c->query(\OCP\Share\IManager::class)
1132
-			);
1133
-		});
1134
-
1135
-		$this->registerService(Installer::class, function(Server $c) {
1136
-			return new Installer(
1137
-				$c->getAppFetcher(),
1138
-				$c->getHTTPClientService(),
1139
-				$c->getTempManager(),
1140
-				$c->getLogger(),
1141
-				$c->getConfig()
1142
-			);
1143
-		});
1144
-
1145
-		$this->registerService(IApiFactory::class, function(Server $c) {
1146
-			return new ApiFactory($c->getHTTPClientService());
1147
-		});
1148
-
1149
-		$this->registerService(IInstanceFactory::class, function(Server $c) {
1150
-			$memcacheFactory = $c->getMemCacheFactory();
1151
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1152
-		});
1153
-
1154
-		$this->registerService(IContactsStore::class, function(Server $c) {
1155
-			return new ContactsStore(
1156
-				$c->getContactsManager(),
1157
-				$c->getConfig(),
1158
-				$c->getUserManager(),
1159
-				$c->getGroupManager()
1160
-			);
1161
-		});
1162
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1163
-
1164
-		$this->connectDispatcher();
1165
-	}
1166
-
1167
-	/**
1168
-	 * @return \OCP\Calendar\IManager
1169
-	 */
1170
-	public function getCalendarManager() {
1171
-		return $this->query('CalendarManager');
1172
-	}
1173
-
1174
-	private function connectDispatcher() {
1175
-		$dispatcher = $this->getEventDispatcher();
1176
-
1177
-		// Delete avatar on user deletion
1178
-		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1179
-			$logger = $this->getLogger();
1180
-			$manager = $this->getAvatarManager();
1181
-			/** @var IUser $user */
1182
-			$user = $e->getSubject();
1183
-
1184
-			try {
1185
-				$avatar = $manager->getAvatar($user->getUID());
1186
-				$avatar->remove();
1187
-			} catch (NotFoundException $e) {
1188
-				// no avatar to remove
1189
-			} catch (\Exception $e) {
1190
-				// Ignore exceptions
1191
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1192
-			}
1193
-		});
1194
-
1195
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1196
-			$manager = $this->getAvatarManager();
1197
-			/** @var IUser $user */
1198
-			$user = $e->getSubject();
1199
-			$feature = $e->getArgument('feature');
1200
-			$oldValue = $e->getArgument('oldValue');
1201
-			$value = $e->getArgument('value');
1202
-
1203
-			try {
1204
-				$avatar = $manager->getAvatar($user->getUID());
1205
-				$avatar->userChanged($feature, $oldValue, $value);
1206
-			} catch (NotFoundException $e) {
1207
-				// no avatar to remove
1208
-			}
1209
-		});
1210
-	}
1211
-
1212
-	/**
1213
-	 * @return \OCP\Contacts\IManager
1214
-	 */
1215
-	public function getContactsManager() {
1216
-		return $this->query('ContactsManager');
1217
-	}
1218
-
1219
-	/**
1220
-	 * @return \OC\Encryption\Manager
1221
-	 */
1222
-	public function getEncryptionManager() {
1223
-		return $this->query('EncryptionManager');
1224
-	}
1225
-
1226
-	/**
1227
-	 * @return \OC\Encryption\File
1228
-	 */
1229
-	public function getEncryptionFilesHelper() {
1230
-		return $this->query('EncryptionFileHelper');
1231
-	}
1232
-
1233
-	/**
1234
-	 * @return \OCP\Encryption\Keys\IStorage
1235
-	 */
1236
-	public function getEncryptionKeyStorage() {
1237
-		return $this->query('EncryptionKeyStorage');
1238
-	}
1239
-
1240
-	/**
1241
-	 * The current request object holding all information about the request
1242
-	 * currently being processed is returned from this method.
1243
-	 * In case the current execution was not initiated by a web request null is returned
1244
-	 *
1245
-	 * @return \OCP\IRequest
1246
-	 */
1247
-	public function getRequest() {
1248
-		return $this->query('Request');
1249
-	}
1250
-
1251
-	/**
1252
-	 * Returns the preview manager which can create preview images for a given file
1253
-	 *
1254
-	 * @return \OCP\IPreview
1255
-	 */
1256
-	public function getPreviewManager() {
1257
-		return $this->query('PreviewManager');
1258
-	}
1259
-
1260
-	/**
1261
-	 * Returns the tag manager which can get and set tags for different object types
1262
-	 *
1263
-	 * @see \OCP\ITagManager::load()
1264
-	 * @return \OCP\ITagManager
1265
-	 */
1266
-	public function getTagManager() {
1267
-		return $this->query('TagManager');
1268
-	}
1269
-
1270
-	/**
1271
-	 * Returns the system-tag manager
1272
-	 *
1273
-	 * @return \OCP\SystemTag\ISystemTagManager
1274
-	 *
1275
-	 * @since 9.0.0
1276
-	 */
1277
-	public function getSystemTagManager() {
1278
-		return $this->query('SystemTagManager');
1279
-	}
1280
-
1281
-	/**
1282
-	 * Returns the system-tag object mapper
1283
-	 *
1284
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1285
-	 *
1286
-	 * @since 9.0.0
1287
-	 */
1288
-	public function getSystemTagObjectMapper() {
1289
-		return $this->query('SystemTagObjectMapper');
1290
-	}
1291
-
1292
-	/**
1293
-	 * Returns the avatar manager, used for avatar functionality
1294
-	 *
1295
-	 * @return \OCP\IAvatarManager
1296
-	 */
1297
-	public function getAvatarManager() {
1298
-		return $this->query('AvatarManager');
1299
-	}
1300
-
1301
-	/**
1302
-	 * Returns the root folder of ownCloud's data directory
1303
-	 *
1304
-	 * @return \OCP\Files\IRootFolder
1305
-	 */
1306
-	public function getRootFolder() {
1307
-		return $this->query('LazyRootFolder');
1308
-	}
1309
-
1310
-	/**
1311
-	 * Returns the root folder of ownCloud's data directory
1312
-	 * This is the lazy variant so this gets only initialized once it
1313
-	 * is actually used.
1314
-	 *
1315
-	 * @return \OCP\Files\IRootFolder
1316
-	 */
1317
-	public function getLazyRootFolder() {
1318
-		return $this->query('LazyRootFolder');
1319
-	}
1320
-
1321
-	/**
1322
-	 * Returns a view to ownCloud's files folder
1323
-	 *
1324
-	 * @param string $userId user ID
1325
-	 * @return \OCP\Files\Folder|null
1326
-	 */
1327
-	public function getUserFolder($userId = null) {
1328
-		if ($userId === null) {
1329
-			$user = $this->getUserSession()->getUser();
1330
-			if (!$user) {
1331
-				return null;
1332
-			}
1333
-			$userId = $user->getUID();
1334
-		}
1335
-		$root = $this->getRootFolder();
1336
-		return $root->getUserFolder($userId);
1337
-	}
1338
-
1339
-	/**
1340
-	 * Returns an app-specific view in ownClouds data directory
1341
-	 *
1342
-	 * @return \OCP\Files\Folder
1343
-	 * @deprecated since 9.2.0 use IAppData
1344
-	 */
1345
-	public function getAppFolder() {
1346
-		$dir = '/' . \OC_App::getCurrentApp();
1347
-		$root = $this->getRootFolder();
1348
-		if (!$root->nodeExists($dir)) {
1349
-			$folder = $root->newFolder($dir);
1350
-		} else {
1351
-			$folder = $root->get($dir);
1352
-		}
1353
-		return $folder;
1354
-	}
1355
-
1356
-	/**
1357
-	 * @return \OC\User\Manager
1358
-	 */
1359
-	public function getUserManager() {
1360
-		return $this->query('UserManager');
1361
-	}
1362
-
1363
-	/**
1364
-	 * @return \OC\Group\Manager
1365
-	 */
1366
-	public function getGroupManager() {
1367
-		return $this->query('GroupManager');
1368
-	}
1369
-
1370
-	/**
1371
-	 * @return \OC\User\Session
1372
-	 */
1373
-	public function getUserSession() {
1374
-		return $this->query('UserSession');
1375
-	}
1376
-
1377
-	/**
1378
-	 * @return \OCP\ISession
1379
-	 */
1380
-	public function getSession() {
1381
-		return $this->query('UserSession')->getSession();
1382
-	}
1383
-
1384
-	/**
1385
-	 * @param \OCP\ISession $session
1386
-	 */
1387
-	public function setSession(\OCP\ISession $session) {
1388
-		$this->query(SessionStorage::class)->setSession($session);
1389
-		$this->query('UserSession')->setSession($session);
1390
-		$this->query(Store::class)->setSession($session);
1391
-	}
1392
-
1393
-	/**
1394
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1395
-	 */
1396
-	public function getTwoFactorAuthManager() {
1397
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1398
-	}
1399
-
1400
-	/**
1401
-	 * @return \OC\NavigationManager
1402
-	 */
1403
-	public function getNavigationManager() {
1404
-		return $this->query('NavigationManager');
1405
-	}
1406
-
1407
-	/**
1408
-	 * @return \OCP\IConfig
1409
-	 */
1410
-	public function getConfig() {
1411
-		return $this->query('AllConfig');
1412
-	}
1413
-
1414
-	/**
1415
-	 * @return \OC\SystemConfig
1416
-	 */
1417
-	public function getSystemConfig() {
1418
-		return $this->query('SystemConfig');
1419
-	}
1420
-
1421
-	/**
1422
-	 * Returns the app config manager
1423
-	 *
1424
-	 * @return \OCP\IAppConfig
1425
-	 */
1426
-	public function getAppConfig() {
1427
-		return $this->query('AppConfig');
1428
-	}
1429
-
1430
-	/**
1431
-	 * @return \OCP\L10N\IFactory
1432
-	 */
1433
-	public function getL10NFactory() {
1434
-		return $this->query('L10NFactory');
1435
-	}
1436
-
1437
-	/**
1438
-	 * get an L10N instance
1439
-	 *
1440
-	 * @param string $app appid
1441
-	 * @param string $lang
1442
-	 * @return IL10N
1443
-	 */
1444
-	public function getL10N($app, $lang = null) {
1445
-		return $this->getL10NFactory()->get($app, $lang);
1446
-	}
1447
-
1448
-	/**
1449
-	 * @return \OCP\IURLGenerator
1450
-	 */
1451
-	public function getURLGenerator() {
1452
-		return $this->query('URLGenerator');
1453
-	}
1454
-
1455
-	/**
1456
-	 * @return AppFetcher
1457
-	 */
1458
-	public function getAppFetcher() {
1459
-		return $this->query(AppFetcher::class);
1460
-	}
1461
-
1462
-	/**
1463
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1464
-	 * getMemCacheFactory() instead.
1465
-	 *
1466
-	 * @return \OCP\ICache
1467
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1468
-	 */
1469
-	public function getCache() {
1470
-		return $this->query('UserCache');
1471
-	}
1472
-
1473
-	/**
1474
-	 * Returns an \OCP\CacheFactory instance
1475
-	 *
1476
-	 * @return \OCP\ICacheFactory
1477
-	 */
1478
-	public function getMemCacheFactory() {
1479
-		return $this->query('MemCacheFactory');
1480
-	}
1481
-
1482
-	/**
1483
-	 * Returns an \OC\RedisFactory instance
1484
-	 *
1485
-	 * @return \OC\RedisFactory
1486
-	 */
1487
-	public function getGetRedisFactory() {
1488
-		return $this->query('RedisFactory');
1489
-	}
1490
-
1491
-
1492
-	/**
1493
-	 * Returns the current session
1494
-	 *
1495
-	 * @return \OCP\IDBConnection
1496
-	 */
1497
-	public function getDatabaseConnection() {
1498
-		return $this->query('DatabaseConnection');
1499
-	}
1500
-
1501
-	/**
1502
-	 * Returns the activity manager
1503
-	 *
1504
-	 * @return \OCP\Activity\IManager
1505
-	 */
1506
-	public function getActivityManager() {
1507
-		return $this->query('ActivityManager');
1508
-	}
1509
-
1510
-	/**
1511
-	 * Returns an job list for controlling background jobs
1512
-	 *
1513
-	 * @return \OCP\BackgroundJob\IJobList
1514
-	 */
1515
-	public function getJobList() {
1516
-		return $this->query('JobList');
1517
-	}
1518
-
1519
-	/**
1520
-	 * Returns a logger instance
1521
-	 *
1522
-	 * @return \OCP\ILogger
1523
-	 */
1524
-	public function getLogger() {
1525
-		return $this->query('Logger');
1526
-	}
1527
-
1528
-	/**
1529
-	 * @return ILogFactory
1530
-	 * @throws \OCP\AppFramework\QueryException
1531
-	 */
1532
-	public function getLogFactory() {
1533
-		return $this->query(ILogFactory::class);
1534
-	}
1535
-
1536
-	/**
1537
-	 * Returns a router for generating and matching urls
1538
-	 *
1539
-	 * @return \OCP\Route\IRouter
1540
-	 */
1541
-	public function getRouter() {
1542
-		return $this->query('Router');
1543
-	}
1544
-
1545
-	/**
1546
-	 * Returns a search instance
1547
-	 *
1548
-	 * @return \OCP\ISearch
1549
-	 */
1550
-	public function getSearch() {
1551
-		return $this->query('Search');
1552
-	}
1553
-
1554
-	/**
1555
-	 * Returns a SecureRandom instance
1556
-	 *
1557
-	 * @return \OCP\Security\ISecureRandom
1558
-	 */
1559
-	public function getSecureRandom() {
1560
-		return $this->query('SecureRandom');
1561
-	}
1562
-
1563
-	/**
1564
-	 * Returns a Crypto instance
1565
-	 *
1566
-	 * @return \OCP\Security\ICrypto
1567
-	 */
1568
-	public function getCrypto() {
1569
-		return $this->query('Crypto');
1570
-	}
1571
-
1572
-	/**
1573
-	 * Returns a Hasher instance
1574
-	 *
1575
-	 * @return \OCP\Security\IHasher
1576
-	 */
1577
-	public function getHasher() {
1578
-		return $this->query('Hasher');
1579
-	}
1580
-
1581
-	/**
1582
-	 * Returns a CredentialsManager instance
1583
-	 *
1584
-	 * @return \OCP\Security\ICredentialsManager
1585
-	 */
1586
-	public function getCredentialsManager() {
1587
-		return $this->query('CredentialsManager');
1588
-	}
1589
-
1590
-	/**
1591
-	 * Get the certificate manager for the user
1592
-	 *
1593
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1594
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1595
-	 */
1596
-	public function getCertificateManager($userId = '') {
1597
-		if ($userId === '') {
1598
-			$userSession = $this->getUserSession();
1599
-			$user = $userSession->getUser();
1600
-			if (is_null($user)) {
1601
-				return null;
1602
-			}
1603
-			$userId = $user->getUID();
1604
-		}
1605
-		return new CertificateManager(
1606
-			$userId,
1607
-			new View(),
1608
-			$this->getConfig(),
1609
-			$this->getLogger(),
1610
-			$this->getSecureRandom()
1611
-		);
1612
-	}
1613
-
1614
-	/**
1615
-	 * Returns an instance of the HTTP client service
1616
-	 *
1617
-	 * @return \OCP\Http\Client\IClientService
1618
-	 */
1619
-	public function getHTTPClientService() {
1620
-		return $this->query('HttpClientService');
1621
-	}
1622
-
1623
-	/**
1624
-	 * Create a new event source
1625
-	 *
1626
-	 * @return \OCP\IEventSource
1627
-	 */
1628
-	public function createEventSource() {
1629
-		return new \OC_EventSource();
1630
-	}
1631
-
1632
-	/**
1633
-	 * Get the active event logger
1634
-	 *
1635
-	 * The returned logger only logs data when debug mode is enabled
1636
-	 *
1637
-	 * @return \OCP\Diagnostics\IEventLogger
1638
-	 */
1639
-	public function getEventLogger() {
1640
-		return $this->query('EventLogger');
1641
-	}
1642
-
1643
-	/**
1644
-	 * Get the active query logger
1645
-	 *
1646
-	 * The returned logger only logs data when debug mode is enabled
1647
-	 *
1648
-	 * @return \OCP\Diagnostics\IQueryLogger
1649
-	 */
1650
-	public function getQueryLogger() {
1651
-		return $this->query('QueryLogger');
1652
-	}
1653
-
1654
-	/**
1655
-	 * Get the manager for temporary files and folders
1656
-	 *
1657
-	 * @return \OCP\ITempManager
1658
-	 */
1659
-	public function getTempManager() {
1660
-		return $this->query('TempManager');
1661
-	}
1662
-
1663
-	/**
1664
-	 * Get the app manager
1665
-	 *
1666
-	 * @return \OCP\App\IAppManager
1667
-	 */
1668
-	public function getAppManager() {
1669
-		return $this->query('AppManager');
1670
-	}
1671
-
1672
-	/**
1673
-	 * Creates a new mailer
1674
-	 *
1675
-	 * @return \OCP\Mail\IMailer
1676
-	 */
1677
-	public function getMailer() {
1678
-		return $this->query('Mailer');
1679
-	}
1680
-
1681
-	/**
1682
-	 * Get the webroot
1683
-	 *
1684
-	 * @return string
1685
-	 */
1686
-	public function getWebRoot() {
1687
-		return $this->webRoot;
1688
-	}
1689
-
1690
-	/**
1691
-	 * @return \OC\OCSClient
1692
-	 */
1693
-	public function getOcsClient() {
1694
-		return $this->query('OcsClient');
1695
-	}
1696
-
1697
-	/**
1698
-	 * @return \OCP\IDateTimeZone
1699
-	 */
1700
-	public function getDateTimeZone() {
1701
-		return $this->query('DateTimeZone');
1702
-	}
1703
-
1704
-	/**
1705
-	 * @return \OCP\IDateTimeFormatter
1706
-	 */
1707
-	public function getDateTimeFormatter() {
1708
-		return $this->query('DateTimeFormatter');
1709
-	}
1710
-
1711
-	/**
1712
-	 * @return \OCP\Files\Config\IMountProviderCollection
1713
-	 */
1714
-	public function getMountProviderCollection() {
1715
-		return $this->query('MountConfigManager');
1716
-	}
1717
-
1718
-	/**
1719
-	 * Get the IniWrapper
1720
-	 *
1721
-	 * @return IniGetWrapper
1722
-	 */
1723
-	public function getIniWrapper() {
1724
-		return $this->query('IniWrapper');
1725
-	}
1726
-
1727
-	/**
1728
-	 * @return \OCP\Command\IBus
1729
-	 */
1730
-	public function getCommandBus() {
1731
-		return $this->query('AsyncCommandBus');
1732
-	}
1733
-
1734
-	/**
1735
-	 * Get the trusted domain helper
1736
-	 *
1737
-	 * @return TrustedDomainHelper
1738
-	 */
1739
-	public function getTrustedDomainHelper() {
1740
-		return $this->query('TrustedDomainHelper');
1741
-	}
1742
-
1743
-	/**
1744
-	 * Get the locking provider
1745
-	 *
1746
-	 * @return \OCP\Lock\ILockingProvider
1747
-	 * @since 8.1.0
1748
-	 */
1749
-	public function getLockingProvider() {
1750
-		return $this->query('LockingProvider');
1751
-	}
1752
-
1753
-	/**
1754
-	 * @return \OCP\Files\Mount\IMountManager
1755
-	 **/
1756
-	function getMountManager() {
1757
-		return $this->query('MountManager');
1758
-	}
1759
-
1760
-	/** @return \OCP\Files\Config\IUserMountCache */
1761
-	function getUserMountCache() {
1762
-		return $this->query('UserMountCache');
1763
-	}
1764
-
1765
-	/**
1766
-	 * Get the MimeTypeDetector
1767
-	 *
1768
-	 * @return \OCP\Files\IMimeTypeDetector
1769
-	 */
1770
-	public function getMimeTypeDetector() {
1771
-		return $this->query('MimeTypeDetector');
1772
-	}
1773
-
1774
-	/**
1775
-	 * Get the MimeTypeLoader
1776
-	 *
1777
-	 * @return \OCP\Files\IMimeTypeLoader
1778
-	 */
1779
-	public function getMimeTypeLoader() {
1780
-		return $this->query('MimeTypeLoader');
1781
-	}
1782
-
1783
-	/**
1784
-	 * Get the manager of all the capabilities
1785
-	 *
1786
-	 * @return \OC\CapabilitiesManager
1787
-	 */
1788
-	public function getCapabilitiesManager() {
1789
-		return $this->query('CapabilitiesManager');
1790
-	}
1791
-
1792
-	/**
1793
-	 * Get the EventDispatcher
1794
-	 *
1795
-	 * @return EventDispatcherInterface
1796
-	 * @since 8.2.0
1797
-	 */
1798
-	public function getEventDispatcher() {
1799
-		return $this->query('EventDispatcher');
1800
-	}
1801
-
1802
-	/**
1803
-	 * Get the Notification Manager
1804
-	 *
1805
-	 * @return \OCP\Notification\IManager
1806
-	 * @since 8.2.0
1807
-	 */
1808
-	public function getNotificationManager() {
1809
-		return $this->query('NotificationManager');
1810
-	}
1811
-
1812
-	/**
1813
-	 * @return \OCP\Comments\ICommentsManager
1814
-	 */
1815
-	public function getCommentsManager() {
1816
-		return $this->query('CommentsManager');
1817
-	}
1818
-
1819
-	/**
1820
-	 * @return \OCA\Theming\ThemingDefaults
1821
-	 */
1822
-	public function getThemingDefaults() {
1823
-		return $this->query('ThemingDefaults');
1824
-	}
1825
-
1826
-	/**
1827
-	 * @return \OC\IntegrityCheck\Checker
1828
-	 */
1829
-	public function getIntegrityCodeChecker() {
1830
-		return $this->query('IntegrityCodeChecker');
1831
-	}
1832
-
1833
-	/**
1834
-	 * @return \OC\Session\CryptoWrapper
1835
-	 */
1836
-	public function getSessionCryptoWrapper() {
1837
-		return $this->query('CryptoWrapper');
1838
-	}
1839
-
1840
-	/**
1841
-	 * @return CsrfTokenManager
1842
-	 */
1843
-	public function getCsrfTokenManager() {
1844
-		return $this->query('CsrfTokenManager');
1845
-	}
1846
-
1847
-	/**
1848
-	 * @return Throttler
1849
-	 */
1850
-	public function getBruteForceThrottler() {
1851
-		return $this->query('Throttler');
1852
-	}
1853
-
1854
-	/**
1855
-	 * @return IContentSecurityPolicyManager
1856
-	 */
1857
-	public function getContentSecurityPolicyManager() {
1858
-		return $this->query('ContentSecurityPolicyManager');
1859
-	}
1860
-
1861
-	/**
1862
-	 * @return ContentSecurityPolicyNonceManager
1863
-	 */
1864
-	public function getContentSecurityPolicyNonceManager() {
1865
-		return $this->query('ContentSecurityPolicyNonceManager');
1866
-	}
1867
-
1868
-	/**
1869
-	 * Not a public API as of 8.2, wait for 9.0
1870
-	 *
1871
-	 * @return \OCA\Files_External\Service\BackendService
1872
-	 */
1873
-	public function getStoragesBackendService() {
1874
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1875
-	}
1876
-
1877
-	/**
1878
-	 * Not a public API as of 8.2, wait for 9.0
1879
-	 *
1880
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1881
-	 */
1882
-	public function getGlobalStoragesService() {
1883
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1884
-	}
1885
-
1886
-	/**
1887
-	 * Not a public API as of 8.2, wait for 9.0
1888
-	 *
1889
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1890
-	 */
1891
-	public function getUserGlobalStoragesService() {
1892
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1893
-	}
1894
-
1895
-	/**
1896
-	 * Not a public API as of 8.2, wait for 9.0
1897
-	 *
1898
-	 * @return \OCA\Files_External\Service\UserStoragesService
1899
-	 */
1900
-	public function getUserStoragesService() {
1901
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1902
-	}
1903
-
1904
-	/**
1905
-	 * @return \OCP\Share\IManager
1906
-	 */
1907
-	public function getShareManager() {
1908
-		return $this->query('ShareManager');
1909
-	}
1910
-
1911
-	/**
1912
-	 * @return \OCP\Collaboration\Collaborators\ISearch
1913
-	 */
1914
-	public function getCollaboratorSearch() {
1915
-		return $this->query('CollaboratorSearch');
1916
-	}
1917
-
1918
-	/**
1919
-	 * @return \OCP\Collaboration\AutoComplete\IManager
1920
-	 */
1921
-	public function getAutoCompleteManager(){
1922
-		return $this->query(IManager::class);
1923
-	}
1924
-
1925
-	/**
1926
-	 * Returns the LDAP Provider
1927
-	 *
1928
-	 * @return \OCP\LDAP\ILDAPProvider
1929
-	 */
1930
-	public function getLDAPProvider() {
1931
-		return $this->query('LDAPProvider');
1932
-	}
1933
-
1934
-	/**
1935
-	 * @return \OCP\Settings\IManager
1936
-	 */
1937
-	public function getSettingsManager() {
1938
-		return $this->query('SettingsManager');
1939
-	}
1940
-
1941
-	/**
1942
-	 * @return \OCP\Files\IAppData
1943
-	 */
1944
-	public function getAppDataDir($app) {
1945
-		/** @var \OC\Files\AppData\Factory $factory */
1946
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1947
-		return $factory->get($app);
1948
-	}
1949
-
1950
-	/**
1951
-	 * @return \OCP\Lockdown\ILockdownManager
1952
-	 */
1953
-	public function getLockdownManager() {
1954
-		return $this->query('LockdownManager');
1955
-	}
1956
-
1957
-	/**
1958
-	 * @return \OCP\Federation\ICloudIdManager
1959
-	 */
1960
-	public function getCloudIdManager() {
1961
-		return $this->query(ICloudIdManager::class);
1962
-	}
1963
-
1964
-	/**
1965
-	 * @return \OCP\Remote\Api\IApiFactory
1966
-	 */
1967
-	public function getRemoteApiFactory() {
1968
-		return $this->query(IApiFactory::class);
1969
-	}
1970
-
1971
-	/**
1972
-	 * @return \OCP\Remote\IInstanceFactory
1973
-	 */
1974
-	public function getRemoteInstanceFactory() {
1975
-		return $this->query(IInstanceFactory::class);
1976
-	}
932
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
933
+            if (isset($prefixes['OCA\\Theming\\'])) {
934
+                $classExists = true;
935
+            } else {
936
+                $classExists = false;
937
+            }
938
+
939
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
940
+                return new ThemingDefaults(
941
+                    $c->getConfig(),
942
+                    $c->getL10N('theming'),
943
+                    $c->getURLGenerator(),
944
+                    $c->getMemCacheFactory(),
945
+                    new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
946
+                    new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
947
+                    $c->getAppManager()
948
+                );
949
+            }
950
+            return new \OC_Defaults();
951
+        });
952
+        $this->registerService(SCSSCacher::class, function (Server $c) {
953
+            /** @var Factory $cacheFactory */
954
+            $cacheFactory = $c->query(Factory::class);
955
+            return new SCSSCacher(
956
+                $c->getLogger(),
957
+                $c->query(\OC\Files\AppData\Factory::class),
958
+                $c->getURLGenerator(),
959
+                $c->getConfig(),
960
+                $c->getThemingDefaults(),
961
+                \OC::$SERVERROOT,
962
+                $this->getMemCacheFactory()
963
+            );
964
+        });
965
+        $this->registerService(JSCombiner::class, function (Server $c) {
966
+            /** @var Factory $cacheFactory */
967
+            $cacheFactory = $c->query(Factory::class);
968
+            return new JSCombiner(
969
+                $c->getAppDataDir('js'),
970
+                $c->getURLGenerator(),
971
+                $this->getMemCacheFactory(),
972
+                $c->getSystemConfig(),
973
+                $c->getLogger()
974
+            );
975
+        });
976
+        $this->registerService(EventDispatcher::class, function () {
977
+            return new EventDispatcher();
978
+        });
979
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
980
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
981
+
982
+        $this->registerService('CryptoWrapper', function (Server $c) {
983
+            // FIXME: Instantiiated here due to cyclic dependency
984
+            $request = new Request(
985
+                [
986
+                    'get' => $_GET,
987
+                    'post' => $_POST,
988
+                    'files' => $_FILES,
989
+                    'server' => $_SERVER,
990
+                    'env' => $_ENV,
991
+                    'cookies' => $_COOKIE,
992
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
993
+                        ? $_SERVER['REQUEST_METHOD']
994
+                        : null,
995
+                ],
996
+                $c->getSecureRandom(),
997
+                $c->getConfig()
998
+            );
999
+
1000
+            return new CryptoWrapper(
1001
+                $c->getConfig(),
1002
+                $c->getCrypto(),
1003
+                $c->getSecureRandom(),
1004
+                $request
1005
+            );
1006
+        });
1007
+        $this->registerService('CsrfTokenManager', function (Server $c) {
1008
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1009
+
1010
+            return new CsrfTokenManager(
1011
+                $tokenGenerator,
1012
+                $c->query(SessionStorage::class)
1013
+            );
1014
+        });
1015
+        $this->registerService(SessionStorage::class, function (Server $c) {
1016
+            return new SessionStorage($c->getSession());
1017
+        });
1018
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1019
+            return new ContentSecurityPolicyManager();
1020
+        });
1021
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1022
+
1023
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1024
+            return new ContentSecurityPolicyNonceManager(
1025
+                $c->getCsrfTokenManager(),
1026
+                $c->getRequest()
1027
+            );
1028
+        });
1029
+
1030
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1031
+            $config = $c->getConfig();
1032
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1033
+            /** @var \OCP\Share\IProviderFactory $factory */
1034
+            $factory = new $factoryClass($this);
1035
+
1036
+            $manager = new \OC\Share20\Manager(
1037
+                $c->getLogger(),
1038
+                $c->getConfig(),
1039
+                $c->getSecureRandom(),
1040
+                $c->getHasher(),
1041
+                $c->getMountManager(),
1042
+                $c->getGroupManager(),
1043
+                $c->getL10N('lib'),
1044
+                $c->getL10NFactory(),
1045
+                $factory,
1046
+                $c->getUserManager(),
1047
+                $c->getLazyRootFolder(),
1048
+                $c->getEventDispatcher(),
1049
+                $c->getMailer(),
1050
+                $c->getURLGenerator(),
1051
+                $c->getThemingDefaults()
1052
+            );
1053
+
1054
+            return $manager;
1055
+        });
1056
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1057
+
1058
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1059
+            $instance = new Collaboration\Collaborators\Search($c);
1060
+
1061
+            // register default plugins
1062
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1063
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1064
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1065
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1066
+
1067
+            return $instance;
1068
+        });
1069
+        $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1070
+
1071
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1072
+
1073
+        $this->registerService('SettingsManager', function (Server $c) {
1074
+            $manager = new \OC\Settings\Manager(
1075
+                $c->getLogger(),
1076
+                $c->getDatabaseConnection(),
1077
+                $c->getL10N('lib'),
1078
+                $c->getConfig(),
1079
+                $c->getEncryptionManager(),
1080
+                $c->getUserManager(),
1081
+                $c->getLockingProvider(),
1082
+                $c->getRequest(),
1083
+                $c->getURLGenerator(),
1084
+                $c->query(AccountManager::class),
1085
+                $c->getGroupManager(),
1086
+                $c->getL10NFactory(),
1087
+                $c->getAppManager()
1088
+            );
1089
+            return $manager;
1090
+        });
1091
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1092
+            return new \OC\Files\AppData\Factory(
1093
+                $c->getRootFolder(),
1094
+                $c->getSystemConfig()
1095
+            );
1096
+        });
1097
+
1098
+        $this->registerService('LockdownManager', function (Server $c) {
1099
+            return new LockdownManager(function () use ($c) {
1100
+                return $c->getSession();
1101
+            });
1102
+        });
1103
+
1104
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1105
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1106
+        });
1107
+
1108
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1109
+            return new CloudIdManager();
1110
+        });
1111
+
1112
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1113
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1114
+
1115
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1116
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1117
+
1118
+        $this->registerService(Defaults::class, function (Server $c) {
1119
+            return new Defaults(
1120
+                $c->getThemingDefaults()
1121
+            );
1122
+        });
1123
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1124
+
1125
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1126
+            return $c->query(\OCP\IUserSession::class)->getSession();
1127
+        });
1128
+
1129
+        $this->registerService(IShareHelper::class, function (Server $c) {
1130
+            return new ShareHelper(
1131
+                $c->query(\OCP\Share\IManager::class)
1132
+            );
1133
+        });
1134
+
1135
+        $this->registerService(Installer::class, function(Server $c) {
1136
+            return new Installer(
1137
+                $c->getAppFetcher(),
1138
+                $c->getHTTPClientService(),
1139
+                $c->getTempManager(),
1140
+                $c->getLogger(),
1141
+                $c->getConfig()
1142
+            );
1143
+        });
1144
+
1145
+        $this->registerService(IApiFactory::class, function(Server $c) {
1146
+            return new ApiFactory($c->getHTTPClientService());
1147
+        });
1148
+
1149
+        $this->registerService(IInstanceFactory::class, function(Server $c) {
1150
+            $memcacheFactory = $c->getMemCacheFactory();
1151
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1152
+        });
1153
+
1154
+        $this->registerService(IContactsStore::class, function(Server $c) {
1155
+            return new ContactsStore(
1156
+                $c->getContactsManager(),
1157
+                $c->getConfig(),
1158
+                $c->getUserManager(),
1159
+                $c->getGroupManager()
1160
+            );
1161
+        });
1162
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1163
+
1164
+        $this->connectDispatcher();
1165
+    }
1166
+
1167
+    /**
1168
+     * @return \OCP\Calendar\IManager
1169
+     */
1170
+    public function getCalendarManager() {
1171
+        return $this->query('CalendarManager');
1172
+    }
1173
+
1174
+    private function connectDispatcher() {
1175
+        $dispatcher = $this->getEventDispatcher();
1176
+
1177
+        // Delete avatar on user deletion
1178
+        $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1179
+            $logger = $this->getLogger();
1180
+            $manager = $this->getAvatarManager();
1181
+            /** @var IUser $user */
1182
+            $user = $e->getSubject();
1183
+
1184
+            try {
1185
+                $avatar = $manager->getAvatar($user->getUID());
1186
+                $avatar->remove();
1187
+            } catch (NotFoundException $e) {
1188
+                // no avatar to remove
1189
+            } catch (\Exception $e) {
1190
+                // Ignore exceptions
1191
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1192
+            }
1193
+        });
1194
+
1195
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1196
+            $manager = $this->getAvatarManager();
1197
+            /** @var IUser $user */
1198
+            $user = $e->getSubject();
1199
+            $feature = $e->getArgument('feature');
1200
+            $oldValue = $e->getArgument('oldValue');
1201
+            $value = $e->getArgument('value');
1202
+
1203
+            try {
1204
+                $avatar = $manager->getAvatar($user->getUID());
1205
+                $avatar->userChanged($feature, $oldValue, $value);
1206
+            } catch (NotFoundException $e) {
1207
+                // no avatar to remove
1208
+            }
1209
+        });
1210
+    }
1211
+
1212
+    /**
1213
+     * @return \OCP\Contacts\IManager
1214
+     */
1215
+    public function getContactsManager() {
1216
+        return $this->query('ContactsManager');
1217
+    }
1218
+
1219
+    /**
1220
+     * @return \OC\Encryption\Manager
1221
+     */
1222
+    public function getEncryptionManager() {
1223
+        return $this->query('EncryptionManager');
1224
+    }
1225
+
1226
+    /**
1227
+     * @return \OC\Encryption\File
1228
+     */
1229
+    public function getEncryptionFilesHelper() {
1230
+        return $this->query('EncryptionFileHelper');
1231
+    }
1232
+
1233
+    /**
1234
+     * @return \OCP\Encryption\Keys\IStorage
1235
+     */
1236
+    public function getEncryptionKeyStorage() {
1237
+        return $this->query('EncryptionKeyStorage');
1238
+    }
1239
+
1240
+    /**
1241
+     * The current request object holding all information about the request
1242
+     * currently being processed is returned from this method.
1243
+     * In case the current execution was not initiated by a web request null is returned
1244
+     *
1245
+     * @return \OCP\IRequest
1246
+     */
1247
+    public function getRequest() {
1248
+        return $this->query('Request');
1249
+    }
1250
+
1251
+    /**
1252
+     * Returns the preview manager which can create preview images for a given file
1253
+     *
1254
+     * @return \OCP\IPreview
1255
+     */
1256
+    public function getPreviewManager() {
1257
+        return $this->query('PreviewManager');
1258
+    }
1259
+
1260
+    /**
1261
+     * Returns the tag manager which can get and set tags for different object types
1262
+     *
1263
+     * @see \OCP\ITagManager::load()
1264
+     * @return \OCP\ITagManager
1265
+     */
1266
+    public function getTagManager() {
1267
+        return $this->query('TagManager');
1268
+    }
1269
+
1270
+    /**
1271
+     * Returns the system-tag manager
1272
+     *
1273
+     * @return \OCP\SystemTag\ISystemTagManager
1274
+     *
1275
+     * @since 9.0.0
1276
+     */
1277
+    public function getSystemTagManager() {
1278
+        return $this->query('SystemTagManager');
1279
+    }
1280
+
1281
+    /**
1282
+     * Returns the system-tag object mapper
1283
+     *
1284
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1285
+     *
1286
+     * @since 9.0.0
1287
+     */
1288
+    public function getSystemTagObjectMapper() {
1289
+        return $this->query('SystemTagObjectMapper');
1290
+    }
1291
+
1292
+    /**
1293
+     * Returns the avatar manager, used for avatar functionality
1294
+     *
1295
+     * @return \OCP\IAvatarManager
1296
+     */
1297
+    public function getAvatarManager() {
1298
+        return $this->query('AvatarManager');
1299
+    }
1300
+
1301
+    /**
1302
+     * Returns the root folder of ownCloud's data directory
1303
+     *
1304
+     * @return \OCP\Files\IRootFolder
1305
+     */
1306
+    public function getRootFolder() {
1307
+        return $this->query('LazyRootFolder');
1308
+    }
1309
+
1310
+    /**
1311
+     * Returns the root folder of ownCloud's data directory
1312
+     * This is the lazy variant so this gets only initialized once it
1313
+     * is actually used.
1314
+     *
1315
+     * @return \OCP\Files\IRootFolder
1316
+     */
1317
+    public function getLazyRootFolder() {
1318
+        return $this->query('LazyRootFolder');
1319
+    }
1320
+
1321
+    /**
1322
+     * Returns a view to ownCloud's files folder
1323
+     *
1324
+     * @param string $userId user ID
1325
+     * @return \OCP\Files\Folder|null
1326
+     */
1327
+    public function getUserFolder($userId = null) {
1328
+        if ($userId === null) {
1329
+            $user = $this->getUserSession()->getUser();
1330
+            if (!$user) {
1331
+                return null;
1332
+            }
1333
+            $userId = $user->getUID();
1334
+        }
1335
+        $root = $this->getRootFolder();
1336
+        return $root->getUserFolder($userId);
1337
+    }
1338
+
1339
+    /**
1340
+     * Returns an app-specific view in ownClouds data directory
1341
+     *
1342
+     * @return \OCP\Files\Folder
1343
+     * @deprecated since 9.2.0 use IAppData
1344
+     */
1345
+    public function getAppFolder() {
1346
+        $dir = '/' . \OC_App::getCurrentApp();
1347
+        $root = $this->getRootFolder();
1348
+        if (!$root->nodeExists($dir)) {
1349
+            $folder = $root->newFolder($dir);
1350
+        } else {
1351
+            $folder = $root->get($dir);
1352
+        }
1353
+        return $folder;
1354
+    }
1355
+
1356
+    /**
1357
+     * @return \OC\User\Manager
1358
+     */
1359
+    public function getUserManager() {
1360
+        return $this->query('UserManager');
1361
+    }
1362
+
1363
+    /**
1364
+     * @return \OC\Group\Manager
1365
+     */
1366
+    public function getGroupManager() {
1367
+        return $this->query('GroupManager');
1368
+    }
1369
+
1370
+    /**
1371
+     * @return \OC\User\Session
1372
+     */
1373
+    public function getUserSession() {
1374
+        return $this->query('UserSession');
1375
+    }
1376
+
1377
+    /**
1378
+     * @return \OCP\ISession
1379
+     */
1380
+    public function getSession() {
1381
+        return $this->query('UserSession')->getSession();
1382
+    }
1383
+
1384
+    /**
1385
+     * @param \OCP\ISession $session
1386
+     */
1387
+    public function setSession(\OCP\ISession $session) {
1388
+        $this->query(SessionStorage::class)->setSession($session);
1389
+        $this->query('UserSession')->setSession($session);
1390
+        $this->query(Store::class)->setSession($session);
1391
+    }
1392
+
1393
+    /**
1394
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1395
+     */
1396
+    public function getTwoFactorAuthManager() {
1397
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1398
+    }
1399
+
1400
+    /**
1401
+     * @return \OC\NavigationManager
1402
+     */
1403
+    public function getNavigationManager() {
1404
+        return $this->query('NavigationManager');
1405
+    }
1406
+
1407
+    /**
1408
+     * @return \OCP\IConfig
1409
+     */
1410
+    public function getConfig() {
1411
+        return $this->query('AllConfig');
1412
+    }
1413
+
1414
+    /**
1415
+     * @return \OC\SystemConfig
1416
+     */
1417
+    public function getSystemConfig() {
1418
+        return $this->query('SystemConfig');
1419
+    }
1420
+
1421
+    /**
1422
+     * Returns the app config manager
1423
+     *
1424
+     * @return \OCP\IAppConfig
1425
+     */
1426
+    public function getAppConfig() {
1427
+        return $this->query('AppConfig');
1428
+    }
1429
+
1430
+    /**
1431
+     * @return \OCP\L10N\IFactory
1432
+     */
1433
+    public function getL10NFactory() {
1434
+        return $this->query('L10NFactory');
1435
+    }
1436
+
1437
+    /**
1438
+     * get an L10N instance
1439
+     *
1440
+     * @param string $app appid
1441
+     * @param string $lang
1442
+     * @return IL10N
1443
+     */
1444
+    public function getL10N($app, $lang = null) {
1445
+        return $this->getL10NFactory()->get($app, $lang);
1446
+    }
1447
+
1448
+    /**
1449
+     * @return \OCP\IURLGenerator
1450
+     */
1451
+    public function getURLGenerator() {
1452
+        return $this->query('URLGenerator');
1453
+    }
1454
+
1455
+    /**
1456
+     * @return AppFetcher
1457
+     */
1458
+    public function getAppFetcher() {
1459
+        return $this->query(AppFetcher::class);
1460
+    }
1461
+
1462
+    /**
1463
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1464
+     * getMemCacheFactory() instead.
1465
+     *
1466
+     * @return \OCP\ICache
1467
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1468
+     */
1469
+    public function getCache() {
1470
+        return $this->query('UserCache');
1471
+    }
1472
+
1473
+    /**
1474
+     * Returns an \OCP\CacheFactory instance
1475
+     *
1476
+     * @return \OCP\ICacheFactory
1477
+     */
1478
+    public function getMemCacheFactory() {
1479
+        return $this->query('MemCacheFactory');
1480
+    }
1481
+
1482
+    /**
1483
+     * Returns an \OC\RedisFactory instance
1484
+     *
1485
+     * @return \OC\RedisFactory
1486
+     */
1487
+    public function getGetRedisFactory() {
1488
+        return $this->query('RedisFactory');
1489
+    }
1490
+
1491
+
1492
+    /**
1493
+     * Returns the current session
1494
+     *
1495
+     * @return \OCP\IDBConnection
1496
+     */
1497
+    public function getDatabaseConnection() {
1498
+        return $this->query('DatabaseConnection');
1499
+    }
1500
+
1501
+    /**
1502
+     * Returns the activity manager
1503
+     *
1504
+     * @return \OCP\Activity\IManager
1505
+     */
1506
+    public function getActivityManager() {
1507
+        return $this->query('ActivityManager');
1508
+    }
1509
+
1510
+    /**
1511
+     * Returns an job list for controlling background jobs
1512
+     *
1513
+     * @return \OCP\BackgroundJob\IJobList
1514
+     */
1515
+    public function getJobList() {
1516
+        return $this->query('JobList');
1517
+    }
1518
+
1519
+    /**
1520
+     * Returns a logger instance
1521
+     *
1522
+     * @return \OCP\ILogger
1523
+     */
1524
+    public function getLogger() {
1525
+        return $this->query('Logger');
1526
+    }
1527
+
1528
+    /**
1529
+     * @return ILogFactory
1530
+     * @throws \OCP\AppFramework\QueryException
1531
+     */
1532
+    public function getLogFactory() {
1533
+        return $this->query(ILogFactory::class);
1534
+    }
1535
+
1536
+    /**
1537
+     * Returns a router for generating and matching urls
1538
+     *
1539
+     * @return \OCP\Route\IRouter
1540
+     */
1541
+    public function getRouter() {
1542
+        return $this->query('Router');
1543
+    }
1544
+
1545
+    /**
1546
+     * Returns a search instance
1547
+     *
1548
+     * @return \OCP\ISearch
1549
+     */
1550
+    public function getSearch() {
1551
+        return $this->query('Search');
1552
+    }
1553
+
1554
+    /**
1555
+     * Returns a SecureRandom instance
1556
+     *
1557
+     * @return \OCP\Security\ISecureRandom
1558
+     */
1559
+    public function getSecureRandom() {
1560
+        return $this->query('SecureRandom');
1561
+    }
1562
+
1563
+    /**
1564
+     * Returns a Crypto instance
1565
+     *
1566
+     * @return \OCP\Security\ICrypto
1567
+     */
1568
+    public function getCrypto() {
1569
+        return $this->query('Crypto');
1570
+    }
1571
+
1572
+    /**
1573
+     * Returns a Hasher instance
1574
+     *
1575
+     * @return \OCP\Security\IHasher
1576
+     */
1577
+    public function getHasher() {
1578
+        return $this->query('Hasher');
1579
+    }
1580
+
1581
+    /**
1582
+     * Returns a CredentialsManager instance
1583
+     *
1584
+     * @return \OCP\Security\ICredentialsManager
1585
+     */
1586
+    public function getCredentialsManager() {
1587
+        return $this->query('CredentialsManager');
1588
+    }
1589
+
1590
+    /**
1591
+     * Get the certificate manager for the user
1592
+     *
1593
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1594
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1595
+     */
1596
+    public function getCertificateManager($userId = '') {
1597
+        if ($userId === '') {
1598
+            $userSession = $this->getUserSession();
1599
+            $user = $userSession->getUser();
1600
+            if (is_null($user)) {
1601
+                return null;
1602
+            }
1603
+            $userId = $user->getUID();
1604
+        }
1605
+        return new CertificateManager(
1606
+            $userId,
1607
+            new View(),
1608
+            $this->getConfig(),
1609
+            $this->getLogger(),
1610
+            $this->getSecureRandom()
1611
+        );
1612
+    }
1613
+
1614
+    /**
1615
+     * Returns an instance of the HTTP client service
1616
+     *
1617
+     * @return \OCP\Http\Client\IClientService
1618
+     */
1619
+    public function getHTTPClientService() {
1620
+        return $this->query('HttpClientService');
1621
+    }
1622
+
1623
+    /**
1624
+     * Create a new event source
1625
+     *
1626
+     * @return \OCP\IEventSource
1627
+     */
1628
+    public function createEventSource() {
1629
+        return new \OC_EventSource();
1630
+    }
1631
+
1632
+    /**
1633
+     * Get the active event logger
1634
+     *
1635
+     * The returned logger only logs data when debug mode is enabled
1636
+     *
1637
+     * @return \OCP\Diagnostics\IEventLogger
1638
+     */
1639
+    public function getEventLogger() {
1640
+        return $this->query('EventLogger');
1641
+    }
1642
+
1643
+    /**
1644
+     * Get the active query logger
1645
+     *
1646
+     * The returned logger only logs data when debug mode is enabled
1647
+     *
1648
+     * @return \OCP\Diagnostics\IQueryLogger
1649
+     */
1650
+    public function getQueryLogger() {
1651
+        return $this->query('QueryLogger');
1652
+    }
1653
+
1654
+    /**
1655
+     * Get the manager for temporary files and folders
1656
+     *
1657
+     * @return \OCP\ITempManager
1658
+     */
1659
+    public function getTempManager() {
1660
+        return $this->query('TempManager');
1661
+    }
1662
+
1663
+    /**
1664
+     * Get the app manager
1665
+     *
1666
+     * @return \OCP\App\IAppManager
1667
+     */
1668
+    public function getAppManager() {
1669
+        return $this->query('AppManager');
1670
+    }
1671
+
1672
+    /**
1673
+     * Creates a new mailer
1674
+     *
1675
+     * @return \OCP\Mail\IMailer
1676
+     */
1677
+    public function getMailer() {
1678
+        return $this->query('Mailer');
1679
+    }
1680
+
1681
+    /**
1682
+     * Get the webroot
1683
+     *
1684
+     * @return string
1685
+     */
1686
+    public function getWebRoot() {
1687
+        return $this->webRoot;
1688
+    }
1689
+
1690
+    /**
1691
+     * @return \OC\OCSClient
1692
+     */
1693
+    public function getOcsClient() {
1694
+        return $this->query('OcsClient');
1695
+    }
1696
+
1697
+    /**
1698
+     * @return \OCP\IDateTimeZone
1699
+     */
1700
+    public function getDateTimeZone() {
1701
+        return $this->query('DateTimeZone');
1702
+    }
1703
+
1704
+    /**
1705
+     * @return \OCP\IDateTimeFormatter
1706
+     */
1707
+    public function getDateTimeFormatter() {
1708
+        return $this->query('DateTimeFormatter');
1709
+    }
1710
+
1711
+    /**
1712
+     * @return \OCP\Files\Config\IMountProviderCollection
1713
+     */
1714
+    public function getMountProviderCollection() {
1715
+        return $this->query('MountConfigManager');
1716
+    }
1717
+
1718
+    /**
1719
+     * Get the IniWrapper
1720
+     *
1721
+     * @return IniGetWrapper
1722
+     */
1723
+    public function getIniWrapper() {
1724
+        return $this->query('IniWrapper');
1725
+    }
1726
+
1727
+    /**
1728
+     * @return \OCP\Command\IBus
1729
+     */
1730
+    public function getCommandBus() {
1731
+        return $this->query('AsyncCommandBus');
1732
+    }
1733
+
1734
+    /**
1735
+     * Get the trusted domain helper
1736
+     *
1737
+     * @return TrustedDomainHelper
1738
+     */
1739
+    public function getTrustedDomainHelper() {
1740
+        return $this->query('TrustedDomainHelper');
1741
+    }
1742
+
1743
+    /**
1744
+     * Get the locking provider
1745
+     *
1746
+     * @return \OCP\Lock\ILockingProvider
1747
+     * @since 8.1.0
1748
+     */
1749
+    public function getLockingProvider() {
1750
+        return $this->query('LockingProvider');
1751
+    }
1752
+
1753
+    /**
1754
+     * @return \OCP\Files\Mount\IMountManager
1755
+     **/
1756
+    function getMountManager() {
1757
+        return $this->query('MountManager');
1758
+    }
1759
+
1760
+    /** @return \OCP\Files\Config\IUserMountCache */
1761
+    function getUserMountCache() {
1762
+        return $this->query('UserMountCache');
1763
+    }
1764
+
1765
+    /**
1766
+     * Get the MimeTypeDetector
1767
+     *
1768
+     * @return \OCP\Files\IMimeTypeDetector
1769
+     */
1770
+    public function getMimeTypeDetector() {
1771
+        return $this->query('MimeTypeDetector');
1772
+    }
1773
+
1774
+    /**
1775
+     * Get the MimeTypeLoader
1776
+     *
1777
+     * @return \OCP\Files\IMimeTypeLoader
1778
+     */
1779
+    public function getMimeTypeLoader() {
1780
+        return $this->query('MimeTypeLoader');
1781
+    }
1782
+
1783
+    /**
1784
+     * Get the manager of all the capabilities
1785
+     *
1786
+     * @return \OC\CapabilitiesManager
1787
+     */
1788
+    public function getCapabilitiesManager() {
1789
+        return $this->query('CapabilitiesManager');
1790
+    }
1791
+
1792
+    /**
1793
+     * Get the EventDispatcher
1794
+     *
1795
+     * @return EventDispatcherInterface
1796
+     * @since 8.2.0
1797
+     */
1798
+    public function getEventDispatcher() {
1799
+        return $this->query('EventDispatcher');
1800
+    }
1801
+
1802
+    /**
1803
+     * Get the Notification Manager
1804
+     *
1805
+     * @return \OCP\Notification\IManager
1806
+     * @since 8.2.0
1807
+     */
1808
+    public function getNotificationManager() {
1809
+        return $this->query('NotificationManager');
1810
+    }
1811
+
1812
+    /**
1813
+     * @return \OCP\Comments\ICommentsManager
1814
+     */
1815
+    public function getCommentsManager() {
1816
+        return $this->query('CommentsManager');
1817
+    }
1818
+
1819
+    /**
1820
+     * @return \OCA\Theming\ThemingDefaults
1821
+     */
1822
+    public function getThemingDefaults() {
1823
+        return $this->query('ThemingDefaults');
1824
+    }
1825
+
1826
+    /**
1827
+     * @return \OC\IntegrityCheck\Checker
1828
+     */
1829
+    public function getIntegrityCodeChecker() {
1830
+        return $this->query('IntegrityCodeChecker');
1831
+    }
1832
+
1833
+    /**
1834
+     * @return \OC\Session\CryptoWrapper
1835
+     */
1836
+    public function getSessionCryptoWrapper() {
1837
+        return $this->query('CryptoWrapper');
1838
+    }
1839
+
1840
+    /**
1841
+     * @return CsrfTokenManager
1842
+     */
1843
+    public function getCsrfTokenManager() {
1844
+        return $this->query('CsrfTokenManager');
1845
+    }
1846
+
1847
+    /**
1848
+     * @return Throttler
1849
+     */
1850
+    public function getBruteForceThrottler() {
1851
+        return $this->query('Throttler');
1852
+    }
1853
+
1854
+    /**
1855
+     * @return IContentSecurityPolicyManager
1856
+     */
1857
+    public function getContentSecurityPolicyManager() {
1858
+        return $this->query('ContentSecurityPolicyManager');
1859
+    }
1860
+
1861
+    /**
1862
+     * @return ContentSecurityPolicyNonceManager
1863
+     */
1864
+    public function getContentSecurityPolicyNonceManager() {
1865
+        return $this->query('ContentSecurityPolicyNonceManager');
1866
+    }
1867
+
1868
+    /**
1869
+     * Not a public API as of 8.2, wait for 9.0
1870
+     *
1871
+     * @return \OCA\Files_External\Service\BackendService
1872
+     */
1873
+    public function getStoragesBackendService() {
1874
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1875
+    }
1876
+
1877
+    /**
1878
+     * Not a public API as of 8.2, wait for 9.0
1879
+     *
1880
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1881
+     */
1882
+    public function getGlobalStoragesService() {
1883
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1884
+    }
1885
+
1886
+    /**
1887
+     * Not a public API as of 8.2, wait for 9.0
1888
+     *
1889
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1890
+     */
1891
+    public function getUserGlobalStoragesService() {
1892
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1893
+    }
1894
+
1895
+    /**
1896
+     * Not a public API as of 8.2, wait for 9.0
1897
+     *
1898
+     * @return \OCA\Files_External\Service\UserStoragesService
1899
+     */
1900
+    public function getUserStoragesService() {
1901
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1902
+    }
1903
+
1904
+    /**
1905
+     * @return \OCP\Share\IManager
1906
+     */
1907
+    public function getShareManager() {
1908
+        return $this->query('ShareManager');
1909
+    }
1910
+
1911
+    /**
1912
+     * @return \OCP\Collaboration\Collaborators\ISearch
1913
+     */
1914
+    public function getCollaboratorSearch() {
1915
+        return $this->query('CollaboratorSearch');
1916
+    }
1917
+
1918
+    /**
1919
+     * @return \OCP\Collaboration\AutoComplete\IManager
1920
+     */
1921
+    public function getAutoCompleteManager(){
1922
+        return $this->query(IManager::class);
1923
+    }
1924
+
1925
+    /**
1926
+     * Returns the LDAP Provider
1927
+     *
1928
+     * @return \OCP\LDAP\ILDAPProvider
1929
+     */
1930
+    public function getLDAPProvider() {
1931
+        return $this->query('LDAPProvider');
1932
+    }
1933
+
1934
+    /**
1935
+     * @return \OCP\Settings\IManager
1936
+     */
1937
+    public function getSettingsManager() {
1938
+        return $this->query('SettingsManager');
1939
+    }
1940
+
1941
+    /**
1942
+     * @return \OCP\Files\IAppData
1943
+     */
1944
+    public function getAppDataDir($app) {
1945
+        /** @var \OC\Files\AppData\Factory $factory */
1946
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1947
+        return $factory->get($app);
1948
+    }
1949
+
1950
+    /**
1951
+     * @return \OCP\Lockdown\ILockdownManager
1952
+     */
1953
+    public function getLockdownManager() {
1954
+        return $this->query('LockdownManager');
1955
+    }
1956
+
1957
+    /**
1958
+     * @return \OCP\Federation\ICloudIdManager
1959
+     */
1960
+    public function getCloudIdManager() {
1961
+        return $this->query(ICloudIdManager::class);
1962
+    }
1963
+
1964
+    /**
1965
+     * @return \OCP\Remote\Api\IApiFactory
1966
+     */
1967
+    public function getRemoteApiFactory() {
1968
+        return $this->query(IApiFactory::class);
1969
+    }
1970
+
1971
+    /**
1972
+     * @return \OCP\Remote\IInstanceFactory
1973
+     */
1974
+    public function getRemoteInstanceFactory() {
1975
+        return $this->query(IInstanceFactory::class);
1976
+    }
1977 1977
 }
Please login to merge, or discard this patch.
lib/private/Authentication/TwoFactorAuth/Manager.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -44,331 +44,331 @@
 block discarded – undo
44 44
 
45 45
 class Manager {
46 46
 
47
-	const SESSION_UID_KEY = 'two_factor_auth_uid';
48
-	const SESSION_UID_DONE = 'two_factor_auth_passed';
49
-	const REMEMBER_LOGIN = 'two_factor_remember_login';
50
-
51
-	/** @var ProviderLoader */
52
-	private $providerLoader;
53
-
54
-	/** @var IRegistry */
55
-	private $providerRegistry;
56
-
57
-	/** @var ISession */
58
-	private $session;
59
-
60
-	/** @var IConfig */
61
-	private $config;
62
-
63
-	/** @var IManager */
64
-	private $activityManager;
65
-
66
-	/** @var ILogger */
67
-	private $logger;
68
-
69
-	/** @var TokenProvider */
70
-	private $tokenProvider;
71
-
72
-	/** @var ITimeFactory */
73
-	private $timeFactory;
74
-
75
-	/** @var EventDispatcherInterface */
76
-	private $dispatcher;
77
-
78
-	public function __construct(ProviderLoader $providerLoader,
79
-		IRegistry $providerRegistry, ISession $session, IConfig $config,
80
-		IManager $activityManager, ILogger $logger, TokenProvider $tokenProvider,
81
-		ITimeFactory $timeFactory, EventDispatcherInterface $eventDispatcher) {
82
-		$this->providerLoader = $providerLoader;
83
-		$this->session = $session;
84
-		$this->config = $config;
85
-		$this->activityManager = $activityManager;
86
-		$this->logger = $logger;
87
-		$this->tokenProvider = $tokenProvider;
88
-		$this->timeFactory = $timeFactory;
89
-		$this->dispatcher = $eventDispatcher;
90
-		$this->providerRegistry = $providerRegistry;
91
-	}
92
-
93
-	/**
94
-	 * Determine whether the user must provide a second factor challenge
95
-	 *
96
-	 * @param IUser $user
97
-	 * @return boolean
98
-	 */
99
-	public function isTwoFactorAuthenticated(IUser $user): bool {
100
-		$twoFactorEnabled = ((int) $this->config->getUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 0)) === 0;
101
-
102
-		if (!$twoFactorEnabled) {
103
-			return false;
104
-		}
105
-
106
-		$providerStates = $this->providerRegistry->getProviderStates($user);
107
-		$enabled = array_filter($providerStates);
108
-
109
-		return $twoFactorEnabled && !empty($enabled);
110
-	}
111
-
112
-	/**
113
-	 * Disable 2FA checks for the given user
114
-	 *
115
-	 * @param IUser $user
116
-	 */
117
-	public function disableTwoFactorAuthentication(IUser $user) {
118
-		$this->config->setUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 1);
119
-	}
120
-
121
-	/**
122
-	 * Enable all 2FA checks for the given user
123
-	 *
124
-	 * @param IUser $user
125
-	 */
126
-	public function enableTwoFactorAuthentication(IUser $user) {
127
-		$this->config->deleteUserValue($user->getUID(), 'core', 'two_factor_auth_disabled');
128
-	}
129
-
130
-	/**
131
-	 * Get a 2FA provider by its ID
132
-	 *
133
-	 * @param IUser $user
134
-	 * @param string $challengeProviderId
135
-	 * @return IProvider|null
136
-	 */
137
-	public function getProvider(IUser $user, string $challengeProviderId) {
138
-		$providers = $this->getProviderSet($user)->getProviders();
139
-		return $providers[$challengeProviderId] ?? null;
140
-	}
141
-
142
-	/**
143
-	 * Check if the persistant mapping of enabled/disabled state of each available
144
-	 * provider is missing an entry and add it to the registry in that case.
145
-	 *
146
-	 * @todo remove in Nextcloud 17 as by then all providers should have been updated
147
-	 *
148
-	 * @param string[] $providerStates
149
-	 * @param IProvider[] $providers
150
-	 * @param IUser $user
151
-	 * @return string[] the updated $providerStates variable
152
-	 */
153
-	private function fixMissingProviderStates(array $providerStates,
154
-		array $providers, IUser $user): array {
155
-
156
-		foreach ($providers as $provider) {
157
-			if (isset($providerStates[$provider->getId()])) {
158
-				// All good
159
-				continue;
160
-			}
161
-
162
-			$enabled = $provider->isTwoFactorAuthEnabledForUser($user);
163
-			if ($enabled) {
164
-				$this->providerRegistry->enableProviderFor($provider, $user);
165
-			} else {
166
-				$this->providerRegistry->disableProviderFor($provider, $user);
167
-			}
168
-			$providerStates[$provider->getId()] = $enabled;
169
-		}
170
-
171
-		return $providerStates;
172
-	}
173
-
174
-	/**
175
-	 * @param array $states
176
-	 * @param IProvider $providers
177
-	 */
178
-	private function isProviderMissing(array $states, array $providers): bool {
179
-		$indexed = [];
180
-		foreach ($providers as $provider) {
181
-			$indexed[$provider->getId()] = $provider;
182
-		}
183
-
184
-		$missing = [];
185
-		foreach ($states as $providerId => $enabled) {
186
-			if (!$enabled) {
187
-				// Don't care
188
-				continue;
189
-			}
190
-
191
-			if (!isset($indexed[$providerId])) {
192
-				$missing[] = $providerId;
193
-				$this->logger->alert("two-factor auth provider '$providerId' failed to load",
194
-					[
195
-					'app' => 'core',
196
-				]);
197
-			}
198
-		}
199
-
200
-		if (!empty($missing)) {
201
-			// There was at least one provider missing
202
-			$this->logger->alert(count($missing) . " two-factor auth providers failed to load", ['app' => 'core']);
203
-
204
-			return true;
205
-		}
206
-
207
-		// If we reach this, there was not a single provider missing
208
-		return false;
209
-	}
210
-
211
-	/**
212
-	 * Get the list of 2FA providers for the given user
213
-	 *
214
-	 * @param IUser $user
215
-	 * @throws Exception
216
-	 */
217
-	public function getProviderSet(IUser $user): ProviderSet {
218
-		$providerStates = $this->providerRegistry->getProviderStates($user);
219
-		$providers = $this->providerLoader->getProviders($user);
220
-
221
-		$fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user);
222
-		$isProviderMissing = $this->isProviderMissing($fixedStates, $providers);
223
-
224
-		$enabled = array_filter($providers, function (IProvider $provider) use ($fixedStates) {
225
-			return $fixedStates[$provider->getId()];
226
-		});
227
-		return new ProviderSet($enabled, $isProviderMissing);
228
-	}
229
-
230
-	/**
231
-	 * Verify the given challenge
232
-	 *
233
-	 * @param string $providerId
234
-	 * @param IUser $user
235
-	 * @param string $challenge
236
-	 * @return boolean
237
-	 */
238
-	public function verifyChallenge(string $providerId, IUser $user, string $challenge): bool {
239
-		$provider = $this->getProvider($user, $providerId);
240
-		if ($provider === null) {
241
-			return false;
242
-		}
243
-
244
-		$passed = $provider->verifyChallenge($user, $challenge);
245
-		if ($passed) {
246
-			if ($this->session->get(self::REMEMBER_LOGIN) === true) {
247
-				// TODO: resolve cyclic dependency and use DI
248
-				\OC::$server->getUserSession()->createRememberMeToken($user);
249
-			}
250
-			$this->session->remove(self::SESSION_UID_KEY);
251
-			$this->session->remove(self::REMEMBER_LOGIN);
252
-			$this->session->set(self::SESSION_UID_DONE, $user->getUID());
253
-
254
-			// Clear token from db
255
-			$sessionId = $this->session->getId();
256
-			$token = $this->tokenProvider->getToken($sessionId);
257
-			$tokenId = $token->getId();
258
-			$this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId);
259
-
260
-			$dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
261
-			$this->dispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent);
262
-
263
-			$this->publishEvent($user, 'twofactor_success', [
264
-				'provider' => $provider->getDisplayName(),
265
-			]);
266
-		} else {
267
-			$dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
268
-			$this->dispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent);
269
-
270
-			$this->publishEvent($user, 'twofactor_failed', [
271
-				'provider' => $provider->getDisplayName(),
272
-			]);
273
-		}
274
-		return $passed;
275
-	}
276
-
277
-	/**
278
-	 * Push a 2fa event the user's activity stream
279
-	 *
280
-	 * @param IUser $user
281
-	 * @param string $event
282
-	 * @param array $params
283
-	 */
284
-	private function publishEvent(IUser $user, string $event, array $params) {
285
-		$activity = $this->activityManager->generateEvent();
286
-		$activity->setApp('core')
287
-			->setType('security')
288
-			->setAuthor($user->getUID())
289
-			->setAffectedUser($user->getUID())
290
-			->setSubject($event, $params);
291
-		try {
292
-			$this->activityManager->publish($activity);
293
-		} catch (BadMethodCallException $e) {
294
-			$this->logger->warning('could not publish activity', ['app' => 'core']);
295
-			$this->logger->logException($e, ['app' => 'core']);
296
-		}
297
-	}
298
-
299
-	/**
300
-	 * Check if the currently logged in user needs to pass 2FA
301
-	 *
302
-	 * @param IUser $user the currently logged in user
303
-	 * @return boolean
304
-	 */
305
-	public function needsSecondFactor(IUser $user = null): bool {
306
-		if ($user === null) {
307
-			return false;
308
-		}
309
-
310
-		// If we are authenticated using an app password skip all this
311
-		if ($this->session->exists('app_password')) {
312
-			return false;
313
-		}
314
-
315
-		// First check if the session tells us we should do 2FA (99% case)
316
-		if (!$this->session->exists(self::SESSION_UID_KEY)) {
317
-
318
-			// Check if the session tells us it is 2FA authenticated already
319
-			if ($this->session->exists(self::SESSION_UID_DONE) &&
320
-				$this->session->get(self::SESSION_UID_DONE) === $user->getUID()) {
321
-				return false;
322
-			}
323
-
324
-			/*
47
+    const SESSION_UID_KEY = 'two_factor_auth_uid';
48
+    const SESSION_UID_DONE = 'two_factor_auth_passed';
49
+    const REMEMBER_LOGIN = 'two_factor_remember_login';
50
+
51
+    /** @var ProviderLoader */
52
+    private $providerLoader;
53
+
54
+    /** @var IRegistry */
55
+    private $providerRegistry;
56
+
57
+    /** @var ISession */
58
+    private $session;
59
+
60
+    /** @var IConfig */
61
+    private $config;
62
+
63
+    /** @var IManager */
64
+    private $activityManager;
65
+
66
+    /** @var ILogger */
67
+    private $logger;
68
+
69
+    /** @var TokenProvider */
70
+    private $tokenProvider;
71
+
72
+    /** @var ITimeFactory */
73
+    private $timeFactory;
74
+
75
+    /** @var EventDispatcherInterface */
76
+    private $dispatcher;
77
+
78
+    public function __construct(ProviderLoader $providerLoader,
79
+        IRegistry $providerRegistry, ISession $session, IConfig $config,
80
+        IManager $activityManager, ILogger $logger, TokenProvider $tokenProvider,
81
+        ITimeFactory $timeFactory, EventDispatcherInterface $eventDispatcher) {
82
+        $this->providerLoader = $providerLoader;
83
+        $this->session = $session;
84
+        $this->config = $config;
85
+        $this->activityManager = $activityManager;
86
+        $this->logger = $logger;
87
+        $this->tokenProvider = $tokenProvider;
88
+        $this->timeFactory = $timeFactory;
89
+        $this->dispatcher = $eventDispatcher;
90
+        $this->providerRegistry = $providerRegistry;
91
+    }
92
+
93
+    /**
94
+     * Determine whether the user must provide a second factor challenge
95
+     *
96
+     * @param IUser $user
97
+     * @return boolean
98
+     */
99
+    public function isTwoFactorAuthenticated(IUser $user): bool {
100
+        $twoFactorEnabled = ((int) $this->config->getUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 0)) === 0;
101
+
102
+        if (!$twoFactorEnabled) {
103
+            return false;
104
+        }
105
+
106
+        $providerStates = $this->providerRegistry->getProviderStates($user);
107
+        $enabled = array_filter($providerStates);
108
+
109
+        return $twoFactorEnabled && !empty($enabled);
110
+    }
111
+
112
+    /**
113
+     * Disable 2FA checks for the given user
114
+     *
115
+     * @param IUser $user
116
+     */
117
+    public function disableTwoFactorAuthentication(IUser $user) {
118
+        $this->config->setUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 1);
119
+    }
120
+
121
+    /**
122
+     * Enable all 2FA checks for the given user
123
+     *
124
+     * @param IUser $user
125
+     */
126
+    public function enableTwoFactorAuthentication(IUser $user) {
127
+        $this->config->deleteUserValue($user->getUID(), 'core', 'two_factor_auth_disabled');
128
+    }
129
+
130
+    /**
131
+     * Get a 2FA provider by its ID
132
+     *
133
+     * @param IUser $user
134
+     * @param string $challengeProviderId
135
+     * @return IProvider|null
136
+     */
137
+    public function getProvider(IUser $user, string $challengeProviderId) {
138
+        $providers = $this->getProviderSet($user)->getProviders();
139
+        return $providers[$challengeProviderId] ?? null;
140
+    }
141
+
142
+    /**
143
+     * Check if the persistant mapping of enabled/disabled state of each available
144
+     * provider is missing an entry and add it to the registry in that case.
145
+     *
146
+     * @todo remove in Nextcloud 17 as by then all providers should have been updated
147
+     *
148
+     * @param string[] $providerStates
149
+     * @param IProvider[] $providers
150
+     * @param IUser $user
151
+     * @return string[] the updated $providerStates variable
152
+     */
153
+    private function fixMissingProviderStates(array $providerStates,
154
+        array $providers, IUser $user): array {
155
+
156
+        foreach ($providers as $provider) {
157
+            if (isset($providerStates[$provider->getId()])) {
158
+                // All good
159
+                continue;
160
+            }
161
+
162
+            $enabled = $provider->isTwoFactorAuthEnabledForUser($user);
163
+            if ($enabled) {
164
+                $this->providerRegistry->enableProviderFor($provider, $user);
165
+            } else {
166
+                $this->providerRegistry->disableProviderFor($provider, $user);
167
+            }
168
+            $providerStates[$provider->getId()] = $enabled;
169
+        }
170
+
171
+        return $providerStates;
172
+    }
173
+
174
+    /**
175
+     * @param array $states
176
+     * @param IProvider $providers
177
+     */
178
+    private function isProviderMissing(array $states, array $providers): bool {
179
+        $indexed = [];
180
+        foreach ($providers as $provider) {
181
+            $indexed[$provider->getId()] = $provider;
182
+        }
183
+
184
+        $missing = [];
185
+        foreach ($states as $providerId => $enabled) {
186
+            if (!$enabled) {
187
+                // Don't care
188
+                continue;
189
+            }
190
+
191
+            if (!isset($indexed[$providerId])) {
192
+                $missing[] = $providerId;
193
+                $this->logger->alert("two-factor auth provider '$providerId' failed to load",
194
+                    [
195
+                    'app' => 'core',
196
+                ]);
197
+            }
198
+        }
199
+
200
+        if (!empty($missing)) {
201
+            // There was at least one provider missing
202
+            $this->logger->alert(count($missing) . " two-factor auth providers failed to load", ['app' => 'core']);
203
+
204
+            return true;
205
+        }
206
+
207
+        // If we reach this, there was not a single provider missing
208
+        return false;
209
+    }
210
+
211
+    /**
212
+     * Get the list of 2FA providers for the given user
213
+     *
214
+     * @param IUser $user
215
+     * @throws Exception
216
+     */
217
+    public function getProviderSet(IUser $user): ProviderSet {
218
+        $providerStates = $this->providerRegistry->getProviderStates($user);
219
+        $providers = $this->providerLoader->getProviders($user);
220
+
221
+        $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user);
222
+        $isProviderMissing = $this->isProviderMissing($fixedStates, $providers);
223
+
224
+        $enabled = array_filter($providers, function (IProvider $provider) use ($fixedStates) {
225
+            return $fixedStates[$provider->getId()];
226
+        });
227
+        return new ProviderSet($enabled, $isProviderMissing);
228
+    }
229
+
230
+    /**
231
+     * Verify the given challenge
232
+     *
233
+     * @param string $providerId
234
+     * @param IUser $user
235
+     * @param string $challenge
236
+     * @return boolean
237
+     */
238
+    public function verifyChallenge(string $providerId, IUser $user, string $challenge): bool {
239
+        $provider = $this->getProvider($user, $providerId);
240
+        if ($provider === null) {
241
+            return false;
242
+        }
243
+
244
+        $passed = $provider->verifyChallenge($user, $challenge);
245
+        if ($passed) {
246
+            if ($this->session->get(self::REMEMBER_LOGIN) === true) {
247
+                // TODO: resolve cyclic dependency and use DI
248
+                \OC::$server->getUserSession()->createRememberMeToken($user);
249
+            }
250
+            $this->session->remove(self::SESSION_UID_KEY);
251
+            $this->session->remove(self::REMEMBER_LOGIN);
252
+            $this->session->set(self::SESSION_UID_DONE, $user->getUID());
253
+
254
+            // Clear token from db
255
+            $sessionId = $this->session->getId();
256
+            $token = $this->tokenProvider->getToken($sessionId);
257
+            $tokenId = $token->getId();
258
+            $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId);
259
+
260
+            $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
261
+            $this->dispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent);
262
+
263
+            $this->publishEvent($user, 'twofactor_success', [
264
+                'provider' => $provider->getDisplayName(),
265
+            ]);
266
+        } else {
267
+            $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
268
+            $this->dispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent);
269
+
270
+            $this->publishEvent($user, 'twofactor_failed', [
271
+                'provider' => $provider->getDisplayName(),
272
+            ]);
273
+        }
274
+        return $passed;
275
+    }
276
+
277
+    /**
278
+     * Push a 2fa event the user's activity stream
279
+     *
280
+     * @param IUser $user
281
+     * @param string $event
282
+     * @param array $params
283
+     */
284
+    private function publishEvent(IUser $user, string $event, array $params) {
285
+        $activity = $this->activityManager->generateEvent();
286
+        $activity->setApp('core')
287
+            ->setType('security')
288
+            ->setAuthor($user->getUID())
289
+            ->setAffectedUser($user->getUID())
290
+            ->setSubject($event, $params);
291
+        try {
292
+            $this->activityManager->publish($activity);
293
+        } catch (BadMethodCallException $e) {
294
+            $this->logger->warning('could not publish activity', ['app' => 'core']);
295
+            $this->logger->logException($e, ['app' => 'core']);
296
+        }
297
+    }
298
+
299
+    /**
300
+     * Check if the currently logged in user needs to pass 2FA
301
+     *
302
+     * @param IUser $user the currently logged in user
303
+     * @return boolean
304
+     */
305
+    public function needsSecondFactor(IUser $user = null): bool {
306
+        if ($user === null) {
307
+            return false;
308
+        }
309
+
310
+        // If we are authenticated using an app password skip all this
311
+        if ($this->session->exists('app_password')) {
312
+            return false;
313
+        }
314
+
315
+        // First check if the session tells us we should do 2FA (99% case)
316
+        if (!$this->session->exists(self::SESSION_UID_KEY)) {
317
+
318
+            // Check if the session tells us it is 2FA authenticated already
319
+            if ($this->session->exists(self::SESSION_UID_DONE) &&
320
+                $this->session->get(self::SESSION_UID_DONE) === $user->getUID()) {
321
+                return false;
322
+            }
323
+
324
+            /*
325 325
 			 * If the session is expired check if we are not logged in by a token
326 326
 			 * that still needs 2FA auth
327 327
 			 */
328
-			try {
329
-				$sessionId = $this->session->getId();
330
-				$token = $this->tokenProvider->getToken($sessionId);
331
-				$tokenId = $token->getId();
332
-				$tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa');
333
-
334
-				if (!\in_array($tokenId, $tokensNeeding2FA, true)) {
335
-					$this->session->set(self::SESSION_UID_DONE, $user->getUID());
336
-					return false;
337
-				}
338
-			} catch (InvalidTokenException $e) {
339
-			}
340
-		}
341
-
342
-		if (!$this->isTwoFactorAuthenticated($user)) {
343
-			// There is no second factor any more -> let the user pass
344
-			//   This prevents infinite redirect loops when a user is about
345
-			//   to solve the 2FA challenge, and the provider app is
346
-			//   disabled the same time
347
-			$this->session->remove(self::SESSION_UID_KEY);
348
-
349
-			$keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa');
350
-			foreach ($keys as $key) {
351
-				$this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key);
352
-			}
353
-			return false;
354
-		}
355
-
356
-		return true;
357
-	}
358
-
359
-	/**
360
-	 * Prepare the 2FA login
361
-	 *
362
-	 * @param IUser $user
363
-	 * @param boolean $rememberMe
364
-	 */
365
-	public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) {
366
-		$this->session->set(self::SESSION_UID_KEY, $user->getUID());
367
-		$this->session->set(self::REMEMBER_LOGIN, $rememberMe);
368
-
369
-		$id = $this->session->getId();
370
-		$token = $this->tokenProvider->getToken($id);
371
-		$this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime());
372
-	}
328
+            try {
329
+                $sessionId = $this->session->getId();
330
+                $token = $this->tokenProvider->getToken($sessionId);
331
+                $tokenId = $token->getId();
332
+                $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa');
333
+
334
+                if (!\in_array($tokenId, $tokensNeeding2FA, true)) {
335
+                    $this->session->set(self::SESSION_UID_DONE, $user->getUID());
336
+                    return false;
337
+                }
338
+            } catch (InvalidTokenException $e) {
339
+            }
340
+        }
341
+
342
+        if (!$this->isTwoFactorAuthenticated($user)) {
343
+            // There is no second factor any more -> let the user pass
344
+            //   This prevents infinite redirect loops when a user is about
345
+            //   to solve the 2FA challenge, and the provider app is
346
+            //   disabled the same time
347
+            $this->session->remove(self::SESSION_UID_KEY);
348
+
349
+            $keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa');
350
+            foreach ($keys as $key) {
351
+                $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key);
352
+            }
353
+            return false;
354
+        }
355
+
356
+        return true;
357
+    }
358
+
359
+    /**
360
+     * Prepare the 2FA login
361
+     *
362
+     * @param IUser $user
363
+     * @param boolean $rememberMe
364
+     */
365
+    public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) {
366
+        $this->session->set(self::SESSION_UID_KEY, $user->getUID());
367
+        $this->session->set(self::REMEMBER_LOGIN, $rememberMe);
368
+
369
+        $id = $this->session->getId();
370
+        $token = $this->tokenProvider->getToken($id);
371
+        $this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime());
372
+    }
373 373
 
374 374
 }
Please login to merge, or discard this patch.