ExternalBackend: Don't throw an error if it's not possible to clean usernames

This commit is contained in:
Johannes Meyer 2016-11-16 12:04:46 +01:00
parent 0bd00ba3d0
commit 3a816ce0f7
1 changed files with 7 additions and 5 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Authentication\User; namespace Icinga\Authentication\User;
use Icinga\Application\Logger;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\User; use Icinga\User;
@ -105,12 +106,13 @@ class ExternalBackend implements UserBackendInterface
$user->setExternalUserInformation($username, $field); $user->setExternalUserInformation($username, $field);
if ($this->stripUsernameRegexp) { if ($this->stripUsernameRegexp) {
$stripped = preg_replace($this->stripUsernameRegexp, '', $username); $stripped = @preg_replace($this->stripUsernameRegexp, '', $username);
if ($stripped !== false) { if ($stripped === false) {
// TODO(el): PHP issues a warning when PHP cannot compile the regular expression. Should we log an Logger::error('Failed to strip external username. The configured regular expression is invalid.');
// additional message in that case? return false;
$username = $stripped;
} }
$username = $stripped;
} }
$user->setUsername($username); $user->setUsername($username);