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

Skip to content

Commit 922c131

Browse files
wouterjnicolas-grekas
authored andcommitted
[Security] Remove everything related to the deprecated authentication manager
1 parent 11abf7c commit 922c131

File tree

276 files changed

+412
-16355
lines changed
  • User
  • 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.

    276 files changed

    +412
    -16355
    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
    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
    }

    src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

    Lines changed: 0 additions & 14 deletions
    Original file line numberDiff line numberDiff line change
    @@ -39,7 +39,6 @@
    3939
    use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
    4040
    use Symfony\Component\HttpKernel\HttpKernelInterface;
    4141
    use Symfony\Component\Routing\RouterInterface;
    42-
    use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
    4342
    use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
    4443
    use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
    4544
    use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
    @@ -146,19 +145,6 @@ public function testGetUser()
    146145
    $this->assertSame($controller->getUser(), $user);
    147146
    }
    148147

    149-
    /**
    150-
    * @group legacy
    151-
    */
    152-
    public function testGetUserAnonymousUserConvertedToNull()
    153-
    {
    154-
    $token = new AnonymousToken('default', 'anon.');
    155-
    156-
    $controller = $this->createController();
    157-
    $controller->setContainer($this->getContainerWithTokenStorage($token));
    158-
    159-
    $this->assertNull($controller->getUser());
    160-
    }
    161-
    162148
    public function testGetUserWithEmptyTokenStorage()
    163149
    {
    164150
    $controller = $this->createController();

    src/Symfony/Bundle/SecurityBundle/Command/DebugFirewallCommand.php

    Lines changed: 2 additions & 10 deletions
    Original file line numberDiff line numberDiff line change
    @@ -35,23 +35,17 @@ final class DebugFirewallCommand extends Command
    3535
    private $contexts;
    3636
    private $eventDispatchers;
    3737
    private $authenticators;
    38-
    private $authenticatorManagerEnabled;
    3938

    4039
    /**
    4140
    * @param string[] $firewallNames
    4241
    * @param AuthenticatorInterface[][] $authenticators
    4342
    */
    44-
    public function __construct(array $firewallNames, ContainerInterface $contexts, ContainerInterface $eventDispatchers, array $authenticators, bool $authenticatorManagerEnabled)
    43+
    public function __construct(array $firewallNames, ContainerInterface $contexts, ContainerInterface $eventDispatchers, array $authenticators)
    4544
    {
    46-
    if (!$authenticatorManagerEnabled) {
    47-
    trigger_deprecation('symfony/security-bundle', '5.4', 'Setting the $authenticatorManagerEnabled argument of "%s" to "false" is deprecated, use the new authenticator system instead.', __METHOD__);
    48-
    }
    49-
    5045
    $this->firewallNames = $firewallNames;
    5146
    $this->contexts = $contexts;
    5247
    $this->eventDispatchers = $eventDispatchers;
    5348
    $this->authenticators = $authenticators;
    54-
    $this->authenticatorManagerEnabled = $authenticatorManagerEnabled;
    5549

    5650
    parent::__construct();
    5751
    }
    @@ -119,9 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
    119113
    $this->displayEventListeners($name, $context, $io);
    120114
    }
    121115

    122-
    if ($this->authenticatorManagerEnabled) {
    123-
    $this->displayAuthenticators($name, $io);
    124-
    }
    116+
    $this->displayAuthenticators($name, $io);
    125117

    126118
    return 0;
    127119
    }

    src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

    Lines changed: 4 additions & 21 deletions
    Original file line numberDiff line numberDiff line change
    @@ -17,7 +17,6 @@
    1717
    use Symfony\Component\HttpFoundation\Response;
    1818
    use Symfony\Component\HttpKernel\DataCollector\DataCollector;
    1919
    use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
    20-
    use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
    2120
    use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
    2221
    use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
    2322
    use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
    @@ -44,22 +43,16 @@ class SecurityDataCollector extends DataCollector implements LateDataCollectorIn
    4443
    private $firewallMap;
    4544
    private $firewall;
    4645
    private $hasVarDumper;
    47-
    private $authenticatorManagerEnabled;
    4846

    49-
    public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null, TraceableFirewallListener $firewall = null, bool $authenticatorManagerEnabled = false)
    47+
    public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null, TraceableFirewallListener $firewall = null)
    5048
    {
    51-
    if (!$authenticatorManagerEnabled) {
    52-
    trigger_deprecation('symfony/security-bundle', '5.4', 'Setting the $authenticatorManagerEnabled argument of "%s" to "false" is deprecated, use the new authenticator system instead.', __METHOD__);
    53-
    }
    54-
    5549
    $this->tokenStorage = $tokenStorage;
    5650
    $this->roleHierarchy = $roleHierarchy;
    5751
    $this->logoutUrlGenerator = $logoutUrlGenerator;
    5852
    $this->accessDecisionManager = $accessDecisionManager;
    5953
    $this->firewallMap = $firewallMap;
    6054
    $this->firewall = $firewall;
    6155
    $this->hasVarDumper = class_exists(ClassStub::class);
    62-
    $this->authenticatorManagerEnabled = $authenticatorManagerEnabled;
    6356
    }
    6457

    6558
    /**
    @@ -104,8 +97,7 @@ public function collect(Request $request, Response $response, \Throwable $except
    10497
    $impersonatorUser = null;
    10598
    if ($token instanceof SwitchUserToken) {
    10699
    $originalToken = $token->getOriginalToken();
    107-
    // @deprecated since Symfony 5.3, change to $originalToken->getUserIdentifier() in 6.0
    108-
    $impersonatorUser = method_exists($originalToken, 'getUserIdentifier') ? $originalToken->getUserIdentifier() : $originalToken->getUsername();
    100+
    $impersonatorUser = $originalToken->getUserIdentifier();
    109101
    }
    110102

    111103
    if (null !== $this->roleHierarchy) {
    @@ -118,7 +110,7 @@ public function collect(Request $request, Response $response, \Throwable $except
    118110

    119111
    $logoutUrl = null;
    120112
    try {
    121-
    if (null !== $this->logoutUrlGenerator && !$token instanceof AnonymousToken) {
    113+
    if (null !== $this->logoutUrlGenerator) {
    122114
    $logoutUrl = $this->logoutUrlGenerator->getLogoutPath();
    123115
    }
    124116
    } catch (\Exception $e) {
    @@ -134,8 +126,7 @@ public function collect(Request $request, Response $response, \Throwable $except
    134126
    'token' => $token,
    135127
    'token_class' => $this->hasVarDumper ? new ClassStub(\get_class($token)) : \get_class($token),
    136128
    'logout_url' => $logoutUrl,
    137-
    // @deprecated since Symfony 5.3, change to $token->getUserIdentifier() in 6.0
    138-
    'user' => method_exists($token, 'getUserIdentifier') ? $token->getUserIdentifier() : $token->getUsername(),
    129+
    'user' => $token->getUserIdentifier(),
    139130
    'roles' => $assignedRoles,
    140131
    'inherited_roles' => array_unique($inheritedRoles),
    141132
    'supports_role_hierarchy' => null !== $this->roleHierarchy,
    @@ -184,7 +175,6 @@ public function collect(Request $request, Response $response, \Throwable $except
    184175
    if (null !== $firewallConfig) {
    185176
    $this->data['firewall'] = [
    186177
    'name' => $firewallConfig->getName(),
    187-
    'allows_anonymous' => $this->authenticatorManagerEnabled ? false : $firewallConfig->allowsAnonymous(),
    188178
    'request_matcher' => $firewallConfig->getRequestMatcher(),
    189179
    'security_enabled' => $firewallConfig->isSecurityEnabled(),
    190180
    'stateless' => $firewallConfig->isStateless(),
    @@ -213,8 +203,6 @@ public function collect(Request $request, Response $response, \Throwable $except
    213203
    if ($this->firewall) {
    214204
    $this->data['listeners'] = $this->firewall->getWrappedListeners();
    215205
    }
    216-
    217-
    $this->data['authenticator_manager_enabled'] = $this->authenticatorManagerEnabled;
    218206
    }
    219207

    220208
    /**
    @@ -362,9 +350,4 @@ public function getName(): string
    362350
    {
    363351
    return 'security';
    364352
    }
    365-
    366-
    public function isAuthenticatorManagerEnabled(): bool
    367-
    {
    368-
    return $this->data['authenticator_manager_enabled'];
    369-
    }
    370353
    }

    src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/RegisterCsrfTokenClearingLogoutHandlerPass.php

    Lines changed: 0 additions & 31 deletions
    This file was deleted.

    0 commit comments

    Comments
     (0)
    0