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