Do not override stored credentials when login in with SAML

When login in with SAML, the password from `$event->getPassword()` is `null`.

This PR makes sure that this `null` value won't be used to override the stored password even though it is different.

This PR also allow for the password and user to be updated even though they were not set before.

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2023-04-13 18:05:37 +02:00
parent b3f59aa4c1
commit fec8ad8441

View file

@ -59,12 +59,12 @@ class StorePasswordListener implements IEventListener {
$newCredentials = $storedCredentials;
$shouldUpdate = false;
if (isset($storedCredentials['password']) && $storedCredentials['password'] !== $event->getPassword()) {
if (($storedCredentials['password'] ?? null) !== $event->getPassword() && $event->getPassword() !== null) {
$shouldUpdate = true;
$newCredentials['password'] = $event->getPassword();
}
if (isset($storedCredentials['user']) && $event instanceof UserLoggedInEvent && $storedCredentials['user'] !== $event->getLoginName()) {
if ($event instanceof UserLoggedInEvent && ($storedCredentials['user'] ?? null) !== $event->getLoginName()) {
$shouldUpdate = true;
$newCredentials['user'] = $event->getLoginName();
}