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;
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);