2013-06-14 07:51:44 -04:00
|
|
|
<?php
|
2015-02-04 04:46:36 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-06-14 07:51:44 -04:00
|
|
|
|
2015-08-27 07:09:58 -04:00
|
|
|
namespace Icinga\Controllers;
|
2013-06-14 07:51:44 -04:00
|
|
|
|
2014-12-29 08:30:47 -05:00
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
|
use Icinga\Forms\Authentication\LoginForm;
|
2015-07-29 08:17:07 -04:00
|
|
|
use Icinga\Web\Controller;
|
2014-03-06 06:07:24 -05:00
|
|
|
use Icinga\Web\Url;
|
2013-07-12 10:10:56 -04:00
|
|
|
|
2013-06-14 07:51:44 -04:00
|
|
|
/**
|
2013-08-16 08:56:23 -04:00
|
|
|
* Application wide controller for authentication
|
2013-06-14 07:51:44 -04:00
|
|
|
*/
|
2015-07-29 08:17:07 -04:00
|
|
|
class AuthenticationController extends Controller
|
2013-06-14 07:51:44 -04:00
|
|
|
{
|
|
|
|
|
/**
|
2015-08-13 02:12:30 -04:00
|
|
|
* {@inheritdoc}
|
2013-06-14 07:51:44 -04:00
|
|
|
*/
|
2013-08-30 09:50:49 -04:00
|
|
|
protected $requiresAuthentication = false;
|
2013-06-14 07:51:44 -04:00
|
|
|
|
2015-08-13 02:12:30 -04:00
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
protected $innerLayout = 'inline';
|
|
|
|
|
|
2013-06-14 07:51:44 -04:00
|
|
|
/**
|
2013-08-16 08:56:23 -04:00
|
|
|
* Log into the application
|
2013-06-14 07:51:44 -04:00
|
|
|
*/
|
|
|
|
|
public function loginAction()
|
|
|
|
|
{
|
2014-12-29 08:30:06 -05:00
|
|
|
$icinga = Icinga::app();
|
2015-07-29 08:17:07 -04:00
|
|
|
if (($requiresSetup = $icinga->requiresSetup()) && $icinga->setupTokenExists()) {
|
2014-11-18 07:13:02 -05:00
|
|
|
$this->redirectNow(Url::fromPath('setup'));
|
2014-09-10 08:48:33 -04:00
|
|
|
}
|
2015-07-29 08:17:07 -04:00
|
|
|
$form = new LoginForm();
|
|
|
|
|
if ($this->Auth()->isAuthenticated()) {
|
|
|
|
|
$this->redirectNow($form->getRedirectUrl());
|
2013-06-24 12:46:45 -04:00
|
|
|
}
|
2015-07-29 08:17:07 -04:00
|
|
|
if (! $requiresSetup) {
|
2015-08-13 05:21:05 -04:00
|
|
|
if (! $this->getRequest()->hasCookieSupport()) {
|
2015-08-27 07:21:43 -04:00
|
|
|
$this
|
|
|
|
|
->getResponse()
|
|
|
|
|
->setBody("Cookies must be enabled to run this application.\n")
|
|
|
|
|
->setHttpResponseCode(403)
|
|
|
|
|
->sendResponse();
|
2015-08-13 05:21:05 -04:00
|
|
|
exit();
|
|
|
|
|
}
|
2015-07-29 08:17:07 -04:00
|
|
|
$form->handleRequest();
|
|
|
|
|
}
|
|
|
|
|
$this->view->form = $form;
|
|
|
|
|
$this->view->title = $this->translate('Icinga Web 2 Login');
|
|
|
|
|
$this->view->requiresSetup = $requiresSetup;
|
2013-06-14 07:51:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-08-16 08:56:23 -04:00
|
|
|
* Log out the current user
|
2013-06-14 07:51:44 -04:00
|
|
|
*/
|
|
|
|
|
public function logoutAction()
|
|
|
|
|
{
|
2014-06-22 14:08:55 -04:00
|
|
|
$auth = $this->Auth();
|
2014-10-01 02:13:17 -04:00
|
|
|
if (! $auth->isAuthenticated()) {
|
|
|
|
|
$this->redirectToLogin();
|
|
|
|
|
}
|
2015-07-29 09:44:32 -04:00
|
|
|
// Get info whether the user is externally authenticated before removing authorization which destroys the
|
|
|
|
|
// session and the user object
|
|
|
|
|
$isExternalUser = $auth->getUser()->isExternalUser();
|
2013-06-24 12:46:45 -04:00
|
|
|
$auth->removeAuthorization();
|
2015-07-29 09:44:32 -04:00
|
|
|
if ($isExternalUser) {
|
2015-07-29 08:17:07 -04:00
|
|
|
$this->getResponse()->setHttpResponseCode(401);
|
2014-02-26 11:36:20 -05:00
|
|
|
} else {
|
2014-10-01 02:13:17 -04:00
|
|
|
$this->redirectToLogin();
|
2014-02-26 11:36:20 -05:00
|
|
|
}
|
2013-06-14 07:51:44 -04:00
|
|
|
}
|
|
|
|
|
}
|