mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
Conflicts: application/forms/Config/Resource/LdapResourceForm.php test/php/application/forms/Config/Authentication/LdapBackendFormTest.php
85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
namespace Icinga\Authentication\Backend;
|
|
|
|
use Icinga\Application\Config;
|
|
use Icinga\Authentication\UserBackend;
|
|
use Icinga\User;
|
|
|
|
/**
|
|
* Test login with external authentication mechanism, e.g. Apache
|
|
*/
|
|
class AutoLoginBackend extends UserBackend
|
|
{
|
|
/**
|
|
* Regexp expression to strip values from a username
|
|
*
|
|
* @var string
|
|
*/
|
|
private $stripUsernameRegexp;
|
|
|
|
/**
|
|
* Create new autologin backend
|
|
*
|
|
* @param Config $config
|
|
*/
|
|
public function __construct(Config $config)
|
|
{
|
|
$this->stripUsernameRegexp = $config->get('strip_username_regexp');
|
|
}
|
|
|
|
/**
|
|
* Count the available users
|
|
*
|
|
* Autologin backends will always return 1
|
|
*
|
|
* @return int
|
|
*/
|
|
public function count()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
/**
|
|
* Test whether the given user exists
|
|
*
|
|
* @param User $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasUser(User $user)
|
|
{
|
|
if (isset($_SERVER['REMOTE_USER'])) {
|
|
$username = $_SERVER['REMOTE_USER'];
|
|
$user->setRemoteUserInformation($username, 'REMOTE_USER');
|
|
if ($this->stripUsernameRegexp) {
|
|
$stripped = preg_replace($this->stripUsernameRegexp, '', $username);
|
|
if ($stripped !== false) {
|
|
// TODO(el): PHP issues a warning when PHP cannot compile the regular expression. Should we log an
|
|
// additional message in that case?
|
|
$username = $stripped;
|
|
}
|
|
}
|
|
$user->setUsername($username);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Authenticate
|
|
*
|
|
* @param User $user
|
|
* @param string $password
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authenticate(User $user, $password = null)
|
|
{
|
|
return $this->hasUser($user);
|
|
}
|
|
}
|