diff --git a/core/lib/Thelia/Action/HttpException.php b/core/lib/Thelia/Action/HttpException.php
index ad1df93ab..5541023d7 100644
--- a/core/lib/Thelia/Action/HttpException.php
+++ b/core/lib/Thelia/Action/HttpException.php
@@ -30,6 +30,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Thelia\Core\Template\ParserInterface;
+use Thelia\Exception\AdminAccessDenied;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Template\TemplateHelper;
@@ -53,13 +54,36 @@ class HttpException extends BaseAction implements EventSubscriberInterface
public function checkHttpException(GetResponseForExceptionEvent $event)
{
- if ($event->getException() instanceof NotFoundHttpException) {
+ $exception = $event->getException();
+ if ($exception instanceof NotFoundHttpException) {
$this->display404($event);
}
- if ($event->getException() instanceof AccessDeniedHttpException) {
+ if ($exception instanceof AccessDeniedHttpException) {
$this->display403($event);
}
+
+ if ($exception instanceof AdminAccessDenied) {
+ $this->displayAdminGeneralError($event);
+ }
+ }
+
+ protected function displayAdminGeneralError(GetResponseForExceptionEvent $event)
+ {
+ // Define the template thant shoud be used
+ $this->parser->setTemplateDefinition(TemplateHelper::getInstance()->getActiveAdminTemplate());
+
+ $message = $event->getException()->getMessage();
+
+ $response = Response::create(
+ $this->parser->render('general_error.html',
+ array(
+ "error_message" => $message
+ )),
+ 403
+ ) ;
+
+ $event->setResponse($response);
}
protected function display404(GetResponseForExceptionEvent $event)
diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml
index f567d23d9..703dcb33b 100644
--- a/core/lib/Thelia/Config/Resources/routing/admin.xml
+++ b/core/lib/Thelia/Config/Resources/routing/admin.xml
@@ -7,6 +7,7 @@
Thelia\Controller\Admin\AdminController::indexAction
+ 1
@@ -24,6 +25,7 @@
Thelia\Controller\Admin\SessionController::showLoginAction
+ 1
@@ -34,6 +36,7 @@
Thelia\Controller\Admin\SessionController::checkLoginAction
+ 1
diff --git a/core/lib/Thelia/Core/Controller/ControllerResolver.php b/core/lib/Thelia/Core/Controller/ControllerResolver.php
index a9cd30feb..530e6865b 100644
--- a/core/lib/Thelia/Core/Controller/ControllerResolver.php
+++ b/core/lib/Thelia/Core/Controller/ControllerResolver.php
@@ -27,6 +27,9 @@ use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseController
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Thelia\Controller\Admin\BaseAdminController;
+use Thelia\Exception\AdminAccessDenied;
/**
* ControllerResolver that supports "a:b:c", "service:method" and class::method" notations in routes definition
@@ -90,6 +93,15 @@ class ControllerResolver extends BaseControllerResolver
$controller->setContainer($this->container);
}
+ //check if an admin is logged in
+ if ($controller instanceof BaseAdminController) {
+ $securityContext = $this->container->get('thelia.securityContext');
+ $request = $this->container->get('request');
+ if(false === $securityContext->hasAdminUser() && $request->attributes->get('not-logged') != 1) {
+ throw new AdminAccessDenied();
+ }
+ }
+
return array($controller, $method);
}
}
diff --git a/core/lib/Thelia/Exception/AdminAccessDenied.php b/core/lib/Thelia/Exception/AdminAccessDenied.php
new file mode 100644
index 000000000..4fe79a428
--- /dev/null
+++ b/core/lib/Thelia/Exception/AdminAccessDenied.php
@@ -0,0 +1,35 @@
+. */
+/* */
+/*************************************************************************************/
+
+namespace Thelia\Exception;
+
+
+/**
+ * Class AdminAccessDenied
+ * @package Thelia\Exception
+ * @author Manuel Raynaud
+ */
+class AdminAccessDenied extends \RuntimeException
+{
+
+}
\ No newline at end of file
diff --git a/templates/backOffice/default/general_error.html b/templates/backOffice/default/general_error.html
index eae6614c9..503cc4106 100644
--- a/templates/backOffice/default/general_error.html
+++ b/templates/backOffice/default/general_error.html
@@ -15,7 +15,7 @@
{block name="error-message"}{$error_message}
{/block}
- {intl l="Go to administration home"}
+ {intl l="Go to administration home"}