From 2ac54d7c3e309ef44cdaa5e7490697fffda81e8f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 11 Apr 2016 14:01:36 +0200 Subject: [PATCH] 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 --- .../Authentication/User/ExternalBackend.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/library/Icinga/Authentication/User/ExternalBackend.php b/library/Icinga/Authentication/User/ExternalBackend.php index e2cb44716..616f2371e 100644 --- a/library/Icinga/Authentication/User/ExternalBackend.php +++ b/library/Icinga/Authentication/User/ExternalBackend.php @@ -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}