summaryrefslogtreecommitdiffstats
path: root/lib/private/appframework/middleware
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-28 02:12:01 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-28 02:15:16 +0200
commit5e9ea2b3659eebf6d21c253771e477abe16496c9 (patch)
treeb5d93d0eaa553e129a7d64fc080e57a08e15468f /lib/private/appframework/middleware
parent4e2cdb2f8af807767a978a175ef5415cd3d651eb (diff)
downloadnextcloud-server-5e9ea2b3659eebf6d21c253771e477abe16496c9.tar.gz
nextcloud-server-5e9ea2b3659eebf6d21c253771e477abe16496c9.zip
fix 8757, get rid of service locator antipattern
Diffstat (limited to 'lib/private/appframework/middleware')
-rw-r--r--lib/private/appframework/middleware/security/securitymiddleware.php58
1 files changed, 35 insertions, 23 deletions
diff --git a/lib/private/appframework/middleware/security/securitymiddleware.php b/lib/private/appframework/middleware/security/securitymiddleware.php
index d7e398fe445..5b56210024d 100644
--- a/lib/private/appframework/middleware/security/securitymiddleware.php
+++ b/lib/private/appframework/middleware/security/securitymiddleware.php
@@ -30,8 +30,10 @@ use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\JSONResponse;
-use OCP\AppFramework\IAppContainer;
+use OCP\INavigationManager;
+use OCP\IURLGenerator;
use OCP\IRequest;
+use OCP\ILogger;
/**
@@ -42,31 +44,41 @@ use OCP\IRequest;
*/
class SecurityMiddleware extends Middleware {
- /**
- * @var \OCP\AppFramework\IAppContainer
- */
- private $app;
-
- /**
- * @var \OCP\IRequest
- */
+ private $navigationManager;
private $request;
-
- /**
- * @var OC\AppFramework\Utility\ControllerMethodReflector
- */
private $reflector;
+ private $appName;
+ private $urlGenerator;
+ private $logger;
+ private $isLoggedIn;
+ private $isAdminUser;
/**
- * @param IAppContainer $app
* @param IRequest $request
* @param ControllerMethodReflector $reflector
+ * @param INavigationManager $navigationManager
+ * @param IURLGenerator $urlGenerator
+ * @param ILogger $logger
+ * @param string $appName
+ * @param bool $isLoggedIn
+ * @param bool $isAdminUser
*/
- public function __construct(IAppContainer $app, IRequest $request,
- ControllerMethodReflector $reflector){
- $this->app = $app;
+ public function __construct(IRequest $request,
+ ControllerMethodReflector $reflector,
+ INavigationManager $navigationManager,
+ IURLGenerator $urlGenerator,
+ ILogger $logger,
+ $appName,
+ $isLoggedIn,
+ $isAdminUser){
+ $this->navigationManager = $navigationManager;
$this->request = $request;
$this->reflector = $reflector;
+ $this->appName = $appName;
+ $this->urlGenerator = $urlGenerator;
+ $this->logger = $logger;
+ $this->isLoggedIn = $isLoggedIn;
+ $this->isAdminUser = $isAdminUser;
}
@@ -82,17 +94,17 @@ class SecurityMiddleware extends Middleware {
// this will set the current navigation entry of the app, use this only
// for normal HTML requests and not for AJAX requests
- $this->app->getServer()->getNavigationManager()->setActiveEntry($this->app->getAppName());
+ $this->navigationManager->setActiveEntry($this->appName);
// security checks
$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
if(!$isPublicPage) {
- if(!$this->app->isLoggedIn()) {
+ if(!$this->isLoggedIn) {
throw new SecurityException('Current user is not logged in', Http::STATUS_UNAUTHORIZED);
}
if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
- if(!$this->app->isAdminUser()) {
+ if(!$this->isAdminUser) {
throw new SecurityException('Logged in user must be an admin', Http::STATUS_FORBIDDEN);
}
}
@@ -126,13 +138,13 @@ class SecurityMiddleware extends Middleware {
array('message' => $exception->getMessage()),
$exception->getCode()
);
- $this->app->log($exception->getMessage(), 'debug');
+ $this->logger->debug($exception->getMessage());
} else {
// TODO: replace with link to route
- $url = $this->app->getServer()->getURLGenerator()->getAbsoluteURL('index.php');
+ $url = $this->urlGenerator->getAbsoluteURL('index.php');
$response = new RedirectResponse($url);
- $this->app->log($exception->getMessage(), 'debug');
+ $this->logger->debug($exception->getMessage());
}
return $response;