2013-06-07 17:30:18 +02:00
|
|
|
<?php
|
2013-06-10 17:03:01 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-28 16:47:30 +02:00
|
|
|
/**
|
2013-10-23 15:10:33 +02:00
|
|
|
* This file is part of Icinga Web 2.
|
2013-09-04 18:27:16 +02:00
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
2014-01-23 12:09:48 +01:00
|
|
|
* Copyright (C) 2014 Icinga Development Team
|
2013-09-04 18:27:16 +02:00
|
|
|
*
|
2013-06-28 16:47:30 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2013-09-04 18:27:16 +02:00
|
|
|
*
|
2013-06-28 16:47:30 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2013-09-04 18:27:16 +02:00
|
|
|
*
|
2013-06-28 16:47:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2013-09-04 18:27:16 +02:00
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* @copyright 2014 Icinga Development Team <info@icinga.org>
|
2013-10-23 15:10:33 +02:00
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*
|
2013-06-28 16:47:30 +02:00
|
|
|
*/
|
2013-06-10 17:03:01 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-07 17:30:18 +02:00
|
|
|
|
|
|
|
namespace Icinga\Authentication;
|
|
|
|
|
2014-02-14 17:28:11 +01:00
|
|
|
use Exception;
|
|
|
|
use Zend_Config;
|
2014-01-23 12:09:48 +01:00
|
|
|
use Icinga\User;
|
|
|
|
use Icinga\Web\Session;
|
|
|
|
use Icinga\Data\ResourceFactory;
|
|
|
|
use Icinga\Application\Logger;
|
|
|
|
use Icinga\Exception\ConfigurationError;
|
|
|
|
use Icinga\Application\Config as IcingaConfig;
|
|
|
|
use Icinga\Authentication\Backend\DbUserBackend;
|
|
|
|
use Icinga\Authentication\Backend\LdapUserBackend;
|
2014-02-14 17:28:11 +01:00
|
|
|
use Icinga\User\Preferences;
|
|
|
|
use Icinga\User\Preferences\PreferencesStore;
|
|
|
|
use Icinga\Exception\NotReadableError;
|
2013-11-06 10:20:15 +01:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2014-01-23 12:09:48 +01:00
|
|
|
* The authentication manager allows to identify users and
|
|
|
|
* to persist authentication information in a session.
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* Direct instantiation is not permitted, the AuthenticationManager
|
|
|
|
* must be created using the getInstance method. Subsequent getInstance
|
|
|
|
* calls return the same object and ignore any additional configuration.
|
2013-08-13 18:08:21 +02:00
|
|
|
**/
|
2013-06-07 17:30:18 +02:00
|
|
|
class Manager
|
|
|
|
{
|
2013-08-28 10:16:18 +02:00
|
|
|
/**
|
|
|
|
* Singleton instance
|
|
|
|
*
|
|
|
|
* @var self
|
|
|
|
*/
|
2014-01-23 12:09:48 +01:00
|
|
|
private static $instance;
|
2013-06-10 13:28:54 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-08-28 10:16:18 +02:00
|
|
|
* Instance of authenticated user
|
|
|
|
*
|
2013-08-13 18:08:21 +02:00
|
|
|
* @var User
|
|
|
|
**/
|
2014-01-23 12:09:48 +01:00
|
|
|
private $user;
|
2013-07-12 15:37:36 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-08-28 10:16:18 +02:00
|
|
|
* Array of user backends
|
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* @var array
|
2013-08-13 18:08:21 +02:00
|
|
|
**/
|
2013-08-28 10:16:18 +02:00
|
|
|
private $userBackends = array();
|
2013-06-27 15:18:24 +02:00
|
|
|
|
2014-01-22 12:50:17 +01:00
|
|
|
/**
|
|
|
|
* The configuration
|
|
|
|
*
|
|
|
|
* @var Zend_Config
|
|
|
|
*/
|
|
|
|
private $config = null;
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-08-13 18:08:21 +02:00
|
|
|
* Creates a new authentication manager using the provided config (or the
|
2014-02-14 12:11:49 +01:00
|
|
|
* configuration provided in the authentication.ini if no config is given).
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2013-08-28 10:16:18 +02:00
|
|
|
* @param Zend_Config $config The configuration to use for authentication
|
|
|
|
* instead of the authentication.ini
|
2013-08-13 18:08:21 +02:00
|
|
|
**/
|
2014-02-14 12:11:49 +01:00
|
|
|
private function __construct(Zend_Config $config = null)
|
2013-06-07 17:30:18 +02:00
|
|
|
{
|
2014-02-14 12:11:49 +01:00
|
|
|
$this->config = $config === null ? IcingaConfig::app('authentication') : $config;
|
|
|
|
$this->setupBackends($this->config);
|
2013-06-07 17:30:18 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2014-02-14 12:11:49 +01:00
|
|
|
* Get the authentication manager
|
2013-08-28 10:16:18 +02:00
|
|
|
*
|
2014-02-14 12:11:49 +01:00
|
|
|
* @param Zend_Config $config
|
2013-08-28 10:16:18 +02:00
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
* @see Manager:__construct
|
|
|
|
*/
|
2014-02-14 12:11:49 +01:00
|
|
|
public static function getInstance(Zend_Config $config = null)
|
2013-06-07 17:30:18 +02:00
|
|
|
{
|
|
|
|
if (self::$instance === null) {
|
2014-02-14 12:11:49 +01:00
|
|
|
self::$instance = new static($config);
|
2013-06-07 17:30:18 +02:00
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-08-28 10:16:18 +02:00
|
|
|
* Initialize multiple backends from Zend Config
|
2013-08-13 18:08:21 +02:00
|
|
|
*/
|
2013-08-28 10:16:18 +02:00
|
|
|
private function setupBackends(Zend_Config $config)
|
2013-06-07 17:30:18 +02:00
|
|
|
{
|
2013-08-28 10:16:18 +02:00
|
|
|
foreach ($config as $name => $backendConfig) {
|
2014-02-18 09:33:33 +01:00
|
|
|
if ((bool) $backendConfig->get('disabled', false) === true) {
|
2013-10-22 16:47:04 +02:00
|
|
|
continue;
|
|
|
|
}
|
2013-08-28 10:16:18 +02:00
|
|
|
if ($backendConfig->name === null) {
|
|
|
|
$backendConfig->name = $name;
|
|
|
|
}
|
|
|
|
$backend = $this->createBackend($backendConfig);
|
2014-02-18 09:33:33 +01:00
|
|
|
$this->userBackends[$backend->getName()] = $backend;
|
2013-08-13 18:08:21 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-14 13:51:44 +02:00
|
|
|
|
2013-08-13 18:08:21 +02:00
|
|
|
/**
|
2014-02-18 09:33:33 +01:00
|
|
|
* Create a backend from the given Zend_Config
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2014-02-18 09:33:33 +01:00
|
|
|
* @param Zend_Config $backendConfig
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2014-02-18 09:33:33 +01:00
|
|
|
* @return UserBackend
|
|
|
|
* @throws ConfigurationError
|
2013-08-13 18:08:21 +02:00
|
|
|
*/
|
2013-08-28 10:16:18 +02:00
|
|
|
private function createBackend(Zend_Config $backendConfig)
|
2013-08-13 18:08:21 +02:00
|
|
|
{
|
2014-02-18 09:33:33 +01:00
|
|
|
if (isset($backendConfig->class)) {
|
|
|
|
// Use a custom backend class, this is only useful for testing
|
|
|
|
if (!class_exists($backendConfig->class)) {
|
|
|
|
throw new ConfigurationError(
|
|
|
|
'Authentication configuration for backend "' . $backendConfig->name . '" defines an invalid backend'
|
|
|
|
. ' class. Backend class "' . $backendConfig->class. '" not found'
|
|
|
|
);
|
2013-08-13 18:08:21 +02:00
|
|
|
}
|
2014-02-18 09:33:33 +01:00
|
|
|
return new $backendConfig->class($backendConfig);
|
|
|
|
}
|
|
|
|
if (($type = ResourceFactory::getResourceConfig($backendConfig->resource)->type) === null) {
|
|
|
|
throw new ConfigurationError(
|
|
|
|
'Authentication configuration for backend "%s" is missing the type directive',
|
|
|
|
$backendConfig->name,
|
|
|
|
$backendConfig->class
|
|
|
|
);
|
|
|
|
}
|
|
|
|
switch (strtolower($type)) {
|
|
|
|
case 'db':
|
|
|
|
return new DbUserBackend($backendConfig);
|
|
|
|
case 'ldap':
|
|
|
|
return new LdapUserBackend($backendConfig);
|
|
|
|
default:
|
|
|
|
throw new ConfigurationError(
|
|
|
|
'Authentication configuration for backend "' . $backendConfig->name. '" defines an invalid backend'
|
|
|
|
. ' type. Backend type "' . $type . '" is not supported'
|
|
|
|
);
|
2013-08-13 18:08:21 +02:00
|
|
|
}
|
2013-06-07 17:30:18 +02:00
|
|
|
}
|
|
|
|
|
2013-08-28 10:16:18 +02:00
|
|
|
/**
|
2014-01-23 12:09:48 +01:00
|
|
|
* Add a user backend to the stack
|
2013-08-28 10:16:18 +02:00
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* @param UserBackend $userBackend
|
2013-08-28 10:16:18 +02:00
|
|
|
*/
|
|
|
|
public function addUserBackend(UserBackend $userBackend)
|
|
|
|
{
|
2013-08-28 15:56:33 +02:00
|
|
|
$this->userBackends[$userBackend->getName()] = $userBackend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a user backend by name
|
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* @param string $name
|
2013-08-28 15:56:33 +02:00
|
|
|
*
|
|
|
|
* @return UserBackend|null
|
|
|
|
*/
|
|
|
|
public function getUserBackend($name)
|
|
|
|
{
|
2014-01-23 12:09:48 +01:00
|
|
|
return (isset($this->userBackends[$name])) ? $this->userBackends[$name] : null;
|
2013-08-28 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-18 09:33:33 +01:00
|
|
|
* Find the backend which provides the user with the given credentials
|
2013-08-28 10:16:18 +02:00
|
|
|
*
|
2014-02-18 09:33:33 +01:00
|
|
|
* @param Credential $credentials
|
2013-08-28 10:16:18 +02:00
|
|
|
*
|
|
|
|
* @return UserBackend|null
|
|
|
|
* @throws ConfigurationError
|
|
|
|
*/
|
2014-02-18 09:33:33 +01:00
|
|
|
private function revealBackend(Credential $credentials)
|
2013-08-28 10:16:18 +02:00
|
|
|
{
|
2014-02-18 09:33:33 +01:00
|
|
|
if (count($this->userBackends) === 0) {
|
|
|
|
throw new ConfigurationError(
|
|
|
|
'No authentication methods available. It seems that none authentication method has been set up. '
|
|
|
|
. ' Please contact your Icinga Web administrator'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$backendsWithError = 0;
|
|
|
|
// TODO(el): Currently the user is only notified about authentication backend problems when all backends
|
|
|
|
// have errors. It may be the case that the authentication backend which provides the user has errors but other
|
|
|
|
// authentication backends work. In that scenario the user is presented an error message saying "Incorrect
|
|
|
|
// username or password". We must inform the user that not all authentication methods are available.
|
|
|
|
foreach ($this->userBackends as $backend) {
|
|
|
|
Logger::debug(
|
|
|
|
'Asking authentication backend "%s" for user "%s"',
|
|
|
|
$backend->getName(),
|
|
|
|
$credentials->getUsername()
|
|
|
|
);
|
2013-08-28 10:16:18 +02:00
|
|
|
try {
|
2014-02-18 09:33:33 +01:00
|
|
|
$hasUser = $backend->hasUsername($credentials);
|
2013-08-28 10:16:18 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
Logger::error(
|
2014-02-18 09:33:33 +01:00
|
|
|
'Cannot ask authentication backend "%s" for user "%s". An exception was thrown: %s',
|
|
|
|
$backend->getName(),
|
|
|
|
$credentials->getUsername(),
|
2013-08-28 10:16:18 +02:00
|
|
|
$e->getMessage()
|
|
|
|
);
|
2014-02-18 09:33:33 +01:00
|
|
|
++$backendsWithError;
|
2013-08-28 10:16:18 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-02-18 09:33:33 +01:00
|
|
|
if ($hasUser === true) {
|
|
|
|
Logger::debug(
|
|
|
|
'Authentication backend "%s" provides user "%s"',
|
|
|
|
$backend->getName(),
|
|
|
|
$credentials->getUsername()
|
|
|
|
);
|
|
|
|
return $backend;
|
|
|
|
} else {
|
2013-08-28 10:16:18 +02:00
|
|
|
Logger::debug(
|
2014-02-18 09:33:33 +01:00
|
|
|
'Authentication backend "%s" does not provide user "%s"',
|
|
|
|
$backend->getName(),
|
2013-08-28 10:16:18 +02:00
|
|
|
$credentials->getUsername()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 09:33:33 +01:00
|
|
|
if ($backendsWithError === count($this->userBackends)) {
|
2013-08-28 10:16:18 +02:00
|
|
|
throw new ConfigurationError(
|
2014-02-18 09:33:33 +01:00
|
|
|
'No authentication methods available. It seems that all set up authentication methods have errors. '
|
|
|
|
. ' Please contact your Icinga Web administrator'
|
2013-08-28 10:16:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2014-01-23 12:09:48 +01:00
|
|
|
* Try to authenticate a user with the given credentials
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* @param Credential $credentials The credentials to use for authentication
|
|
|
|
* @param Boolean $persist Whether to persist the authentication result in the current session
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* @return Boolean Whether the authentication was successful or not
|
|
|
|
* @throws ConfigurationError
|
2013-08-26 10:08:32 +02:00
|
|
|
*/
|
2013-08-30 10:24:05 +02:00
|
|
|
public function authenticate(Credential $credentials, $persist = true)
|
2013-06-07 17:30:18 +02:00
|
|
|
{
|
2014-02-18 09:33:33 +01:00
|
|
|
$userBackend = $this->revealBackend($credentials);
|
2013-08-28 10:16:18 +02:00
|
|
|
if ($userBackend === null) {
|
2014-02-18 09:33:33 +01:00
|
|
|
Logger::info('Unknown user "%s" tried to log in', $credentials->getUsername());
|
2013-06-07 17:30:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-18 09:33:33 +01:00
|
|
|
if (($user = $userBackend->authenticate($credentials)) === null) {
|
|
|
|
Logger::info('User "%s" tried to log in with an incorrect password', $credentials->getUsername());
|
2013-06-07 17:30:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-06-27 13:04:47 +02:00
|
|
|
|
2014-02-12 17:01:11 +01:00
|
|
|
$username = $credentials->getUsername();
|
|
|
|
|
|
|
|
$membership = new Membership();
|
|
|
|
|
|
|
|
$groups = $membership->getGroupsByUsername($username);
|
2014-02-18 09:33:33 +01:00
|
|
|
$user->setGroups($groups);
|
2014-02-12 17:01:11 +01:00
|
|
|
|
|
|
|
$admissionLoader = new AdmissionLoader();
|
|
|
|
|
2014-02-18 09:33:33 +01:00
|
|
|
$user->setPermissions(
|
2014-02-12 17:01:11 +01:00
|
|
|
$admissionLoader->getPermissions($username, $groups)
|
|
|
|
);
|
|
|
|
|
2014-02-18 09:33:33 +01:00
|
|
|
$user->setRestrictions(
|
2014-02-12 17:01:11 +01:00
|
|
|
$admissionLoader->getRestrictions($username, $groups)
|
|
|
|
);
|
2014-01-22 14:06:59 +01:00
|
|
|
|
2014-02-14 17:28:11 +01:00
|
|
|
if (($preferencesConfig = IcingaConfig::app()->preferences) !== null) {
|
|
|
|
try {
|
|
|
|
$preferencesStore = PreferencesStore::create(
|
|
|
|
$preferencesConfig,
|
2014-02-18 09:33:33 +01:00
|
|
|
$user
|
2014-02-14 17:28:11 +01:00
|
|
|
);
|
|
|
|
$preferences = new Preferences($preferencesStore->load());
|
|
|
|
} catch (NotReadableError $e) {
|
|
|
|
Logger::error($e);
|
|
|
|
$preferences = new Preferences();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$preferences = new Preferences();
|
|
|
|
}
|
2014-02-18 09:33:33 +01:00
|
|
|
$user->setPreferences($preferences);
|
|
|
|
$this->user = $user;
|
2013-06-10 13:28:54 +02:00
|
|
|
if ($persist == true) {
|
|
|
|
$this->persistCurrentUser();
|
|
|
|
}
|
2013-08-28 10:16:18 +02:00
|
|
|
|
2014-02-18 14:46:15 +01:00
|
|
|
Logger::info('User "%s" logged in', $credentials->getUsername());
|
2013-08-28 10:16:18 +02:00
|
|
|
|
2013-06-07 17:30:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2014-01-23 12:09:48 +01:00
|
|
|
* Writes the current user to the session
|
2013-08-13 18:08:21 +02:00
|
|
|
**/
|
2013-06-07 17:30:18 +02:00
|
|
|
public function persistCurrentUser()
|
|
|
|
{
|
2014-01-23 12:09:48 +01:00
|
|
|
$session = Session::getSession();
|
|
|
|
$session->set('user', $this->user);
|
|
|
|
$session->write();
|
2013-06-07 17:30:18 +02:00
|
|
|
}
|
2013-09-04 18:27:16 +02:00
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-08-13 18:08:21 +02:00
|
|
|
* Tries to authenticate the user with the current session
|
|
|
|
**/
|
2013-06-07 17:30:18 +02:00
|
|
|
public function authenticateFromSession()
|
|
|
|
{
|
2014-01-23 12:09:48 +01:00
|
|
|
$this->user = Session::getSession()->get('user');
|
2013-06-07 17:30:18 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-08-13 18:08:21 +02:00
|
|
|
* Returns true when the user is currently authenticated
|
|
|
|
*
|
2014-01-23 12:09:48 +01:00
|
|
|
* @param Boolean $ignoreSession Set to true to prevent authentication by session
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2013-08-28 10:16:18 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
2013-06-10 13:28:54 +02:00
|
|
|
public function isAuthenticated($ignoreSession = false)
|
2013-06-07 17:30:18 +02:00
|
|
|
{
|
2013-06-10 13:28:54 +02:00
|
|
|
if ($this->user === null && !$ignoreSession) {
|
2013-06-07 17:30:18 +02:00
|
|
|
$this->authenticateFromSession();
|
|
|
|
}
|
2013-06-10 13:28:54 +02:00
|
|
|
return is_object($this->user);
|
2013-06-07 17:30:18 +02:00
|
|
|
}
|
|
|
|
|
2014-01-22 14:06:59 +01:00
|
|
|
/**
|
|
|
|
* Whether an authenticated user has a given permission
|
|
|
|
*
|
|
|
|
* This is true if the user owns this permission, false if not.
|
|
|
|
* Also false if there is no authenticated user
|
|
|
|
*
|
|
|
|
* TODO: I'd like to see wildcard support, e.g. module/*
|
|
|
|
*
|
|
|
|
* @param string $permission Permission name
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasPermission($permission)
|
|
|
|
{
|
|
|
|
if (! $this->isAuthenticated()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach ($this->user->getPermissions() as $p) {
|
|
|
|
if ($p === $permission) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get applied restrictions matching a given restriction name
|
|
|
|
*
|
|
|
|
* Returns a list of applied restrictions, empty if no user is
|
|
|
|
* authenticated
|
|
|
|
*
|
|
|
|
* @param string $restriction Restriction name
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getRestrictions($restriction)
|
|
|
|
{
|
|
|
|
if (! $this->isAuthenticated()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
return $this->user->getRestrictions($restriction);
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2014-01-23 12:09:48 +01:00
|
|
|
* Purges the current authorization information and removes the user from the session
|
2013-08-13 18:08:21 +02:00
|
|
|
**/
|
2013-06-07 17:30:18 +02:00
|
|
|
public function removeAuthorization()
|
|
|
|
{
|
|
|
|
$this->user = null;
|
2014-01-23 12:09:48 +01:00
|
|
|
$this->persistCurrentUser();
|
2013-06-07 17:30:18 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2013-11-20 19:10:38 +01:00
|
|
|
* Returns the current user or null if no user is authenticated
|
2013-08-13 18:08:21 +02:00
|
|
|
*
|
2013-11-20 19:10:38 +01:00
|
|
|
* @return User
|
2013-08-13 18:08:21 +02:00
|
|
|
**/
|
2013-06-07 17:30:18 +02:00
|
|
|
public function getUser()
|
|
|
|
{
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:18:24 +02:00
|
|
|
/**
|
2014-01-23 12:09:48 +01:00
|
|
|
* Getter for groups belonged to authenticated user
|
2013-08-28 10:16:18 +02:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @see User::getGroups
|
2013-08-13 18:08:21 +02:00
|
|
|
**/
|
2013-06-07 17:30:18 +02:00
|
|
|
public function getGroups()
|
|
|
|
{
|
|
|
|
return $this->user->getGroups();
|
|
|
|
}
|
|
|
|
}
|