Skip to content

[Security] Remove deprecated support for passing a UserInterface implementation to Passport #40487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Security] Disallow passing a UserInterface to Passport
This was deprecated in 5.2, with a warning that support would be dropped in 5.3
(due to the experimental state).
  • Loading branch information
wouterj authored and fabpot committed Mar 17, 2021
commit 99cf2a3a71bf412d1005c5164a50f1982a619822
1 change: 1 addition & 0 deletions UPGRADE-5.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Security
If you are using the `isAccountNonLocked()`, `isAccountNonExpired()` or `isCredentialsNonExpired()` method, consider re-implementing
them in your own user class, as they are not part of the `InMemoryUser` API
* Deprecate class `UserChecker`, use `InMemoryUserChecker` or your own implementation instead
* [BC break] Remove support for passing a `UserInterface` implementation to `Passport`, use the `UserBadge` instead.
* Deprecate `UserInterface::getPassword()`
If your `getPassword()` method does not return `null` (i.e. you are using password-based authentication),
you should implement `PasswordAuthenticatedUserInterface`.
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Security/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* Deprecate class `User`, use `InMemoryUser` instead
* Deprecate class `UserChecker`, use `InMemoryUserChecker` or your own implementation instead
* [BC break] Remove support for passing a `UserInterface` implementation to `Passport`, use the `UserBadge` instead.
* Add `PasswordAuthenticatedUserInterface` for user classes that use passwords
* Add `LegacyPasswordAuthenticatedUserInterface` for user classes that use user-provided salts in addition to passwords
* Deprecate all classes in the `Core\Encoder\` sub-namespace, use the `PasswordHasher` component instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,13 @@ class Passport implements UserPassportInterface
private $attributes = [];

/**
* @param UserBadge $userBadge
* @param CredentialsInterface $credentials the credentials to check for this authentication, use
* SelfValidatingPassport if no credentials should be checked
* @param BadgeInterface[] $badges
*/
public function __construct($userBadge, CredentialsInterface $credentials, array $badges = [])
public function __construct(UserBadge $userBadge, CredentialsInterface $credentials, array $badges = [])
{
if ($userBadge instanceof UserInterface) {
trigger_deprecation('symfony/security-http', '5.2', 'The 1st argument of "%s" must be an instance of "%s", support for "%s" will be removed in symfony/security-http 5.3.', __CLASS__, UserBadge::class, UserInterface::class);

$this->user = $userBadge;
} elseif ($userBadge instanceof UserBadge) {
$this->addBadge($userBadge);
} else {
throw new \TypeError(sprintf('Argument 1 of "%s" must be an instance of "%s", "%s" given.', __METHOD__, UserBadge::class, get_debug_type($userBadge)));
}

$this->addBadge($userBadge);
$this->addBadge($credentials);
foreach ($badges as $badge) {
$this->addBadge($badge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,11 @@
class SelfValidatingPassport extends Passport
{
/**
* @param UserBadge $userBadge
* @param BadgeInterface[] $badges
*/
public function __construct($userBadge, array $badges = [])
public function __construct(UserBadge $userBadge, array $badges = [])
{
if ($userBadge instanceof UserInterface) {
trigger_deprecation('symfony/security-http', '5.2', 'The 1st argument of "%s" must be an instance of "%s", support for "%s" will be removed in symfony/security-http 5.3.', __CLASS__, UserBadge::class, UserInterface::class);

$this->user = $userBadge;
} elseif ($userBadge instanceof UserBadge) {
$this->addBadge($userBadge);
} else {
throw new \TypeError(sprintf('Argument 1 of "%s" must be an instance of "%s", "%s" given.', __METHOD__, UserBadge::class, get_debug_type($userBadge)));
}

$this->addBadge($userBadge);
foreach ($badges as $badge) {
$this->addBadge($badge);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,4 @@ public function provideCompletePassports()
{
yield [new SelfValidatingPassport(new UserBadge('wouter', function () {}))];
}

/**
* @group legacy
*/
public function testLegacyUserPassport()
{
$passport = new SelfValidatingPassport($user = $this->createMock(UserInterface::class));
$this->listener->checkPassport(new CheckPassportEvent($this->createMock(AuthenticatorInterface::class), $passport));

$this->assertFalse($passport->hasBadge(UserBadge::class));
$this->assertSame($user, $passport->getUser());
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy