Skip to content

Commit ced19c8

Browse files
committed
[Security] Remove everything related to the deprecated authentication manager
1 parent 016216e commit ced19c8

File tree

164 files changed

+213
-11737
lines changed

Some content is hidden

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

164 files changed

+213
-11737
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ protected function getUser()
410410
}
411411

412412
if (!\is_object($user = $token->getUser())) {
413-
// e.g. anonymous authentication
414413
return null;
415414
}
416415

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

Lines changed: 0 additions & 11 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,16 +145,6 @@ public function testGetUser()
146145
$this->assertSame($controller->getUser(), $user);
147146
}
148147

149-
public function testGetUserAnonymousUserConvertedToNull()
150-
{
151-
$token = new AnonymousToken('default', 'anon.');
152-
153-
$controller = $this->createController();
154-
$controller->setContainer($this->getContainerWithTokenStorage($token));
155-
156-
$this->assertNull($controller->getUser());
157-
}
158-
159148
public function testGetUserWithEmptyTokenStorage()
160149
{
161150
$controller = $this->createController();

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ 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
{
4645
if (!$authenticatorManagerEnabled) {
4746
trigger_deprecation('symfony/security-bundle', '5.4', 'Setting the $authenticatorManagerEnabled argument of "%s" to "false" is deprecated, use the new authenticator system instead.', __METHOD__);
@@ -51,7 +50,6 @@ public function __construct(array $firewallNames, ContainerInterface $contexts,
5150
$this->contexts = $contexts;
5251
$this->eventDispatchers = $eventDispatchers;
5352
$this->authenticators = $authenticators;
54-
$this->authenticatorManagerEnabled = $authenticatorManagerEnabled;
5553

5654
parent::__construct();
5755
}
@@ -119,9 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
119117
$this->displayEventListeners($name, $context, $io);
120118
}
121119

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

126122
return 0;
127123
}

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

Lines changed: 2 additions & 17 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
/**
@@ -118,7 +111,7 @@ public function collect(Request $request, Response $response, \Throwable $except
118111

119112
$logoutUrl = null;
120113
try {
121-
if (null !== $this->logoutUrlGenerator && !$token instanceof AnonymousToken) {
114+
if (null !== $this->logoutUrlGenerator) {
122115
$logoutUrl = $this->logoutUrlGenerator->getLogoutPath();
123116
}
124117
} catch (\Exception $e) {
@@ -184,7 +177,6 @@ public function collect(Request $request, Response $response, \Throwable $except
184177
if (null !== $firewallConfig) {
185178
$this->data['firewall'] = [
186179
'name' => $firewallConfig->getName(),
187-
'allows_anonymous' => $firewallConfig->allowsAnonymous(),
188180
'request_matcher' => $firewallConfig->getRequestMatcher(),
189181
'security_enabled' => $firewallConfig->isSecurityEnabled(),
190182
'stateless' => $firewallConfig->isStateless(),
@@ -213,8 +205,6 @@ public function collect(Request $request, Response $response, \Throwable $except
213205
if ($this->firewall) {
214206
$this->data['listeners'] = $this->firewall->getWrappedListeners();
215207
}
216-
217-
$this->data['authenticator_manager_enabled'] = $this->authenticatorManagerEnabled;
218208
}
219209

220210
/**
@@ -362,9 +352,4 @@ public function getName(): string
362352
{
363353
return 'security';
364354
}
365-
366-
public function isAuthenticatorManagerEnabled(): bool
367-
{
368-
return $this->data['authenticator_manager_enabled'];
369-
}
370355
}

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
2525
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
2626
*/
27-
abstract class AbstractFactory implements SecurityFactoryInterface
27+
abstract class AbstractFactory implements AuthenticatorFactoryInterface
2828
{
2929
protected $options = [
3030
'check_path' => '/login_check',
@@ -48,26 +48,9 @@ abstract class AbstractFactory implements SecurityFactoryInterface
4848
'failure_path_parameter' => '_failure_path',
4949
];
5050

51-
public function create(ContainerBuilder $container, string $id, array $config, string $userProviderId, ?string $defaultEntryPointId)
51+
final public function addOption(string $name, $default = null)
5252
{
53-
// authentication provider
54-
$authProviderId = $this->createAuthProvider($container, $id, $config, $userProviderId);
55-
56-
// authentication listener
57-
$listenerId = $this->createListener($container, $id, $config, $userProviderId);
58-
59-
// add remember-me aware tag if requested
60-
if ($this->isRememberMeAware($config)) {
61-
$container
62-
->getDefinition($listenerId)
63-
->addTag('security.remember_me_aware', ['id' => $id, 'provider' => $userProviderId])
64-
;
65-
}
66-
67-
// create entry point if applicable (optional)
68-
$entryPointId = $this->createEntryPoint($container, $id, $config, $defaultEntryPointId);
69-
70-
return [$authProviderId, $listenerId, $entryPointId];
53+
$this->options[$name] = $default;
7154
}
7255

7356
public function addConfiguration(NodeDefinition $node)
@@ -90,73 +73,6 @@ public function addConfiguration(NodeDefinition $node)
9073
}
9174
}
9275

