/**
  * Apply a restriction on the given data view
  *
  * @param   string      $restriction    The name of restriction
  * @param   Filterable  $filterable     The filterable to restrict
  *
  * @return  Filterable  The filterable
  */
 protected static function applyRestriction($restriction, Filterable $filterable)
 {
     $restrictions = Filter::matchAny();
     foreach (Manager::getInstance()->getRestrictions($restriction) as $filter) {
         $restrictions->addFilter(Filter::fromQueryString($filter));
     }
     $filterable->applyFilter($restrictions);
     return $filterable;
 }
 /**
  * Accept menu items that are permitted to the user
  *
  * @return bool Whether the user has the required permission granted to display the menu item
  */
 public function accept()
 {
     $item = $this->current();
     /** @var Menu $item */
     if (($permission = $item->getPermission()) !== null) {
         $auth = Manager::getInstance();
         if (!$auth->isAuthenticated()) {
             // Don't accept menu item because user is not authenticated and the menu item requires a permission
             return false;
         }
         if (!$auth->getUser()->can($permission)) {
             return false;
         }
     }
     // Accept menu item if it does not require a permission
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Get the authentication manager
  *
  * @return Manager
  */
 public function Auth()
 {
     if ($this->auth === null) {
         $this->auth = Manager::getInstance();
     }
     return $this->auth;
 }
Ejemplo n.º 4
0
 /**
  * Check whether the controller requires a login. That is when the controller requires authentication and the
  * user is currently not authenticated
  *
  * @return  bool
  *
  * @see     requiresAuthentication
  */
 protected function requiresLogin()
 {
     if (!$this->requiresAuthentication) {
         return false;
     }
     return !AuthManager::getInstance()->isAuthenticated();
 }
Ejemplo n.º 5
0
 /**
  * Add Applications Main Menu Items
  */
 protected function addMainMenuItems()
 {
     $auth = Manager::getInstance();
     if ($auth->isAuthenticated()) {
         $this->add(t('Dashboard'), array('url' => 'dashboard', 'icon' => 'dashboard', 'priority' => 10));
         $section = $this->add(t('System'), array('icon' => 'services', 'priority' => 700, 'renderer' => 'ProblemMenuItemRenderer'));
         $section->add(t('About'), array('url' => 'about', 'priority' => 701));
         if (Logger::writesToFile()) {
             $section->add(t('Application Log'), array('url' => 'list/applicationlog', 'priority' => 710));
         }
         $section = $this->add(t('Configuration'), array('icon' => 'wrench', 'permission' => 'config/*', 'priority' => 800));
         $section->add(t('Application'), array('url' => 'config', 'permission' => 'config/application/*', 'priority' => 810));
         $section->add(t('Authentication'), array('url' => 'config/userbackend', 'permission' => 'config/authentication/*', 'priority' => 820));
         $section->add(t('Roles'), array('url' => 'role/list', 'permission' => 'config/authentication/roles/show', 'priority' => 830));
         $section->add(t('Users'), array('url' => 'user/list', 'permission' => 'config/authentication/users/show', 'priority' => 840));
         $section->add(t('Usergroups'), array('url' => 'group/list', 'permission' => 'config/authentication/groups/show', 'priority' => 850));
         $section->add(t('Modules'), array('url' => 'config/modules', 'permission' => 'config/modules', 'priority' => 890));
         $section = $this->add($auth->getUser()->getUsername(), array('icon' => 'user', 'priority' => 900));
         $section->add(t('Preferences'), array('url' => 'preference', 'priority' => 910));
         $section->add(t('Logout'), array('url' => 'authentication/logout', 'priority' => 990, 'renderer' => 'ForeignMenuItemRenderer'));
     }
 }
Ejemplo n.º 6
0
 /**
  * Create user object
  *
  * @return  self
  */
 private function setupUser()
 {
     $authenticationManager = AuthenticationManager::getInstance();
     if ($authenticationManager->isAuthenticated() === true) {
         $this->user = $authenticationManager->getUser();
     }
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Populate preferences
  *
  * @see Form::onRequest()
  */
 public function onRequest()
 {
     $auth = Manager::getInstance();
     $values = $auth->getUser()->getPreferences()->get('icingaweb');
     if (!isset($values['language'])) {
         $values['language'] = 'autodetect';
     }
     if (!isset($values['timezone'])) {
         $values['timezone'] = 'autodetect';
     }
     $this->populate($values);
 }
Ejemplo n.º 8
0
<?php

namespace Icinga\Web\View;

use Icinga\Authentication\Manager;
$this->addHelperFunction('auth', function () {
    return Manager::getInstance();
});
Ejemplo n.º 9
0
 /**
  * Create a new AlertBox
  *
  * @param boolean showUserMessages 	If the current user messages should be displayed
  *                                  in this AlertMessageBox. Defaults to false
  */
 public function __construct($showUserMessages = false)
 {
     if ($showUserMessages) {
         $this->user = AuthenticationManager::getInstance()->getUser();
     }
 }
Ejemplo n.º 10
0
 /**
  * Setup internationalization using gettext
  *
  * Uses the preferred user language or the browser suggested language or our default.
  *
  * @return  string                      Detected locale code
  *
  * @see     Translator::DEFAULT_LOCALE  For the the default locale code.
  */
 protected function detectLocale()
 {
     $auth = Manager::getInstance();
     if ($auth->isAuthenticated() && ($locale = $auth->getUser()->getPreferences()->getValue('icingaweb', 'language')) !== null) {
         return $locale;
     }
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         return Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']);
     }
     return Translator::DEFAULT_LOCALE;
 }
 /**
  * Send a message with the logging level Zend_Log::ERR to the current user and
  * commit the changes to the underlying session.
  *
  * @param $msg      The message content
  */
 protected function addErrorMessage($msg)
 {
     AuthenticationManager::getInstance()->getUser()->addMessage(new Message($msg, Zend_Log::ERR));
     Session::getSession()->write();
 }