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