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