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