From 6da3cb84038a658f9fccce17de38677b952407e5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 23 Jan 2015 09:36:05 +0100 Subject: [PATCH] lib: Reorder auth related functions in the ActionController --- .../Web/Controller/ActionController.php | 86 +++++++++++-------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index 64438fc1d..78fcaf7bf 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -5,7 +5,7 @@ namespace Icinga\Web\Controller; use Exception; -use Icinga\Authentication\Manager as AuthManager; +use Icinga\Authentication\Manager; use Icinga\Application\Benchmark; use Icinga\Application\Config; use Icinga\Exception\IcingaException; @@ -47,6 +47,11 @@ class ActionController extends Zend_Controller_Action private $xhrLayout = 'inline'; + /** + * Authentication manager + * + * @type \Icinga\Authentication\Manager|null + */ private $auth; protected $params; @@ -101,6 +106,49 @@ class ActionController extends Zend_Controller_Action { } + + /** + * Get the authentication manager + * + * @return Manager + */ + public function Auth() + { + if ($this->auth === null) { + $this->auth = Manager::getInstance(); + } + return $this->auth; + } + + /** + * Whether the current user has the given permission + * + * @param string $permission Name of the permission + * + * @return bool + */ + public function hasPermission($permission) + { + return $this->Auth()->hasPermission($permission); + } + + /** + * Throw an exception if user lacks the given permission + * + * @param string $name Permission name + * @throws Exception + */ + public function assertPermission($name) + { + if (! $this->Auth()->hasPermission($name)) { + // TODO: Shall this be an Auth Exception? Or a 404? + throw new IcingaException( + 'Auth error, no permission for "%s"', + $name + ); + } + } + public function Config($file = null) { if ($file === null) { @@ -110,14 +158,6 @@ class ActionController extends Zend_Controller_Action } } - public function Auth() - { - if ($this->auth === null) { - $this->auth = AuthManager::getInstance(); - } - return $this->auth; - } - public function Window() { if ($this->window === null) { @@ -173,34 +213,6 @@ class ActionController extends Zend_Controller_Action return $this->Auth()->getRestrictions($name); } - /** - * Whether the user currently authenticated has the given permission - * - * @param string $name Permission name - * @return bool - */ - public function hasPermission($name) - { - return $this->Auth()->hasPermission($name); - } - - /** - * Throws an exception if user lacks the given permission - * - * @param string $name Permission name - * @throws Exception - */ - public function assertPermission($name) - { - if (! $this->Auth()->hasPermission($name)) { - // TODO: Shall this be an Auth Exception? Or a 404? - throw new IcingaException( - 'Auth error, no permission for "%s"', - $name - ); - } - } - /** * Check whether the controller requires a login. That is when the controller requires authentication and the * user is currently not authenticated