2013-06-14 13:51:44 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-06-14 13:51:44 +02:00
|
|
|
|
|
|
|
# namespace Icinga\Application\Controllers;
|
|
|
|
|
2014-03-03 17:21:17 +01:00
|
|
|
use Icinga\Application\Config;
|
2014-12-29 14:30:47 +01:00
|
|
|
use Icinga\Application\Icinga;
|
2014-10-31 10:27:17 +01:00
|
|
|
use Icinga\Application\Logger;
|
2014-12-29 14:30:47 +01:00
|
|
|
use Icinga\Forms\Authentication\LoginForm;
|
2015-07-29 14:17:07 +02:00
|
|
|
use Icinga\Web\Controller;
|
2014-03-06 12:07:24 +01:00
|
|
|
use Icinga\Web\Url;
|
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
|
|
|
*/
|
2015-07-29 14:17:07 +02:00
|
|
|
class AuthenticationController extends Controller
|
2013-06-14 13:51:44 +02:00
|
|
|
{
|
|
|
|
/**
|
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()
|
|
|
|
{
|
2014-12-29 14:30:06 +01:00
|
|
|
$icinga = Icinga::app();
|
2015-07-29 14:17:07 +02:00
|
|
|
if (($requiresSetup = $icinga->requiresSetup()) && $icinga->setupTokenExists()) {
|
2014-11-18 13:13:02 +01:00
|
|
|
$this->redirectNow(Url::fromPath('setup'));
|
2014-09-10 14:48:33 +02:00
|
|
|
}
|
2015-07-29 14:17:07 +02:00
|
|
|
$form = new LoginForm();
|
|
|
|
if ($this->Auth()->isAuthenticated()) {
|
|
|
|
$this->redirectNow($form->getRedirectUrl());
|
2013-06-24 18:46:45 +02:00
|
|
|
}
|
2015-07-29 14:17:07 +02:00
|
|
|
if (! $requiresSetup) {
|
|
|
|
$form->handleRequest();
|
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
|
|
|
$this->view->title = $this->translate('Icinga Web 2 Login');
|
|
|
|
$this->view->requiresSetup = $requiresSetup;
|
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()
|
|
|
|
{
|
2014-06-22 20:08:55 +02:00
|
|
|
$auth = $this->Auth();
|
2014-10-01 08:13:17 +02:00
|
|
|
if (! $auth->isAuthenticated()) {
|
|
|
|
$this->redirectToLogin();
|
|
|
|
}
|
2015-07-29 15:44:32 +02: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 18:46:45 +02:00
|
|
|
$auth->removeAuthorization();
|
2015-07-29 15:44:32 +02:00
|
|
|
if ($isExternalUser) {
|
2015-07-29 14:17:07 +02:00
|
|
|
$this->getResponse()->setHttpResponseCode(401);
|
2014-02-26 17:36:20 +01:00
|
|
|
} else {
|
2014-10-01 08:13:17 +02:00
|
|
|
$this->redirectToLogin();
|
2014-02-26 17:36:20 +01:00
|
|
|
}
|
2013-06-14 13:51:44 +02:00
|
|
|
}
|
|
|
|
}
|