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