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

Skip to content

Commit ea1395b

Browse files
committed
[Security] Remove everything related to the deprecated authentication manager
1 parent bf7201e commit ea1395b

File tree

169 files changed

+241
-12210
lines changed

Some content is hidden

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

169 files changed

+241
-12210
lines changed

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

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

403403
if (!\is_object($user = $token->getUser())) {
404-
// e.g. anonymous authentication
405404
return null;
406405
}
407406

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,19 +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
{
4645
$this->firewallNames = $firewallNames;
4746
$this->contexts = $contexts;
4847
$this->eventDispatchers = $eventDispatchers;
4948
$this->authenticators = $authenticators;
50-
$this->authenticatorManagerEnabled = $authenticatorManagerEnabled;
5149

5250
parent::__construct();
5351
}
@@ -115,9 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
115113
$this->displayEventListeners($name, $context, $io);
116114
}
117115

118-
if ($this->authenticatorManagerEnabled) {
119-
$this->displayAuthenticators($name, $io);
120-
}
116+
$this->displayAuthenticators($name, $io);
121117

122118
return 0;
123119
}

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

Lines changed: 3 additions & 9 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,9 +43,8 @@ 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
{
5149
$this->tokenStorage = $tokenStorage;
5250
$this->roleHierarchy = $roleHierarchy;
@@ -55,7 +53,6 @@ public function __construct(TokenStorageInterface $tokenStorage = null, RoleHier
5553
$this->firewallMap = $firewallMap;
5654
$this->firewall = $firewall;
5755
$this->hasVarDumper = class_exists(ClassStub::class);
58-
$this->authenticatorManagerEnabled = $authenticatorManagerEnabled;
5956
}
6057

6158
/**
@@ -114,7 +111,7 @@ public function collect(Request $request, Response $response, \Throwable $except
114111

115112
$logoutUrl = null;
116113
try {
117-
if (null !== $this->logoutUrlGenerator && !$token instanceof AnonymousToken) {
114+
if (null !== $this->logoutUrlGenerator) {
118115
$logoutUrl = $this->logoutUrlGenerator->getLogoutPath();
119116
}
120117
} catch (\Exception $e) {
@@ -180,7 +177,6 @@ public function collect(Request $request, Response $response, \Throwable $except
180177
if (null !== $firewallConfig) {
181178
$this->data['firewall'] = [
182179
'name' => $firewallConfig->getName(),
183-
'allows_anonymous' => $firewallConfig->allowsAnonymous(),
184180
'request_matcher' => $firewallConfig->getRequestMatcher(),
185181
'security_enabled' => $firewallConfig->isSecurityEnabled(),
186182
'stateless' => $firewallConfig->isStateless(),
@@ -209,8 +205,6 @@ public function collect(Request $request, Response $response, \Throwable $except
209205
if ($this->firewall) {
210206
$this->data['listeners'] = $this->firewall->getWrappedListeners();
211207
}
212-
213-
$this->data['authenticator_manager_enabled'] = $this->authenticatorManagerEnabled;
214208
}
215209

216210
/**
@@ -399,6 +393,6 @@ public function getName()
399393

400394
public function isAuthenticatorManagerEnabled(): bool
401395
{
402-
return $this->data['authenticator_manager_enabled'];
396+
return true;
403397
}
404398
}

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, $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 & 78 deletions
This file was deleted.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,32 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory;
1313

14+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
1415
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516

1617
/**
1718
* @author Wouter de Jong <wouter@wouterj.nl>
1819
*/
1920
interface AuthenticatorFactoryInterface
2021
{
22+
/**
23+
* Defines the position at which the provider is called.
24+
* Possible values: pre_auth, form, http, and remember_me.
25+
*
26+
* @return string
27+
*/
28+
public function getPosition();
29+
30+
/**
31+
* Defines the configuration key used to reference the provider
32+
* in the firewall configuration.
33+
*
34+
* @return string
35+
*/
36+
public function getKey();
37+
38+
public function addConfiguration(NodeDefinition $builder);
39+
2140
/**
2241
* Creates the authenticator service(s) for the provided configuration.
2342
*

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@
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)
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 getPosition(): string
3126
{
3227
return 'pre_auth';

0 commit comments

Comments
 (0)
0