10000 feature #28693 [Security] Deprecate simple_preauth and simple_form in… · symfony/symfony@7cc7c71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cc7c71

Browse files
committed
feature #28693 [Security] Deprecate simple_preauth and simple_form in favor of Guard (chalasr)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Security] Deprecate simple_preauth and simple_form in favor of Guard | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 5093b9f [Security] Deprecate simple_preauth and simple_form in favor of Guard
2 parents 97aab08 + 5093b9f commit 7cc7c71

26 files changed

+176
-42
lines changed

UPGRADE-4.2.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ Security
186186
use custom tokens, extend the existing `Symfony\Component\Security\Core\Authentication\Token\AnonymousToken`
187187
or `Symfony\Component\Security\Core\Authentication\Token\RememberMeToken`.
188188
* Accessing the user object that is not an instance of `UserInterface` from `Security::getUser()` is deprecated.
189+
* `SimpleAuthenticatorInterface`, `SimpleFormAuthenticatorInterface`, `SimplePreAuthenticatorInterface`,
190+
`SimpleAuthenticationProvider`, `SimpleAuthenticationHandler`, `SimpleFormAuthenticationListener` and
191+
`SimplePreAuthenticationListener` have been deprecated. Use Guard instead.
189192

190193
SecurityBundle
191194
--------------
@@ -196,6 +199,10 @@ SecurityBundle
196199
`security.authentication.trust_resolver.rememberme_class` parameters to define
197200
the token classes is deprecated. To use
198201
custom tokens extend the existing AnonymousToken and RememberMeToken.
202+
* The `simple_form` and `simple_preauth` authentication listeners have been deprecated,
203+
use Guard instead.
204+
* The `SimpleFormFactory` and `SimplePreAuthenticationFactory` classes have been deprecated,
205+
use Guard instead.
199206

200207
Serializer
201208
----------

UPGRADE-5.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ Security
160160
the 3rd one must be either a `LogoutListener` instance or `null`.
161161
* The `AuthenticationTrustResolver` constructor arguments have been removed.
162162
* A user object that is not an instance of `UserInterface` cannot be accessed from `Security::getUser()` anymore and returns `null` instead.
163+
* `SimpleAuthenticatorInterface`, `SimpleFormAuthenticatorInterface`, `SimplePreAuthenticatorInterface`,
164+
`SimpleAuthenticationProvider`, `SimpleAuthenticationHandler`, `SimpleFormAuthenticationListener` and
165+
`SimplePreAuthenticationListener` have been removed. Use Guard instead.
163166

164167
SecurityBundle
165168
--------------
@@ -171,6 +174,10 @@ SecurityBundle
171174
now throws a `\TypeError`, pass a `LogoutListener` instance instead.
172175
* The `security.authentication.trust_resolver.anonymous_class` parameter has been removed.
173176
* The `security.authentication.trust_resolver.rememberme_class` parameter has been removed.
177+
* The `simple_form` and `simple_preauth` authentication listeners have been removed,
178+
use Guard instead.
179+
* The `SimpleFormFactory` and `SimplePreAuthenticationFactory` classes have been removed,
180+
use Guard instead.
174181

175182
Serializer
176183
----------

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ CHANGELOG
1313
* Added `json_login_ldap` authentication provider to use LDAP authentication with a REST API.
1414
* Made remember-me cookies inherit their default config from `framework.session.cookie_*`
1515
and added an "auto" mode to their "secure" config option to make them secure on HTTPS automatically.
16+
* Deprecated the `simple_form` and `simple_preauth` authentication listeners, use Guard instead.
17+
* Deprecated the `SimpleFormFactory` and `SimplePreAuthenticationFactory` classes, use Guard instead.
1618

1719
4.1.0
1820
-----

src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection;
1313

1414
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
15+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SimpleFormFactory;
16+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SimplePreAuthenticationFactory;
1517
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1618
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1719
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -265,6 +267,10 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
265267
->canBeUnset()
266268
;
267269

