/** * Whether an authenticated user has a given permission * * @param string $permission Permission name * * @return bool True if the user owns the given permission, false if not or if not authenticated */ public function hasPermission($permission) { if (!$this->isAuthenticated()) { return false; } return $this->user->can($permission); }
public function testPermissions() { $user = new User('test'); $user->setPermissions(array('test', 'test/some/specific', 'test/more/*', 'test/wildcard-with-wildcard/*', 'test/even-more/specific-with-wildcard/*')); $this->assertTrue($user->can('test')); $this->assertTrue($user->can('test/some/specific')); $this->assertTrue($user->can('test/more/everything')); $this->assertTrue($user->can('test/wildcard-with-wildcard/*')); $this->assertTrue($user->can('test/wildcard-with-wildcard/sub/sub')); $this->assertTrue($user->can('test/even-more/*')); $this->assertFalse($user->can('not/test')); $this->assertFalse($user->can('test/some/not/so/specific')); $this->assertFalse($user->can('test/wildcard2/*')); }
/** * Instantiate front controller * * @return $this */ private function setupFrontController() { $this->frontController = Zend_Controller_Front::getInstance(); $this->frontController->setRequest($this->getRequest()); $this->frontController->setControllerDirectory($this->getApplicationDir('/controllers')); $displayExceptions = $this->config->get('global', 'show_stacktraces', true); if ($this->user !== null && $this->user->can('application/stacktraces')) { $displayExceptions = $this->user->getPreferences()->getValue('icingaweb', 'show_stacktraces', $displayExceptions); } $this->frontController->setParams(array('displayExceptions' => $displayExceptions)); return $this; }