mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
External authentication: respect REDIRECT_REMOTE_USER as well
refs #12164
This commit is contained in:
parent
3caffb0026
commit
29c221418b
@ -55,18 +55,20 @@ 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|null $variable The name variable where to read the user from
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public static function getRemoteUser($variable = 'REMOTE_USER')
|
public static function getRemoteUser($variable = 'REMOTE_USER')
|
||||||
{
|
{
|
||||||
$username = getenv($variable);
|
foreach (($variable === null ? array('REMOTE_USER', 'REDIRECT_REMOTE_USER') : array($variable)) as $variable) {
|
||||||
if ($username !== false) {
|
$username = getenv($variable);
|
||||||
return $username;
|
if ($username !== false) {
|
||||||
}
|
return $username;
|
||||||
if (array_key_exists($variable, $_SERVER)) {
|
}
|
||||||
return $_SERVER[$variable];
|
if (array_key_exists($variable, $_SERVER)) {
|
||||||
|
return $_SERVER[$variable];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -77,9 +79,9 @@ class ExternalBackend implements UserBackendInterface
|
|||||||
*/
|
*/
|
||||||
public function authenticate(User $user, $password = null)
|
public function authenticate(User $user, $password = null)
|
||||||
{
|
{
|
||||||
$username = static::getRemoteUser();
|
$username = static::getRemoteUser(null);
|
||||||
if ($username !== null) {
|
if ($username !== null) {
|
||||||
$user->setExternalUserInformation($username, 'REMOTE_USER');
|
$user->setExternalUserInformation($username, null);
|
||||||
|
|
||||||
if ($this->stripUsernameRegexp) {
|
if ($this->stripUsernameRegexp) {
|
||||||
$stripped = preg_replace($this->stripUsernameRegexp, '', $username);
|
$stripped = preg_replace($this->stripUsernameRegexp, '', $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');
|
$name = ExternalBackend::getRemoteUser(null);
|
||||||
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,7 +31,8 @@ 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'
|
||||||
|
&& ExternalBackend::getRemoteUser(null) === null) {
|
||||||
$this->info(
|
$this->info(
|
||||||
$this->translate(
|
$this->translate(
|
||||||
'You\'re currently not authenticated using any of the web server\'s authentication '
|
'You\'re currently not authenticated using any of the web server\'s authentication '
|
||||||
|
Loading…
x
Reference in New Issue
Block a user