270+
if ($factory instanceof SimplePreAuthenticationFactory || $factory instanceof SimpleFormFactory) {
271+
$factoryNode->setDeprecated(sprintf('The "%s" security listener is deprecated Symfony 4.2, use Guard instead.', $name));
272+
}
273+
268274
if ($factory instanceof AbstractFactory) {
269275
$abstractFactoryKeys[] = $name;
270276
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818

1919
/**
2020
* @author Jordi Boggiano <j.boggiano@seld.be>
21+
*
22+
* @deprecated since Symfony 4.2, use Guard instead.
2123
*/
2224
class SimpleFormFactory extends FormLoginFactory
2325
{
24-
public function __construct()
26+
public function __construct(bool $triggerDeprecation = true)
2527
{
2628
parent::__construct();
2729

2830
$this->addOption('authenticator', null);
31+
32+
if ($triggerDeprecation) {
33+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.2, use Guard instead.', __CLASS__), E_USER_DEPRECATED);
34+
}
2935
}
3036

3137
public function getKey()

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@
1818

1919
/**
2020
* @author Jordi Boggiano <j.boggiano@seld.be>
21+
*
22+
* @deprecated since Symfony 4.2, use Guard instead.
2123
*/
2224
class SimplePreAuthenticationFactory implements SecurityFactoryInterface
2325
{
26+
public function __construct(bool $triggerDeprecation = true)
27+
{
28+
if ($triggerDeprecation) {
29+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.2, use Guard instead.', __CLASS__), E_USER_DEPRECATED);
30+
}
31+
}
32+
2433
public function getPosition()
2534
{
2635
return 'pre_auth';

src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
parent="security.authentication.listener.abstract"
115115
public="false"
116116
abstract="true">
117+
<deprecated>The "%service_id%" service is deprecated since Symfony 4.2.</deprecated>
117118
</service>
118119

119120
<service id="security.authentication.simple_success_failure_handler" class="Symfony\Component\Security\Http\Authentication\SimpleAuthenticationHandler" abstract="true">
@@ -122,6 +123,7 @@
122123
<argument type="service" id="security.authentication.success_handler" />
123124
<argument type="service" id="security.authentication.failure_handler" />
124125
<argument type="service" id="logger" on-invalid="null" />
126+
<deprecated>The "%service_id%" service is deprecated since Symfony 4.2.</deprecated>
125127
</service>
126128

127129
<service id="security.authentication.listener.simple_preauth" class="Symfony\Component\Security\Http\Firewall\SimplePreAuthenticationListener" abstract="true">
@@ -133,6 +135,7 @@
133135
<argument type="service" id="logger" on-invalid="null" />
134136
<argument type="service" id="event_dispatcher" on-invalid="null"/>
135137
<argument type="service" id="security.authentication.trust_resolver" />
138+
<deprecated>The "%service_id%" service is deprecated since Symfony 4.2.</deprecated>
136139
</service>
137140

138141
<service id="security.authentication.listener.x509" class="Symfony\Component\Security\Http\Firewall\X509AuthenticationListener" abstract="true">
@@ -201,6 +204,7 @@
201204
<argument /> <!-- User Provider -->
202205
<argument /> <!-- Provider-shared Key -->
203206
<argument>null</argument> <!-- UserChecker -->
207+
<deprecated>The "%service_id%" service is deprecated since Symfony 4.2.</deprecated>
204208
</service>
205209

206210
<service id="security.authentication.provider.pre_authenticated" class="Symfony\Component\Security\Core\Authentication\Provider\PreAuthenticatedAuthenticationProvider" abstract="true">

src/Symfony/Bundle/SecurityBundle/SecurityBundle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function build(ContainerBuilder $container)
5454
$extension->addSecurityListenerFactory(new RememberMeFactory());
5555
$extension->addSecurityListenerFactory(new X509Factory());
5656
$extension->addSecurityListenerFactory(new RemoteUserFactory());
57-
$extension->addSecurityListenerFactory(new SimplePreAuthenticationFactory());
58-
$extension->addSecurityListenerFactory(new SimpleFormFactory());
57+
$extension->addSecurityListenerFactory(new SimplePreAuthenticationFactory(false));
58+
$extension->addSecurityListenerFactory(new SimpleFormFactory(false));
5959
$extension->addSecurityListenerFactory(new GuardAuthenticationFactory());
6060

6161
$extension->addUserProviderFactory(new InMemoryFactory());

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,6 @@ public function testFirewalls()
147147
),
148148
null,
149149
),
150-
array(
151-
'simple_auth',
152-
'security.user_checker',
153-
null,
154-
true,
155-
false,
156-
'security.user.provider.concrete.default',
157-
'simple_auth',
158-
'security.authentication.form_entry_point.simple_auth',
159-
null,
160-
null,
161-
array(
162-
'simple_form',
163-
'anonymous',
164-
),
165-
null,
166-
),
167150
), $configs);
168151

