8000 [Security] Remove everything related to the deprecated authentication… · symfony/symfony@026a480 · GitHub
[go: up one dir, main page]

Skip to content

Commit 026a480

Browse files
committed
[Security] Remove everything related to the deprecated authentication manager
1 parent 11abf7c commit 026a480

File tree

275 files changed

+410
-16348
lines changed
  • Guard
  • Http
  • Workflow/Tests/EventListener
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    275 files changed

    +410
    -16348
    lines changed

    src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

    Lines changed: 1 addition & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -117,8 +117,7 @@ public function createNewToken(PersistentTokenInterface $token)
    117117
    $sql = 'INSERT INTO rememberme_token (class, username, series, value, lastUsed) VALUES (:class, :username, :series, :value, :lastUsed)';
    118118
    $paramValues = [
    119119
    'class' => $token->getClass(),
    120-
    // @deprecated since Symfony 5.3, change to $token->getUserIdentifier() in 6.0
    121-
    'username' => method_exists($token, 'getUserIdentifier') ? $token->getUserIdentifier() : $token->getUsername(),
    120+
    'username' => $token->getUserIdentifier(),
    122121
    'series' => $token->getSeries(),
    123122
    'value' => $token->getTokenValue(),
    124123
    'lastUsed' => $token->getLastUsed(),

    src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

    Lines changed: 1 addition & 18 deletions
    Original file line numberDiff line numberDiff line change
    @@ -46,16 +46,6 @@ public function __construct(ManagerRegistry $registry, string $classOrAlias, str
    4646
    $this->property = $property;
    4747
    }
    4848

    49-
    /**
    50-
    * {@inheritdoc}
    51-
    */
    52-
    public function loadUserByUsername(string $username): UserInterface
    53-
    {
    54-
    trigger_deprecation('symfony/doctrine-bridge', '5.3', 'Method "%s()" is deprecated, use loadUserByIdentifier() instead.', __METHOD__);
    55-
    56-
    return $this->loadUserByIdentifier($username);
    57-
    }
    58-
    5949
    public function loadUserByIdentifier(string $identifier): UserInterface
    6050
    {
    6151
    $repository = $this->getRepository();
    @@ -66,14 +56,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface
    6656
    throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_debug_type($repository)));
    6757
    }
    6858

    69-
    // @deprecated since Symfony 5.3, change to $repository->loadUserByIdentifier() in 6.0
    70-
    if (method_exists($repository, 'loadUserByIdentifier')) {
    71-
    $user = $repository->loadUserByIdentifier($identifier);
    72-
    } else {
    73-
    trigger_deprecation('symfony/doctrine-bridge', '5.3', 'Not implementing method "loadUserByIdentifier()" in user loader "%s" is deprecated. This method will replace "loadUserByUsername()" in Symfony 6.0.', get_debug_type($repository));
    74-
    75-
    $user = $repository->loadUserByUsername($identifier);
    76-
    }
    59+
    $user = $repository->loadUserByIdentifier($identifier);
    7760
    }
    7861

    7962
    if (null === $user) {

    src/Symfony/Bridge/Doctrine/Security/User/UserLoaderInterface.php

    Lines changed: 4 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -22,15 +22,14 @@
    2222
    *
    2323
    * @see UserInterface
    2424
    *
    25-
    * @method UserInterface|null loadUserByIdentifier(string $identifier) loads the user for the given user identifier (e.g. username or email).
    26-
    * This method must return null if the user is not found.
    27-
    *
    2825
    * @author Michal Trojanowski <michal@kmt-studio.pl>
    2926
    */
    3027
    interface UserLoaderInterface
    3128
    {
    3229
    /**
    33-
    * @deprecated since Symfony 5.3, use loadUserByIdentifier() instead
    30+
    * Loads the user for the given user identifier (e.g. username or email).
    31+
    *
    32+
    * This method must return null if the user is not found.
    3433
    */
    35-
    public function loadUserByUsername(string $username): ?UserInterface;
    34+
    public function loadUserByIdentifier(string $identifier): ?UserInterface;
    3635
    }

    src/Symfony/Bridge/Monolog/Processor/AbstractTokenProcessor.php

    Lines changed: 1 addition & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -46,12 +46,7 @@ public function __invoke(array $record): array
    4646
    'roles' => $token->getRoleNames(),
    4747
    ];
    4848

    49-
    // @deprecated since Symfony 5.3, change to $token->getUserIdentifier() in 6.0
    50-
    if (method_exists($token, 'getUserIdentifier')) {
    51-
    $record['extra'][$this->getKey()]['username'] = $record['extra'][$this->getKey()]['user_identifier'] = $token->getUserIdentifier();
    52-
    } else {
    53-
    $record['extra'][$this->getKey()]['username'] = $token->getUsername();
    54-
    }
    49+
    $record['extra'][$this->getKey()]['user_identifier'] = $token->getUserIdentifier();
    5550
    }
    5651

    5752
    return $record;

    src/Symfony/Bridge/Monolog/Tests/Processor/SwitchUserTokenProcessorTest.php

    Lines changed: 3 additions & 12 deletions
    849F
    Original file line numberDiff line numberDiff line change
    @@ -17,7 +17,6 @@
    1717
    use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
    1818
    use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
    1919
    use Symfony\Component\Security\Core\User\InMemoryUser;
    20-
    use Symfony\Component\Security\Core\User\User;
    2120

    2221
    /**
    2322
    * Tests the SwitchUserTokenProcessor.
    @@ -28,13 +27,8 @@ class SwitchUserTokenProcessorTest extends TestCase
    2827
    {
    2928
    public function testProcessor()
    3029
    {
    31-
    if (class_exists(InMemoryUser::class)) {
    32-
    $originalToken = new UsernamePasswordToken(new InMemoryUser('original_user', 'password', ['ROLE_SUPER_ADMIN']), 'provider', ['ROLE_SUPER_ADMIN']);
    33-
    $switchUserToken = new SwitchUserToken(new InMemoryUser('user', 'passsword', ['ROLE_USER']), 'provider', ['ROLE_USER'], $originalToken);
    34-
    } else {
    35-
    $originalToken = new UsernamePasswordToken(new User('original_user', 'password', ['ROLE_SUPER_ADMIN']), null, 'provider', ['ROLE_SUPER_ADMIN']);
    36-
    $switchUserToken = new SwitchUserToken(new User('user', 'passsword', ['ROLE_USER']), null, 'provider', ['ROLE_USER'], $originalToken);
    37-
    }
    30+
    $originalToken = new UsernamePasswordToken(new InMemoryUser('original_user', 'password', ['ROLE_SUPER_ADMIN']), 'provider', ['ROLE_SUPER_ADMIN']);
    31+
    $switchUserToken = new SwitchUserToken(new InMemoryUser('user', 'passsword', ['ROLE_USER']), 'provider', ['ROLE_USER'], $originalToken);
    3832
    $tokenStorage = $this->createMock(TokenStorageInterface::class);
    3933
    $tokenStorage->method('getToken')->willReturn($switchUserToken);
    4034

    @@ -46,12 +40,9 @@ public function testProcessor()
    4640
    'impersonator_token' => [
    4741
    'authenticated' => true,
    4842
    'roles' => ['ROLE_SUPER_ADMIN'],
    49-
    'username' => 'original_user',
    43+
    'user_identifier' => 'original_user',
    5044
    ],
    5145
    ];
    52-
    if (method_exists($originalToken, 'getUserIdentifier')) {
    53-
    $expected['impersonator_token']['user_identifier'] = 'original_user';
    54-
    }
    5546

    5647
    $this->assertEquals($expected, $record['extra']);
    5748
    }

    src/Symfony/Bridge/Monolog/composer.json

    Lines changed: 3 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -24,15 +24,16 @@
    2424
    "require-dev": {
    2525
    "symfony/console": "^5.4|^6.0",
    2626
    "symfony/http-client": "^5.4|^6.0",
    27-
    "symfony/security-core": "^5.4|^6.0",
    27+
    "symfony/security-core": "^6.0",
    2828
    "symfony/var-dumper": "^5.4|^6.0",
    2929
    "symfony/mailer": "^5.4|^6.0",
    3030
    "symfony/mime": "^5.4|^6.0",
    3131
    "symfony/messenger": "^5.4|^6.0"
    3232
    },
    3333
    "conflict": {
    3434
    "symfony/console": "<5.4",
    35-
    "symfony/http-foundation": "<5.4"
    35+
    "symfony/http-foundation": "<5.4",
    36+
    "symfony/security-core": "<6.0"
    3637
    },
    3738
    "suggest": {
    3839
    "symfony/http-kernel": "For using the debugging handlers together with the response life cycle of the HTTP kernel.",

    src/Symfony/Bridge/Twig/AppVariable.php

    Lines changed: 1 addition & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -78,10 +78,7 @@ public function getUser(): ?object
    7878
    return null;
    7979
    }
    8080

    81-
    $user = $token->getUser();
    82-
    83-
    // @deprecated since 5.4, $user will always be a UserInterface instance
    84-
    return \is_object($user) ? $user : null;
    81+
    return $token->getUser();
    8582
    }
    8683

    8784
    /**

    src/Symfony/Bridge/Twig/Tests/AppVariableTest.php

    Lines changed: 0 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -95,13 +95,6 @@ public function testGetUser()
    9595
    $this->assertEquals($user, $this->appVariable->getUser());
    9696
    }
    9797

    98-
    public function testGetUserWithUsernameAsTokenUser()
    99-
    {
    100-
    $this->setTokenStorage($user = 'username');
    101-
    102-
    $this->assertNull($this->appVariable->getUser());
    103-
    }
    104-
    10598
    public function testGetTokenWithNoToken()
    10699
    {
    107100
    $tokenStorage = $this->createMock(TokenStorageInterface::class);

    src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

    Lines changed: 1 addition & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -409,13 +409,7 @@ protected function getUser(): ?object
    409409
    return null;
    410410
    }
    411411

    412-
    // @deprecated since 5.4, $user will always be a UserInterface instance
    413-
    if (!\is_object($user = $token->getUser())) {
    414-
    // e.g. anonymous authentication
    415-
    return null;
    416-
    }
    417-
    418-
    return $user;
    412+
    return $token->getUser();
    419413
    }
    420414

    421415
    /**

    src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -119,7 +119,7 @@ public function loginUser(object $user, string $firewallContext = 'main'): self
    119119
    }
    120120

    121121
    $token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
    122-
    // @deprecated since Symfony 5.4
    122+
    // required for compatibilty with Symfony 5.4
    123123
    if (method_exists($token, 'isAuthenticated')) {
    124124
    $token->setAuthenticated(true, false);
    125125
    }

    0 commit comments

    Comments
     (0)
    0