93-
final public function addOption(string $name, mixed $default = null)
94-
{
95-
$this->options[$name] = $default;
96-
}
97-
98-
/**
99-
* Subclasses must return the id of a service which implements the
100-
* AuthenticationProviderInterface.
101-
*
102-
* @return string never null, the id of the authentication provider
103-
*/
104-
abstract protected function createAuthProvider(ContainerBuilder $container, string $id, array $config, string $userProviderId);
105-
106-
/**
107-
* Subclasses must return the id of the abstract listener template.
108-
*
109-
* Listener definitions should inherit from the AbstractAuthenticationListener
110-
* like this:
111-
*
112-
* <service id="my.listener.id"
113-
* class="My\Concrete\Classname"
114-
* parent="security.authentication.listener.abstract"
115-
* abstract="true" />
116-
*
117-
* In the above case, this method would return "my.listener.id".
118-
*
119-
* @return string
120-
*/
121-
abstract protected function getListenerId();
122-
123-
/**
124-
* Subclasses may create an entry point of their as they see fit. The
125-
* default implementation does not change the default entry point.
126-
*
127-
* @return string|null the entry point id
128-
*/
129-
protected function createEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPointId)
130-
{
131-
return $defaultEntryPointId;
132-
}
133-
134-
/**
135-
* Subclasses may disable remember-me features for the listener, by
136-
* always returning false from this method.
137-
*
138-
* @return bool Whether a possibly configured RememberMeServices should be set for this listener
139-
*/
140-
protected function isRememberMeAware(array $config)
141-
{
142-
return $config['remember_me'];
143-
}
144-
145-
protected function createListener(ContainerBuilder $container, string $id, array $config, string $userProvider)
146-
{
147-
$listenerId = $this->getListenerId();
148-
$listener = new ChildDefinition($listenerId);
149-
$listener->replaceArgument(4, $id);
150-
$listener->replaceArgument(5, new Reference($this->createAuthenticationSuccessHandler($container, $id, $config)));
151-
$listener->replaceArgument(6, new Reference($this->createAuthenticationFailureHandler($container, $id, $config)));
152-
$listener->replaceArgument(7, array_intersect_key($config, $this->options));
153-
154-
$listenerId .= '.'.$id;
155-
$container->setDefinition($listenerId, $listener);
156-
157-
return $listenerId;
158-
}
159-
16076
protected function createAuthenticationSuccessHandler(ContainerBuilder $container, string $id, array $config)
16177
{
16278
$successHandlerId = $this->getSuccessHandlerId($id);

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php

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

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AuthenticatorFactoryInterface.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,29 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616

1717
/**
18-
* @method int getPriority() defines the position at which the authenticator is called
19-
*
2018
* @author Wouter de Jong <wouter@wouterj.nl>
2119
*/
2220
interface AuthenticatorFactoryInterface
2321
{
2422
/**
25-
* Creates the authenticator service(s) for the provided configuration.
26-
*
27-
* @return string|string[] The authenticator service ID(s) to be used by the firewall
23+
* Defines the priority at which the authenticator is called.
2824
*/
29-
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId);
25+
public function getPriority(): int;
3026

3127
/**
32-
* Defines the configuration key used to reference the authenticator
28+
* Defines the configuration key used to reference the provider
3329
* in the firewall configuration.
3430
*
3531
* @return string
3632
*/
3733
public function getKey();
3834

3935
public function addConfiguration(NodeDefinition $builder);
36+
37+
/**
38+
* Creates the authenticator service(s) for the provided configuration.
39+
*
40+
* @return string|string[] The authenticator service ID(s) to be used by the firewall
41+
*/
42+
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId);
4043
}

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/CustomAuthenticatorFactory.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,13 @@
2020
*
2121
* @internal
2222
*/
23-
class CustomAuthenticatorFactory implements AuthenticatorFactoryInterface, SecurityFactoryInterface
23+
class CustomAuthenticatorFactory implements AuthenticatorFactoryInterface
2424
{
25-
public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint): array
26-
{
27-
throw new \LogicException('Custom authenticators are not supported when "security.enable_authenticator_manager" is not set to true.');
28-
}
29-
3025
public function getPriority(): int
3126
{
3227
return 0;
3328
}
3429

35-
public function getPosition(): string
36-
{
37-
return 'pre_auth';
38-
}
39-
4030
public function getKey(): string
4131
{
4232
return 'custom_authenticators';

0 commit comments

Comments
 (0)