169152
$this->assertEquals(array(
@@ -193,13 +176,6 @@ public function testFirewalls()
193176
'security.authentication.listener.anonymous.with_user_checker',
194177
'security.access_listener',
195178
),
196-
array(
197-
'security.channel_listener',
198-
'security.context_listener.2',
199-
'security.authentication.listener.simple_form.simple_auth',
200-
'security.authentication.listener.anonymous.simple_auth',
201-
'security.access_listener',
202-
),
203179
), $listeners);
204180

205181
$this->assertFalse($container->hasAlias('Symfony\Component\Security\Core\User\UserCheckerInterface', 'No user checker alias is registered when custom user checker services are registered'));
@@ -475,6 +451,50 @@ public function testFirewallListenerWithProvider()
475451
$this->addToAssertionCount(1);
476452
}
477453

454+
/**
455+
* @group legacy
456+
* @expectedDeprecation The "simple_form" security listener is deprecated Symfony 4.2, use Guard instead.
457+
*/
458+
public function testSimpleAuth()
459+
{
460+
$container = $this->getContainer('simple_auth');
461+
$arguments = $container->getDefinition('security.firewall.map')->getArguments();
462+
$listeners = array();
463+
$configs = array();
464+
foreach (array_keys($arguments[1]->getValues()) as $contextId) {
465+
$contextDef = $container->getDefinition($contextId);
466+
$arguments = $contextDef->getArguments();
467+
$listeners[] = array_map('strval', $arguments['index_0']->getValues());
468+
469+
$configDef = $container->getDefinition((string) $arguments['index_3']);
470+
$configs[] = array_values($configDef->getArguments());
471+
}
472+
473+
$this->assertSame(array(array(
474+
'simple_auth',
475+
'security.user_checker',
476+
null,
477+
true,
478+
false,
479+
'security.user.provider.concrete.default',
480+
'simple_auth',
481+
'security.authentication.form_entry_point.simple_auth',
482+
null,
483+
null,
484+
array('simple_form', 'anonymous',
485+
),
486+
null,
487+
)), $configs);
488+
489+
$this->assertSame(array(array(
490+
'security.channel_listener',
491+
'security.context_listener.0',
492+
'security.authentication.listener.simple_form.simple_auth',
493+
'security.authentication.listener.anonymous.simple_auth',
494+
'security.access_listener',
495+
)), $listeners);
496+
}
497+
478498
protected function getContainer($file)
479499
{
480500
$file .= '.'.$this->getFileExtension();

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@
8787
'anonymous' => true,
8888
'http_basic' => true,
8989
),
90-
'simple_auth' => array(
91-
'provider' => 'default',
92-
'anonymous' => true,
93-
'simple_form' => array('authenticator' => 'simple_authenticator'),
94-
),
9590
),
9691

