lib: Add ExternalBackend::getRemoteUser()

If the user is authenticated via the web server, this method should be used to retrieve the user because
it supports both reading the user from the environment or from the $_SERVER variable as fallback.

refs #11391
This commit is contained in:
Eric Lippmann 2016-04-11 14:01:36 +02:00
parent c803ec64c5
commit 2ac54d7c3e
1 changed files with 19 additions and 0 deletions

View File

@ -52,6 +52,25 @@ class ExternalBackend implements UserBackendInterface
return $this;
}
/**
* Get the remote user from environment or $_SERVER, if any
*
* @param string $variable The name variable where to read the user from
*
* @return string|null
*/
public static function getRemoteUser($variable = 'REMOTE_USER')
{
$username = getenv($variable);
if ($username !== false) {
return $username;
}
if (array_key_exists($variable, $_SERVER)) {
return $_SERVER[$variable];
}
return null;
}
/**
* {@inheritdoc}