From 3a816ce0f7a61d74f29a56b76ed1f9ade43516da Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 16 Nov 2016 12:04:46 +0100 Subject: [PATCH] ExternalBackend: Don't throw an error if it's not possible to clean usernames --- .../Icinga/Authentication/User/ExternalBackend.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Authentication/User/ExternalBackend.php b/library/Icinga/Authentication/User/ExternalBackend.php index 84f93e8b7..a6159818a 100644 --- a/library/Icinga/Authentication/User/ExternalBackend.php +++ b/library/Icinga/Authentication/User/ExternalBackend.php @@ -3,6 +3,7 @@ namespace Icinga\Authentication\User; +use Icinga\Application\Logger; use Icinga\Data\ConfigObject; use Icinga\User; @@ -105,12 +106,13 @@ class ExternalBackend implements UserBackendInterface $user->setExternalUserInformation($username, $field); 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; + $stripped = @preg_replace($this->stripUsernameRegexp, '', $username); + if ($stripped === false) { + Logger::error('Failed to strip external username. The configured regular expression is invalid.'); + return false; } + + $username = $stripped; } $user->setUsername($username);