ExternalBackend: make the variable a webserver assigns a username to configurable

refs #12164
This commit is contained in:
Alexander A. Klimov 2016-10-17 18:46:00 +02:00
parent 29c221418b
commit ce951295d3

View File

@ -11,6 +11,13 @@ use Icinga\User;
*/ */
class ExternalBackend implements UserBackendInterface class ExternalBackend implements UserBackendInterface
{ {
/**
* The configuration of this backend
*
* @var ConfigObject
*/
protected $config;
/** /**
* The name of this backend * The name of this backend
* *
@ -32,6 +39,7 @@ class ExternalBackend implements UserBackendInterface
*/ */
public function __construct(ConfigObject $config) public function __construct(ConfigObject $config)
{ {
$this->config = $config;
$this->stripUsernameRegexp = $config->get('strip_username_regexp'); $this->stripUsernameRegexp = $config->get('strip_username_regexp');
} }
@ -79,9 +87,10 @@ class ExternalBackend implements UserBackendInterface
*/ */
public function authenticate(User $user, $password = null) public function authenticate(User $user, $password = null)
{ {
$username = static::getRemoteUser(null); $usernameEnvvar = $this->config->username_envvar;
$username = static::getRemoteUser($usernameEnvvar);
if ($username !== null) { if ($username !== null) {
$user->setExternalUserInformation($username, null); $user->setExternalUserInformation($username, $usernameEnvvar);
if ($this->stripUsernameRegexp) { if ($this->stripUsernameRegexp) {
$stripped = preg_replace($this->stripUsernameRegexp, '', $username); $stripped = preg_replace($this->stripUsernameRegexp, '', $username);