2013-08-17 05:16:48 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 11:07:57 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2015-03-26 06:44:34 -04:00
|
|
|
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2016-05-26 13:56:05 -04:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2016-07-21 11:07:57 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 06:44:34 -04:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 13:56:05 -04:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 06:44:34 -04:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-01-12 09:02:16 -05:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2016-07-21 11:07:57 -04:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Sebastian Wessalowski <sebastian@wessalowski.org>
|
2015-03-26 06:44:34 -04:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
|
* @author Thomas Tanghus <thomas@tanghus.net>
|
2013-08-17 05:16:48 -04:00
|
|
|
*
|
2015-03-26 06:44:34 -04:00
|
|
|
* @license AGPL-3.0
|
2013-08-17 05:16:48 -04:00
|
|
|
*
|
2015-03-26 06:44:34 -04:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
2013-08-17 05:16:48 -04:00
|
|
|
*
|
2015-03-26 06:44:34 -04:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2013-08-17 05:16:48 -04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 06:44:34 -04:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
2013-08-17 05:16:48 -04:00
|
|
|
*
|
2015-03-26 06:44:34 -04:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-08-17 05:16:48 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2015-02-26 05:37:37 -05:00
|
|
|
|
|
|
|
|
|
2013-08-17 05:16:48 -04:00
|
|
|
namespace OC\AppFramework\DependencyInjection;
|
|
|
|
|
|
2015-01-22 09:33:09 -05:00
|
|
|
use OC;
|
2013-10-22 23:57:34 -04:00
|
|
|
use OC\AppFramework\Http;
|
2013-08-17 05:16:48 -04:00
|
|
|
use OC\AppFramework\Http\Dispatcher;
|
2015-01-22 14:26:46 -05:00
|
|
|
use OC\AppFramework\Http\Output;
|
2013-08-17 05:16:48 -04:00
|
|
|
use OC\AppFramework\Middleware\MiddlewareDispatcher;
|
2014-05-08 05:47:18 -04:00
|
|
|
use OC\AppFramework\Middleware\Security\CORSMiddleware;
|
2016-07-20 03:43:02 -04:00
|
|
|
use OC\AppFramework\Middleware\OCSMiddleware;
|
2017-04-12 16:14:11 -04:00
|
|
|
use OC\AppFramework\Middleware\Security\RateLimitingMiddleware;
|
2016-05-11 05:23:25 -04:00
|
|
|
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
|
2014-10-21 08:53:10 -04:00
|
|
|
use OC\AppFramework\Middleware\SessionMiddleware;
|
2013-08-20 11:21:14 -04:00
|
|
|
use OC\AppFramework\Utility\SimpleContainer;
|
2018-04-26 06:19:15 -04:00
|
|
|
use OC\Collaboration\Collaborators\SearchResult;
|
2016-05-11 05:23:25 -04:00
|
|
|
use OC\Core\Middleware\TwoFactorMiddleware;
|
2016-10-12 06:08:42 -04:00
|
|
|
use OC\RichObjectStrings\Validator;
|
2017-03-19 18:14:47 -04:00
|
|
|
use OC\ServerContainer;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\AppFramework\Http\IOutput;
|
2013-08-20 19:02:15 -04:00
|
|
|
use OCP\AppFramework\IAppContainer;
|
2017-03-22 05:33:30 -04:00
|
|
|
use OCP\AppFramework\QueryException;
|
2018-01-02 15:13:32 -05:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2018-04-26 06:19:15 -04:00
|
|
|
use OCP\Collaboration\Collaborators\ISearchResult;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\Files\Folder;
|
2016-09-08 09:20:39 -04:00
|
|
|
use OCP\Files\IAppData;
|
2017-05-24 03:07:58 -04:00
|
|
|
use OCP\GlobalScale\IConfig;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\IL10N;
|
2018-04-25 09:22:28 -04:00
|
|
|
use OCP\ILogger;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\IRequest;
|
2017-03-19 17:20:56 -04:00
|
|
|
use OCP\IServerContainer;
|
2017-03-21 05:00:02 -04:00
|
|
|
use OCP\IUserSession;
|
2016-10-12 06:08:42 -04:00
|
|
|
use OCP\RichObjectStrings\IValidator;
|
2018-01-25 17:16:13 -05:00
|
|
|
use OCP\Encryption\IManager;
|
|
|
|
|
use OCA\WorkflowEngine\Manager;
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2014-12-13 13:28:20 -05:00
|
|
|
class DIContainer extends SimpleContainer implements IAppContainer {
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2013-09-27 11:15:26 -04:00
|
|
|
/**
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2013-09-28 14:40:25 -04:00
|
|
|
private $middleWares = array();
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2017-03-19 18:14:47 -04:00
|
|
|
/** @var ServerContainer */
|
2017-03-19 17:20:56 -04:00
|
|
|
private $server;
|
|
|
|
|
|
2013-08-17 05:16:48 -04:00
|
|
|
/**
|
|
|
|
|
* Put your class dependencies in here
|
|
|
|
|
* @param string $appName the name of the app
|
2017-03-19 17:20:56 -04:00
|
|
|
* @param array $urlParams
|
2017-07-24 05:36:20 -04:00
|
|
|
* @param ServerContainer|null $server
|
2013-08-17 05:16:48 -04:00
|
|
|
*/
|
2017-03-19 18:14:47 -04:00
|
|
|
public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
|
2015-07-24 07:43:50 -04:00
|
|
|
parent::__construct();
|
2013-08-17 05:16:48 -04:00
|
|
|
$this['AppName'] = $appName;
|
2013-10-01 13:01:52 -04:00
|
|
|
$this['urlParams'] = $urlParams;
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2015-12-18 05:43:39 -05:00
|
|
|
/** @var \OC\ServerContainer $server */
|
2017-03-19 17:20:56 -04:00
|
|
|
if ($server === null) {
|
2017-03-19 18:14:47 -04:00
|
|
|
$server = \OC::$server;
|
2017-03-19 17:20:56 -04:00
|
|
|
}
|
2017-03-19 18:14:47 -04:00
|
|
|
$this->server = $server;
|
2017-03-19 17:20:56 -04:00
|
|
|
$this->server->registerAppContainer($appName, $this);
|
2015-12-18 05:43:39 -05:00
|
|
|
|
2015-04-29 16:29:45 -04:00
|
|
|
// aliases
|
2015-07-17 11:18:37 -04:00
|
|
|
$this->registerAlias('appName', 'AppName');
|
|
|
|
|
$this->registerAlias('webRoot', 'WebRoot');
|
|
|
|
|
$this->registerAlias('userId', 'UserId');
|
2015-04-29 16:29:45 -04:00
|
|
|
|
2014-12-13 13:28:20 -05:00
|
|
|
/**
|
|
|
|
|
* Core services
|
|
|
|
|
*/
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerService(IOutput::class, function($c){
|
2015-10-06 09:24:19 -04:00
|
|
|
return new Output($this->getServer()->getWebRoot());
|
2015-01-22 14:26:46 -05:00
|
|
|
});
|
|
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerService(Folder::class, function() {
|
2016-05-09 04:02:07 -04:00
|
|
|
return $this->getServer()->getUserFolder();
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-08 09:20:39 -04:00
|
|
|
$this->registerService(IAppData::class, function (SimpleContainer $c) {
|
|
|
|
|
return $this->getServer()->getAppDataDir($c->query('AppName'));
|
|
|
|
|
});
|
|
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerService(IL10N::class, function($c) {
|
2015-01-22 09:33:09 -05:00
|
|
|
return $this->getServer()->getL10N($c->query('AppName'));
|
2014-12-13 13:28:20 -05:00
|
|
|
});
|
|
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
|
|
|
|
|
$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
|
2016-01-27 08:48:52 -05:00
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerService(IRequest::class, function() {
|
|
|
|
|
return $this->getServer()->query(IRequest::class);
|
2015-11-30 11:08:29 -05:00
|
|
|
});
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerAlias('Request', IRequest::class);
|
2015-11-30 11:08:29 -05:00
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
|
|
|
|
|
$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
|
2015-11-30 11:08:29 -05:00
|
|
|
|
2016-09-06 15:41:15 -04:00
|
|
|
$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
|
2014-12-13 13:28:20 -05:00
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerService(IServerContainer::class, function ($c) {
|
2015-01-22 09:33:09 -05:00
|
|
|
return $this->getServer();
|
2014-12-13 13:28:20 -05:00
|
|
|
});
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerAlias('ServerContainer', IServerContainer::class);
|
2014-12-13 13:28:20 -05:00
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
|
2018-01-25 17:16:13 -05:00
|
|
|
return $c->query(Manager::class);
|
2016-07-27 05:46:09 -04:00
|
|
|
});
|
|
|
|
|
|
2017-03-21 05:00:02 -04:00
|
|
|
$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
|
2015-10-20 04:32:53 -04:00
|
|
|
return $c;
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-26 06:19:15 -04:00
|
|
|
$this->registerAlias(ISearchResult::class, SearchResult::class);
|
|
|
|
|
|
2014-12-13 13:28:20 -05:00
|
|
|
// commonly used attributes
|
|
|
|
|
$this->registerService('UserId', function ($c) {
|
2018-01-25 17:16:13 -05:00
|
|
|
return $c->query(IUserSession::class)->getSession()->get('user_id');
|
2014-12-13 13:28:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$this->registerService('WebRoot', function ($c) {
|
|
|
|
|
return $c->query('ServerContainer')->getWebRoot();
|
|
|
|
|
});
|
|
|
|
|
|
2017-02-24 14:09:09 -05:00
|
|
|
$this->registerService('OC_Defaults', function ($c) {
|
|
|
|
|
return $c->getServer()->getThemingDefaults();
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-25 17:16:13 -05:00
|
|
|
$this->registerService(IManager::class, function ($c) {
|
2016-08-12 19:26:11 -04:00
|
|
|
return $this->getServer()->getEncryptionManager();
|
2016-08-11 09:50:31 -04:00
|
|
|
});
|
|
|
|
|
|
2017-05-24 03:07:58 -04:00
|
|
|
$this->registerService(IConfig::class, function ($c) {
|
|
|
|
|
return $c->query(OC\GlobalScale\Config::class);
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-12 06:08:42 -04:00
|
|
|
$this->registerService(IValidator::class, function($c) {
|
|
|
|
|
return $c->query(Validator::class);
|
|
|
|
|
});
|
|
|
|
|
|
2017-02-08 10:33:58 -05:00
|
|
|
$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
|
|
|
|
|
return new \OC\Security\IdentityProof\Manager(
|
2017-05-10 03:44:28 -04:00
|
|
|
$this->getServer()->query(\OC\Files\AppData\Factory::class),
|
2017-07-25 05:54:14 -04:00
|
|
|
$this->getServer()->getCrypto(),
|
|
|
|
|
$this->getServer()->getConfig()
|
2017-02-08 10:33:58 -05:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-03 07:10:03 -05:00
|
|
|
$this->registerService('Protocol', function($c){
|
2015-10-30 13:05:30 -04:00
|
|
|
/** @var \OC\Server $server */
|
|
|
|
|
$server = $c->query('ServerContainer');
|
|
|
|
|
$protocol = $server->getRequest()->getHttpProtocol();
|
|
|
|
|
return new Http($_SERVER, $protocol);
|
2013-08-17 05:16:48 -04:00
|
|
|
});
|
|
|
|
|
|
2014-11-03 07:10:03 -05:00
|
|
|
$this->registerService('Dispatcher', function($c) {
|
2014-05-06 10:29:19 -04:00
|
|
|
return new Dispatcher(
|
2014-05-27 20:12:01 -04:00
|
|
|
$c['Protocol'],
|
|
|
|
|
$c['MiddlewareDispatcher'],
|
2014-05-06 10:31:08 -04:00
|
|
|
$c['ControllerMethodReflector'],
|
|
|
|
|
$c['Request']
|
2014-05-06 10:29:19 -04:00
|
|
|
);
|
2013-08-17 05:16:48 -04:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 04:11:53 -04:00
|
|
|
/**
|
|
|
|
|
* App Framework default arguments
|
|
|
|
|
*/
|
|
|
|
|
$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
|
|
|
|
|
$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
|
|
|
|
|
$this->registerParameter('corsMaxAge', 1728000);
|
2013-08-17 05:16:48 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Middleware
|
|
|
|
|
*/
|
2013-10-22 03:29:17 -04:00
|
|
|
$app = $this;
|
2014-11-03 07:10:03 -05:00
|
|
|
$this->registerService('SecurityMiddleware', function($c) use ($app){
|
2017-01-17 05:51:10 -05:00
|
|
|
/** @var \OC\Server $server */
|
|
|
|
|
$server = $app->getServer();
|
|
|
|
|
|
2014-05-06 10:29:19 -04:00
|
|
|
return new SecurityMiddleware(
|
2014-05-27 20:12:01 -04:00
|
|
|
$c['Request'],
|
|
|
|
|
$c['ControllerMethodReflector'],
|
2017-01-17 05:51:10 -05:00
|
|
|
$server->getNavigationManager(),
|
|
|
|
|
$server->getURLGenerator(),
|
|
|
|
|
$server->getLogger(),
|
2014-05-27 20:12:01 -04:00
|
|
|
$c['AppName'],
|
2018-01-13 08:13:59 -05:00
|
|
|
$server->getUserSession()->isLoggedIn(),
|
|
|
|
|
$server->getGroupManager()->isAdmin($this->getUserId()),
|
2017-01-17 05:51:10 -05:00
|
|
|
$server->getContentSecurityPolicyManager(),
|
|
|
|
|
$server->getCsrfTokenManager(),
|
2017-10-23 17:40:17 -04:00
|
|
|
$server->getContentSecurityPolicyNonceManager(),
|
2018-02-26 09:32:17 -05:00
|
|
|
$server->getAppManager(),
|
|
|
|
|
$server->getL10N('lib')
|
2014-05-06 10:29:19 -04:00
|
|
|
);
|
2018-01-02 15:13:32 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function ($c) use ($app) {
|
|
|
|
|
/** @var \OC\Server $server */
|
|
|
|
|
$server = $app->getServer();
|
2017-01-17 05:51:10 -05:00
|
|
|
|
2018-01-02 15:13:32 -05:00
|
|
|
return new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware(
|
|
|
|
|
$c['ControllerMethodReflector'],
|
|
|
|
|
$server->getSession(),
|
|
|
|
|
$server->getUserSession(),
|
|
|
|
|
$server->query(ITimeFactory::class)
|
|
|
|
|
);
|
2013-08-17 05:16:48 -04:00
|
|
|
});
|
|
|
|
|
|
2017-04-13 16:50:44 -04:00
|
|
|
$this->registerService('BruteForceMiddleware', function($c) use ($app) {
|
|
|
|
|
/** @var \OC\Server $server */
|
|
|
|
|
$server = $app->getServer();
|
|
|
|
|
|
|
|
|
|
return new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
|
|
|
|
|
$c['ControllerMethodReflector'],
|
|
|
|
|
$server->getBruteForceThrottler(),
|
|
|
|
|
$server->getRequest()
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-04-12 16:14:11 -04:00
|
|
|
$this->registerService('RateLimitingMiddleware', function($c) use ($app) {
|
|
|
|
|
/** @var \OC\Server $server */
|
|
|
|
|
$server = $app->getServer();
|
|
|
|
|
|
|
|
|
|
return new RateLimitingMiddleware(
|
|
|
|
|
$server->getRequest(),
|
|
|
|
|
$server->getUserSession(),
|
|
|
|
|
$c['ControllerMethodReflector'],
|
|
|
|
|
$c->query(OC\Security\RateLimiting\Limiter::class)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-03 07:10:03 -05:00
|
|
|
$this->registerService('CORSMiddleware', function($c) {
|
2014-05-11 11:55:59 -04:00
|
|
|
return new CORSMiddleware(
|
|
|
|
|
$c['Request'],
|
2015-05-22 07:17:27 -04:00
|
|
|
$c['ControllerMethodReflector'],
|
2017-03-21 05:00:02 -04:00
|
|
|
$c->query(IUserSession::class),
|
2016-07-20 12:36:15 -04:00
|
|
|
$c->getServer()->getBruteForceThrottler()
|
2014-05-11 11:55:59 -04:00
|
|
|
);
|
2014-05-08 05:47:18 -04:00
|
|
|
});
|
|
|
|
|
|
2014-11-03 07:10:03 -05:00
|
|
|
$this->registerService('SessionMiddleware', function($c) use ($app) {
|
2014-10-21 08:53:10 -04:00
|
|
|
return new SessionMiddleware(
|
|
|
|
|
$c['Request'],
|
|
|
|
|
$c['ControllerMethodReflector'],
|
|
|
|
|
$app->getServer()->getSession()
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2016-05-11 05:23:25 -04:00
|
|
|
$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
|
|
|
|
|
$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
|
|
|
|
|
$userSession = $app->getServer()->getUserSession();
|
|
|
|
|
$session = $app->getServer()->getSession();
|
|
|
|
|
$urlGenerator = $app->getServer()->getURLGenerator();
|
|
|
|
|
$reflector = $c['ControllerMethodReflector'];
|
2016-06-01 07:54:08 -04:00
|
|
|
$request = $app->getServer()->getRequest();
|
|
|
|
|
return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
|
2016-05-11 05:23:25 -04:00
|
|
|
});
|
|
|
|
|
|
2016-07-20 03:43:02 -04:00
|
|
|
$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
|
|
|
|
|
return new OCSMiddleware(
|
|
|
|
|
$c['Request']
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2017-09-22 06:21:44 -04:00
|
|
|
$this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) {
|
|
|
|
|
return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
|
|
|
|
|
$c['Request'],
|
|
|
|
|
$c['ControllerMethodReflector']
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2014-04-11 14:50:49 -04:00
|
|
|
$middleWares = &$this->middleWares;
|
2014-11-03 07:10:03 -05:00
|
|
|
$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
|
2013-08-17 05:16:48 -04:00
|
|
|
$dispatcher = new MiddlewareDispatcher();
|
2017-09-22 06:21:44 -04:00
|
|
|
$dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]);
|
2014-05-08 05:47:18 -04:00
|
|
|
$dispatcher->registerMiddleware($c['CORSMiddleware']);
|
2016-08-12 09:15:24 -04:00
|
|
|
$dispatcher->registerMiddleware($c['OCSMiddleware']);
|
2015-05-22 07:17:27 -04:00
|
|
|
$dispatcher->registerMiddleware($c['SecurityMiddleware']);
|
2018-01-02 15:13:32 -05:00
|
|
|
$dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class]);
|
2017-04-13 16:50:44 -04:00
|
|
|
$dispatcher->registerMiddleware($c['TwoFactorMiddleware']);
|
|
|
|
|
$dispatcher->registerMiddleware($c['BruteForceMiddleware']);
|
2017-04-12 16:14:11 -04:00
|
|
|
$dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2014-04-11 14:50:49 -04:00
|
|
|
foreach($middleWares as $middleWare) {
|
2014-04-09 17:59:57 -04:00
|
|
|
$dispatcher->registerMiddleware($c[$middleWare]);
|
2013-09-27 11:15:26 -04:00
|
|
|
}
|
|
|
|
|
|
2014-10-21 08:53:10 -04:00
|
|
|
$dispatcher->registerMiddleware($c['SessionMiddleware']);
|
2013-08-17 05:16:48 -04:00
|
|
|
return $dispatcher;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-20 19:02:15 -04:00
|
|
|
/**
|
2013-08-31 15:34:29 -04:00
|
|
|
* @return \OCP\IServerContainer
|
2013-08-20 19:02:15 -04:00
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function getServer()
|
2013-08-20 19:02:15 -04:00
|
|
|
{
|
2017-03-19 17:20:56 -04:00
|
|
|
return $this->server;
|
2013-08-20 19:02:15 -04:00
|
|
|
}
|
2013-09-25 04:30:48 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-04-09 17:59:57 -04:00
|
|
|
* @param string $middleWare
|
2014-02-06 10:30:58 -05:00
|
|
|
* @return boolean|null
|
2013-09-25 04:30:48 -04:00
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function registerMiddleWare($middleWare) {
|
2018-01-25 16:36:03 -05:00
|
|
|
$this->middleWares[] = $middleWare;
|
2013-09-25 04:30:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* used to return the appname of the set application
|
|
|
|
|
* @return string the name of your application
|
|
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function getAppName() {
|
2013-09-25 04:30:48 -04:00
|
|
|
return $this->query('AppName');
|
|
|
|
|
}
|
2013-10-06 18:33:54 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-12-16 13:07:14 -05:00
|
|
|
* @deprecated use IUserSession->isLoggedIn()
|
2013-10-06 18:33:54 -04:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function isLoggedIn() {
|
2017-03-02 10:52:05 -05:00
|
|
|
return \OC::$server->getUserSession()->isLoggedIn();
|
2013-10-06 18:33:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-12-16 14:33:13 -05:00
|
|
|
* @deprecated use IGroupManager->isAdmin($userId)
|
2013-10-06 18:33:54 -04:00
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function isAdminUser() {
|
2013-10-06 18:33:54 -04:00
|
|
|
$uid = $this->getUserId();
|
|
|
|
|
return \OC_User::isAdminUser($uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getUserId() {
|
2015-01-22 09:33:09 -05:00
|
|
|
return $this->getServer()->getSession()->get('user_id');
|
2013-10-06 18:33:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-12-16 13:50:31 -05:00
|
|
|
* @deprecated use the ILogger instead
|
2014-05-11 16:51:30 -04:00
|
|
|
* @param string $message
|
|
|
|
|
* @param string $level
|
2013-10-06 18:33:54 -04:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2017-07-23 15:03:26 -04:00
|
|
|
public function log($message, $level) {
|
2013-10-06 18:33:54 -04:00
|
|
|
switch($level){
|
|
|
|
|
case 'debug':
|
2018-04-25 09:22:28 -04:00
|
|
|
$level = ILogger::DEBUG;
|
2013-10-06 18:33:54 -04:00
|
|
|
break;
|
|
|
|
|
case 'info':
|
2018-04-25 09:22:28 -04:00
|
|
|
$level = ILogger::INFO;
|
2013-10-06 18:33:54 -04:00
|
|
|
break;
|
|
|
|
|
case 'warn':
|
2018-04-25 09:22:28 -04:00
|
|
|
$level = ILogger::WARN;
|
2013-10-06 18:33:54 -04:00
|
|
|
break;
|
|
|
|
|
case 'fatal':
|
2018-04-25 09:22:28 -04:00
|
|
|
$level = ILogger::FATAL;
|
2013-10-06 18:33:54 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2018-04-25 09:22:28 -04:00
|
|
|
$level = ILogger::ERROR;
|
2013-10-06 18:33:54 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
\OCP\Util::writeLog($this->getAppName(), $message, $level);
|
|
|
|
|
}
|
2014-12-13 13:28:20 -05:00
|
|
|
|
2015-07-22 07:04:56 -04:00
|
|
|
/**
|
|
|
|
|
* Register a capability
|
|
|
|
|
*
|
|
|
|
|
* @param string $serviceName e.g. 'OCA\Files\Capabilities'
|
|
|
|
|
*/
|
|
|
|
|
public function registerCapability($serviceName) {
|
|
|
|
|
$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
|
|
|
|
|
return $this->query($serviceName);
|
|
|
|
|
});
|
2016-10-28 15:46:28 -04:00
|
|
|
}
|
2014-12-13 13:28:20 -05:00
|
|
|
|
2017-03-22 05:33:30 -04:00
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws QueryException if the query could not be resolved
|
|
|
|
|
*/
|
2017-03-19 17:09:47 -04:00
|
|
|
public function query($name) {
|
2017-03-22 05:33:30 -04:00
|
|
|
try {
|
|
|
|
|
return $this->queryNoFallback($name);
|
2017-09-12 05:54:13 -04:00
|
|
|
} catch (QueryException $firstException) {
|
|
|
|
|
try {
|
|
|
|
|
return $this->getServer()->query($name);
|
|
|
|
|
} catch (QueryException $secondException) {
|
|
|
|
|
if ($firstException->getCode() === 1) {
|
|
|
|
|
throw $secondException;
|
|
|
|
|
}
|
|
|
|
|
throw $firstException;
|
|
|
|
|
}
|
2017-03-22 05:33:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws QueryException if the query could not be resolved
|
|
|
|
|
*/
|
|
|
|
|
public function queryNoFallback($name) {
|
2017-03-17 09:25:35 -04:00
|
|
|
$name = $this->sanitizeName($name);
|
2017-03-19 17:09:47 -04:00
|
|
|
|
2017-03-19 18:14:47 -04:00
|
|
|
if ($this->offsetExists($name)) {
|
2017-03-17 09:25:35 -04:00
|
|
|
return parent::query($name);
|
2017-03-19 18:14:47 -04:00
|
|
|
} else {
|
2017-03-21 15:53:37 -04:00
|
|
|
if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
|
2017-03-20 05:16:56 -04:00
|
|
|
return parent::query($name);
|
2017-03-21 05:42:33 -04:00
|
|
|
} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
|
|
|
|
|
return parent::query($name);
|
2017-03-22 05:13:14 -04:00
|
|
|
} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
|
2017-03-21 15:53:37 -04:00
|
|
|
return parent::query($name);
|
2017-03-17 09:25:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 05:33:30 -04:00
|
|
|
throw new QueryException('Could not resolve ' . $name . '!' .
|
2017-09-12 05:54:13 -04:00
|
|
|
' Class can not be instantiated', 1);
|
2015-07-22 07:04:56 -04:00
|
|
|
}
|
2013-08-17 05:16:48 -04:00
|
|
|
}
|