8000 minor #40217 [Security] Fix some broken BC layers (chalasr) · symfony/symfony@6ae59a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ae59a9

Browse files
committed
minor #40217 [Security] Fix some broken BC layers (chalasr)
This PR was merged into the 5.3-dev branch. Discussion ---------- [Security] Fix some broken BC layers | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | yes (5.x only) | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 79de1da [Security] Fix some broken BC layers
2 parents 4d91b8f + 79de1da commit 6ae59a9

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/Symfony/Component/Security/Core/Encoder/UserPasswordEncoderInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
namespace Symfony\Component\Security\Core\Encoder;
1313

14-
trigger_deprecation('symfony/security-core', '5.3', sprintf('The "%s" interface is deprecated, use "%s" on hasher implementations that deal with salts instead.', UserPasswordEncoderInterface::class, UserPasswordHasherInterface::class));
14+
trigger_deprecation('symfony/security-core', '5.3', sprintf('The "%s" interface is deprecated, use "%s" instead.', UserPasswordEncoderInterface::class, UserPasswordHasherInterface::class));
1515

16-
use Symfony\Component\Security\Core\User\UserInterface;
1716
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
17+
use Symfony\Component\Security\Core\User\UserInterface;
1818

1919
/**
2020
* UserPasswordEncoderInterface is the interface for the password encoder service.

src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Symfony\Component\Security\Guard\Provider;
1313

14+
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
1415
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
1516
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
16-
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
1717
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
1818
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1919
use Symfony\Component\Security\Core\Exception\AuthenticationExpiredException;
@@ -27,7 +27,6 @@
2727
use Symfony\Component\Security\Guard\PasswordAuthenticatedInterface;
2828
use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
2929
use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken;
30-
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
3130

3231
/**
3332
* Responsible for accepting the PreAuthenticationGuardToken and calling
@@ -130,8 +129,8 @@ private function authenticateViaGuard(AuthenticatorInterface $guardAuthenticator
130129

131130
throw new BadCredentialsException(sprintf('Authentication failed because "%s::checkCredentials()" did not return true.', get_debug_type($guardAuthenticator)));
132131
}
133-
if ($this->userProvider instanceof PasswordUpgraderInterface && $guardAuthenticator instanceof PasswordAuthenticatedInterface && null !== $this->passwordHasher && (null !== $password = $guardAuthenticator->getPassword($token->getCredentials())) && method_exists($this->passwordHasher, 'needsRehash') && $this->passwordHasher->needsRehash($user)) {
134-
if ($this->passwordHasher instanceof PasswordEncoderInterface) {
132+
if ($this->userProvider instanceof PasswordUpgraderInterface && $guardAuthenticator instanceof PasswordAuthenticatedInterface && null !== $this->passwordHasher && (null !== $password = $guardAuthenticator->getPassword($token->getCredentials())) && $this->passwordHasher->needsRehash($user)) {
133+
if ($this->passwordHasher instanceof UserPasswordEncoderInterface) {
135134
// @deprecated since Symfony 5.3
136135
$this->userProvider->upgradePassword($user, $this->passwordHasher->encodePassword($user, $password));
137136
} else {

src/Symfony/Component/Security/Http/EventListener/PasswordMigratingListener.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
namespace Symfony\Component\Security\Http\EventListener;
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15-
use Symfony\Component\PasswordHasher\Exception\InvalidPasswordException;
15+
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
16+
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
1617
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
17-
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1818
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
1919
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge;
2020
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
2121
use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface;
2222
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
23-
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
2423

2524
/**
2625
* @author Wouter de Jong <wouter@wouterj.nl>
@@ -82,7 +81,7 @@ public function onLoginSuccess(LoginSuccessEvent $event): void
8281
}
8382
}
8483

85-
$passwordUpgrader->upgradePassword($user, $passwordHasher->hash($plaintextPassword, $user->getSalt()));
84+
$passwordUpgrader->upgradePassword($user, $passwordHasher instanceof PasswordHasherInterface ? $passwordHasher->hash($plaintextPassword, $user->getSalt()) : $passwordHasher->encodePassword($plaintextPassword, $user->getSalt()));
8685
}
8786

8887
public static function getSubscribedEvents(): array

0 commit comments

Comments
 (0)
0