9792
'access_control' => array(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
$container->loadFromExtension('security', array(
4+
'providers' => array(
5+
'default' => array(
6+
'memory' => array(
7+
'users' => array(
8+
'foo' => array('password' => 'foo', 'roles' => 'ROLE_USER'),
9+
),
10+
),
11+
),
12+
),
13+
14+
'firewalls' => array(
15+
'simple_auth' => array(
16+
'provider' => 'default',
17+
'anonymous' => true,
18+
'simple_form' => array('authenticator' => 'simple_authenticator'),
19+
),
20+
),
21+
));

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@
6868
<user-checker>app.user_checker</user-checker>
6969
</firewall>
7070

71-
<firewall name="simple_auth" provider="default">
72-
<anonymous />
73-
<simple-form authenticator="simple_authenticator" />
74-
</firewall>
75-
7671
<role id="ROLE_ADMIN">ROLE_USER</role>
7772
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
7873
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sec="http://symfony.com/schema/dic/security"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
7+
8+
<sec:config>
9+
<sec:provider name="default">
10+
<sec:memory>
11+
<sec:user name="foo" password="foo" roles="ROLE_USER" />
12+
</sec:memory>
13+
</sec:provider>
14+
15+
<sec:firewall name="simple_auth">
16+
<sec:simple_form authenticator="simple_authenticator"/>
17+
<sec:anonymous/>
18+
</sec:firewall>
19+
</sec:config>
20+
21+
</container>

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ security:
7070
http_basic: ~
7171
user_checker: app.user_checker
7272

73-
simple_auth:
74-
provider: default
75-
anonymous: ~
76-
simple_form: { authenticator: simple_authenticator }
77-
7873
role_hierarchy:
7974
ROLE_ADMIN: ROLE_USER
8075
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
security:
2+
providers:
3+
default:
4+
memory:
5+
users:
6+
foo: { password: foo, roles: ROLE_USER }
7+
8+
firewalls:
9+
simple_auth:
10+
provider: default
11+
anonymous: ~
12+
simple_form: { authenticator: simple_authenticator }

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ CHANGELOG
1313
or `Symfony\Component\Security\Core\Authentication\Token\RememberMeToken`.
1414
* allow passing null as $filter in LdapUserProvider to get the default filter
1515
* accessing the user object that is not an instance of `UserInterface` from `Security::getUser()` is deprecated
16+
* Deprecated `SimpleAuthenticatorInterface`, `SimpleFormAuthenticatorInterface`,
17+
`SimplePreAuthenticatorInterface`, `SimpleAuthenticationProvider`, `SimpleAuthenticationHandler`,
18+
`SimpleFormAuthenticationListener` and `SimplePreAuthenticationListener`. Use Guard instead.
1619

1720
4.1.0
1821
-----

src/Symfony/Component/Security/Core/Authentication/Provider/SimpleAuthenticationProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
use Symfony\Component\Security\Core\User\UserInterface;
2020
use Symfony\Component\Security\Core\User\UserProviderInterface;
2121

22+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.2, use Guard instead.', SimpleAuthenticationProvider::class), E_USER_DEPRECATED);
23+
2224
/**
2325
* @author Jordi Boggiano <j.boggiano@seld.be>
26+
*
27+
* @deprecated since Symfony 4.2, use Guard instead.
2428
*/
2529
class SimpleAuthenticationProvider implements AuthenticationProviderInterface
2630
{

src/Symfony/Component/Security/Core/Authentication/SimpleAuthenticatorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
/**
1818
* @author Jordi Boggiano <j.boggiano@seld.be>
19+
*
20+
* @deprecated since Symfony 4.2, use Guard instead.
1921
*/
2022
interface SimpleAuthenticatorInterface
2123
{

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/SimpleAuthenticationProviderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Symfony\Component\Security\Core\Exception\LockedException;
1818
use Symfony\Component\Security\Core\User\UserChecker;
1919

20+
/**
21+
* @group legacy
22+
*/
2023
class SimpleAuthenticationProviderTest extends TestCase
2124
{
2225
/**

src/Symfony/Component/Security/Http/Authentication/SimpleAuthenticationHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1919
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2020

21+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.2, use Guard instead.', SimpleAuthenticationHandler::class), E_USER_DEPRECATED);
22+
2123
/**
2224
* Class to proxy authentication success/failure handlers.
2325
*
@@ -26,6 +28,8 @@
2628
* the default handlers are triggered.
2729
*
2830
* @author Jordi Boggiano <j.boggiano@seld.be>
31+
*
32+
* @deprecated since Symfony 4.2, use Guard instead.
2933
*/
3034
class SimpleAuthenticationHandl 3DC7 er implements AuthenticationFailureHandlerInterface, AuthenticationSuccessHandlerInterface
3135
{

0 commit comments

Comments
 (0)
0