mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
commit
78be71bc92
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Authentication\User;
|
namespace Icinga\Authentication\User;
|
||||||
|
|
||||||
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\User;
|
use Icinga\User;
|
||||||
|
|
||||||
@ -11,6 +12,13 @@ use Icinga\User;
|
|||||||
*/
|
*/
|
||||||
class ExternalBackend implements UserBackendInterface
|
class ExternalBackend implements UserBackendInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Possible variables where to read the user from
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
public static $remoteUserEnvvars = array('REMOTE_USER', 'REDIRECT_REMOTE_USER');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this backend
|
* The name of this backend
|
||||||
*
|
*
|
||||||
@ -55,7 +63,7 @@ class ExternalBackend implements UserBackendInterface
|
|||||||
/**
|
/**
|
||||||
* Get the remote user from environment or $_SERVER, if any
|
* Get the remote user from environment or $_SERVER, if any
|
||||||
*
|
*
|
||||||
* @param string $variable The name variable where to read the user from
|
* @param string $variable The name of the variable where to read the user from
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
@ -65,29 +73,46 @@ class ExternalBackend implements UserBackendInterface
|
|||||||
if ($username !== false) {
|
if ($username !== false) {
|
||||||
return $username;
|
return $username;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($variable, $_SERVER)) {
|
if (array_key_exists($variable, $_SERVER)) {
|
||||||
return $_SERVER[$variable];
|
return $_SERVER[$variable];
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the remote user information from environment or $_SERVER, if any
|
||||||
|
*
|
||||||
|
* @return array Contains always two entries, the username and origin which may both set to null.
|
||||||
|
*/
|
||||||
|
public static function getRemoteUserInformation()
|
||||||
|
{
|
||||||
|
foreach (static::$remoteUserEnvvars as $envVar) {
|
||||||
|
$username = static::getRemoteUser($envVar);
|
||||||
|
if ($username !== null) {
|
||||||
|
return array($username, $envVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function authenticate(User $user, $password = null)
|
public function authenticate(User $user, $password = null)
|
||||||
{
|
{
|
||||||
$username = static::getRemoteUser();
|
list($username, $field) = static::getRemoteUserInformation();
|
||||||
if ($username !== null) {
|
if ($username !== null) {
|
||||||
$user->setExternalUserInformation($username, 'REMOTE_USER');
|
$user->setExternalUserInformation($username, $field);
|
||||||
|
|
||||||
if ($this->stripUsernameRegexp) {
|
if ($this->stripUsernameRegexp) {
|
||||||
$stripped = preg_replace($this->stripUsernameRegexp, '', $username);
|
$stripped = @preg_replace($this->stripUsernameRegexp, '', $username);
|
||||||
if ($stripped !== null) {
|
if ($stripped === false) {
|
||||||
// TODO(el): PHP issues a warning when PHP cannot compile the regular expression. Should we log an
|
Logger::error('Failed to strip external username. The configured regular expression is invalid.');
|
||||||
// additional message in that case?
|
return false;
|
||||||
$username = $stripped;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$username = $stripped;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->setUsername($username);
|
$user->setUsername($username);
|
||||||
|
@ -5,6 +5,7 @@ namespace Icinga\Module\Setup\Forms;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Authentication\User\ExternalBackend;
|
||||||
use Icinga\Authentication\User\UserBackend;
|
use Icinga\Authentication\User\UserBackend;
|
||||||
use Icinga\Authentication\User\DbUserBackend;
|
use Icinga\Authentication\User\DbUserBackend;
|
||||||
use Icinga\Authentication\User\LdapUserBackend;
|
use Icinga\Authentication\User\LdapUserBackend;
|
||||||
@ -269,8 +270,8 @@ class AdminAccountPage extends Form
|
|||||||
*/
|
*/
|
||||||
protected function getUsername()
|
protected function getUsername()
|
||||||
{
|
{
|
||||||
$name = getenv('REMOTE_USER');
|
list($name, $_) = ExternalBackend::getRemoteUserInformation();
|
||||||
if ($name === false) {
|
if ($name === null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Setup\Forms;
|
namespace Icinga\Module\Setup\Forms;
|
||||||
|
|
||||||
|
use Icinga\Authentication\User\ExternalBackend;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Application\Platform;
|
use Icinga\Application\Platform;
|
||||||
|
|
||||||
@ -30,15 +31,18 @@ class AuthenticationPage extends Form
|
|||||||
*/
|
*/
|
||||||
public function createElements(array $formData)
|
public function createElements(array $formData)
|
||||||
{
|
{
|
||||||
if (isset($formData['type']) && $formData['type'] === 'external' && getenv('REMOTE_USER') === false) {
|
if (isset($formData['type']) && $formData['type'] === 'external') {
|
||||||
$this->info(
|
list($username, $_) = ExternalBackend::getRemoteUserInformation();
|
||||||
$this->translate(
|
if ($username === null) {
|
||||||
'You\'re currently not authenticated using any of the web server\'s authentication '
|
$this->info(
|
||||||
. 'mechanisms. Make sure you\'ll configure such, otherwise you\'ll not be able to '
|
$this->translate(
|
||||||
. 'log into Icinga Web 2.'
|
'You\'re currently not authenticated using any of the web server\'s authentication '
|
||||||
),
|
. 'mechanisms. Make sure you\'ll configure such, otherwise you\'ll not be able to '
|
||||||
false
|
. 'log into Icinga Web 2.'
|
||||||
);
|
),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$backendTypes = array();
|
$backendTypes = array();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user