Acl: code cleanup, more comments

This commit is contained in:
Thomas Gelf 2017-01-13 18:59:04 +01:00
parent 1b71df732e
commit f6fca75eae
1 changed files with 46 additions and 10 deletions

View File

@ -3,14 +3,20 @@
namespace Icinga\Module\Director; namespace Icinga\Module\Director;
use Icinga\Authentication\Auth; use Icinga\Authentication\Auth;
use Icinga\Authentication\Role;
use Icinga\Exception\AuthenticationException; use Icinga\Exception\AuthenticationException;
class Acl class Acl
{ {
/** @var Auth */
protected $auth; protected $auth;
/** @var self */
private static $instance; private static $instance;
/**
* @return self
*/
public static function instance() public static function instance()
{ {
if (self::$instance === null) { if (self::$instance === null) {
@ -20,16 +26,47 @@ class Acl
return self::$instance; return self::$instance;
} }
/**
* Acl constructor
*
* @param Auth $auth
*/
public function __construct(Auth $auth) public function __construct(Auth $auth)
{ {
$this->auth = $auth; $this->auth = $auth;
} }
/**
* Whether the given permission is available
*
* @param $name
*
* @return bool
*/
public function hasPermission($name) public function hasPermission($name)
{ {
return $this->auth->hasPermission($name); return $this->auth->hasPermission($name);
} }
/**
* List all given roles
*
* @return array
*/
public function listRoleNames()
{
return array_map(
array($this, 'getNameForRole'),
$this->getUser()->getRoles()
);
}
/**
* Get our user object, throws auth error if not available
*
* @return \Icinga\User
* @throws AuthenticationException
*/
protected function getUser() protected function getUser()
{ {
if (null === ($user = $this->auth->getUser())) { if (null === ($user = $this->auth->getUser())) {
@ -39,15 +76,14 @@ class Acl
return $user; return $user;
} }
public function listRoleNames() /**
{ * Get the name for a given role
return array_map( *
array($this, 'getNameForRole'), * @param Role $role
$this->getUser()->getRoles() *
); * @return string
} */
protected function getNameForRole(Role $role)
protected function getNameForRole($role)
{ {
return $role->getName(); return $role->getName();
} }