2013-06-14 13:51:44 +02:00
|
|
|
<?php
|
|
|
|
// @codingStandardsIgnoreStart
|
|
|
|
// {{{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.
|
|
|
|
*
|
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
2013-06-28 16:47:30 +02:00
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
2013-08-16 14:56:23 +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-08-16 14:56:23 +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-08-16 14:56:23 +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-08-16 14:56:23 +02:00
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @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-14 13:51:44 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
# namespace Icinga\Application\Controllers;
|
|
|
|
|
2014-02-12 16:59:53 +01:00
|
|
|
use \Exception;
|
2014-01-23 16:03:47 +01:00
|
|
|
use Icinga\Web\Controller\ActionController;
|
|
|
|
use Icinga\Authentication\Credential;
|
|
|
|
use Icinga\Authentication\Manager as AuthManager;
|
|
|
|
use Icinga\Form\Authentication\LoginForm;
|
2013-07-12 16:10:56 +02:00
|
|
|
|
2013-06-14 13:51:44 +02:00
|
|
|
/**
|
2013-08-16 14:56:23 +02:00
|
|
|
* Application wide controller for authentication
|
2013-06-14 13:51:44 +02:00
|
|
|
*/
|
|
|
|
class AuthenticationController extends ActionController
|
|
|
|
{
|
|
|
|
/**
|
2014-01-23 16:03:47 +01:00
|
|
|
* This controller does not require authentication
|
2013-08-16 14:56:23 +02:00
|
|
|
*
|
2013-06-14 13:51:44 +02:00
|
|
|
* @var bool
|
|
|
|
*/
|
2013-08-30 15:50:49 +02:00
|
|
|
protected $requiresAuthentication = false;
|
2013-06-14 13:51:44 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-16 14:56:23 +02:00
|
|
|
* Log into the application
|
2013-06-14 13:51:44 +02:00
|
|
|
*/
|
|
|
|
public function loginAction()
|
|
|
|
{
|
2013-10-22 14:28:35 +02:00
|
|
|
$this->_helper->layout->setLayout('login');
|
2013-07-15 14:32:18 +02:00
|
|
|
$this->view->form = new LoginForm();
|
2013-07-12 16:10:56 +02:00
|
|
|
$this->view->form->setRequest($this->_request);
|
2014-01-23 16:03:47 +01:00
|
|
|
$this->view->title = 'Icinga Web Login';
|
2013-06-24 18:46:45 +02:00
|
|
|
try {
|
2014-01-23 16:03:47 +01:00
|
|
|
$redirectUrl = $this->_request->getParam('redirect', 'index?_render=body');
|
2013-11-20 12:01:40 +01:00
|
|
|
$auth = AuthManager::getInstance();
|
2013-06-24 18:46:45 +02:00
|
|
|
if ($auth->isAuthenticated()) {
|
2014-01-23 16:03:47 +01:00
|
|
|
$this->redirectNow($redirectUrl);
|
2013-06-24 18:46:45 +02:00
|
|
|
}
|
2013-08-02 16:35:16 +02:00
|
|
|
if ($this->view->form->isSubmittedAndValid()) {
|
2014-01-23 16:03:47 +01:00
|
|
|
$credentials = new Credential(
|
|
|
|
$this->view->form->getValue('username'),
|
|
|
|
$this->view->form->getValue('password')
|
|
|
|
);
|
2013-07-15 14:32:18 +02:00
|
|
|
if (!$auth->authenticate($credentials)) {
|
2013-08-16 14:56:23 +02:00
|
|
|
$this->view->form->getElement('password')
|
|
|
|
->addError(t('Please provide a valid username and password'));
|
2013-07-15 14:32:18 +02:00
|
|
|
} else {
|
2014-01-23 16:03:47 +01:00
|
|
|
$this->redirectNow($redirectUrl);
|
2013-06-24 18:46:45 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-12 13:57:17 +01:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->view->errorInfo = $e->getMessage();
|
2013-06-24 18:46:45 +02:00
|
|
|
}
|
2013-06-14 13:51:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-16 14:56:23 +02:00
|
|
|
* Log out the current user
|
2013-06-14 13:51:44 +02:00
|
|
|
*/
|
|
|
|
public function logoutAction()
|
|
|
|
{
|
2013-10-20 16:28:53 +02:00
|
|
|
$this->_helper->layout->setLayout('inline');
|
2013-11-20 12:01:40 +01:00
|
|
|
$auth = AuthManager::getInstance();
|
2013-06-24 18:46:45 +02:00
|
|
|
$auth->removeAuthorization();
|
2013-10-04 12:54:42 +02:00
|
|
|
$this->redirectToLogin();
|
2013-06-14 13:51:44 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-02 16:35:16 +02:00
|
|
|
// @codingStandardsIgnoreEnd
|