8000 feature #13323 [Security] removed usage of the deprecated SecurityCon… · symfony/symfony@e104595 · GitHub
[go: up one dir, main page]

Skip to content

Commit e104595

Browse files
committed
feature #13323 [Security] removed usage of the deprecated SecurityContextInterface (fabpot)
This PR was merged into the 2.7 branch. Discussion ---------- [Security] removed usage of the deprecated SecurityContextInterface | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This PR removed internal usage of SecurityContextInterface in favor of the new alternatives, it also fixes removes as many deprecation notices as possible for the Security component. Commits ------- ba71b68 added type-hint 91d01d8 [Security] removed usage of the deprecated SecurityContextInterface
2 parents 50ed09e + ba71b68 commit e104595

File tree

49 files changed

+361
-375
lines changed

Some content is hidden

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

49 files changed

+361
-375
lines changed

src/Symfony/Bridge/Twig/Extension/SecurityExtension.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Extension;
1313

1414
use Symfony\Component\Security\Acl\Voter\FieldVote;
15-
use Symfony\Component\Security\Core\SecurityContextInterface;
15+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1616

1717
/**
1818
* SecurityExtension exposes security context features.
@@ -21,24 +21,24 @@
2121
*/
2222
class SecurityExtension extends \Twig_Extension
2323
{
24-
private $context;
24+
private $securityChecker;
2525

26-
public function __construct(SecurityContextInterface $context = null)
26+
public function __construct(AuthorizationCheckerInterface $securityChecker = null)
2727
{
28-
$this->context = $context;
28+
$this->securityChecker = $securityChecker;
2929
}
3030

3131
public function isGranted($role, $object = null, $field = null)
3232
{
33-
if (null === $this->context) {
33+
if (null === $this->securityChecker) {
3434
return false;
3535
}
3636

3737
if (null !== $field) {
3838
$object = new FieldVote($object, $field);
3939
}
4040

41-
return $this->context->isGranted($role, $object);
41+
return $this->securityChecker->isGranted($role, $object);
4242
}
4343

4444
/**

src/Symfony/Bridge/Twig/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20-
"symfony/security-csrf": "~2.4|~3.0.0",
20+
"symfony/security-csrf": "~2.6|~3.0.0",
2121
"twig/twig": "~1.13,>=1.13.1"
2222
},
2323
"require-dev": {
@@ -29,7 +29,7 @@
2929
"symfony/templating": "~2.1|~3.0.0",
3030
"symfony/translation": "~2.2|~3.0.0",
3131
"symfony/yaml": "~2.0,>=2.0.5|~3.0.0",
32-
"symfony/security": "~2.4|~3.0.0",
32+
"symfony/security": "~2.6|~3.0.0",
3333
"symfony/stopwatch": "~2.2|~3.0.0",
3434
"symfony/console": "~2.4|~3.0.0",
3535
"symfony/var-dumper": "~2.6|~3.0.0",

src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
1313
<tag name="form.type_extension" alias="form" />
14-
<argument type="service" id="form.csrf_provider" />
14+
<argument type="service" id="security.csrf.token_manager" />
1515
<argument>%form.type_extension.csrf.enabled%</argument>
1616
<argument>%form.type_extension.csrf.field_name%</argument>
1717
<argument type="service" id="translator.default" />

src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115

116116
<service id="templating.form.renderer" class="%templating.form.renderer.class%" public="false">
117117
<argument type="service" id="templating.form.engine" />
118-
<argument type="service" id="form.csrf_provider" on-invalid="null" />
118+
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
119119
</service>
120120

121121
<service id="templating.globals" class="%templating.globals.class%">

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<services>
5353
<service id="security.authentication.listener.anonymous" class="%security.authentication.listener.anonymous.class%" public="false">
5454
<tag name="monolog.logger" channel="security" />
55-
<argument type="service" id="security.context" />
55+
<argument type="service" id="security.token_storage" />
5656
<argument /> <!-- Key -->
5757
<argument type="service" id="logger" on-invalid="null" />
5858
<argument type="service" id="security.authentication.manager" />
@@ -82,15 +82,15 @@
8282

8383
<service id="security.context_listener" class="%security.context_listener.class%" public="false">
8484
<tag name="monolog.logger" channel="security" />
85-
<argument type="service" id="security.context" />
85+
<argument type="service" id="security.token_storage" />
8686
<argument type="collection"></argument>
8787
<argument /> <!-- Provider Key -->
8888
<argument type="service" id="logger" on-invalid="null" />
8989
<argument type="service" id="event_dispatcher" on-invalid="null"/>
9090
</service>
9191

9292
<service id="security.logout_listener" class="%security.logout_listener.class%" public="false" abstract="true">
93-
<argument type="service" id="security.context" />
93+
<argument type="service" id="security.token_storage" />
9494
<argument type="service" id="security.http_utils" />
9595
<argument type="service" id="security.logout.success_handler" />
9696
<argument /> <!-- Options -->
@@ -109,7 +109,7 @@
109109

110110
<service id="security.authentication.listener.abstract" abstract="true" public="false">
111111
<tag name="monolog.logger" channel="security" />
112-
<argument type="service" id="security.context" />
112+
<argument type="service" id="security.token_storage" />
113113
<argument type="service" id="security.authentication.manager" />
114114
<argument type="service" id="security.authentication.session_strategy" />
115115
<argument type="service" id="security.http_utils" />
@@ -167,7 +167,7 @@
167167

168168
<service id="security.authentication.listener.simple_preauth" class="%security.authentication.listener.simple_preauth.class%" public="false" abstract="true">
169169
<tag name="monolog.logger" channel="security" />
170-
<argument type="service" id="security.context" />
170+
<argument type="service" id="security.token_storage" />
171171
<argument type="service" id="security.authentication.manager" />
172172
<argument /> <!-- Provider-shared Key -->
173173
<argument /> <!-- Authenticator -->
@@ -177,7 +177,7 @@
177177

178178
<service id="security.authentication.listener.x509" class="%security.authentication.listener.x509.class%" public="false" abstract="true">
179179
<tag name="monolog.logger" channel="security" />
180-
<argument type="service" id="security.context" />
180+
<argument type="service" id="security.token_storage" />
181181
<argument type="service" id="security.authentication.manager" />
182182
<argument /> <!-- Provider-shared Key -->
183183
<argument /> <!-- x509 user -->
@@ -188,7 +188,7 @@
188188

189189
<service id="security.authentication.listener.remote_user" class="Symfony\Component\Security\Http\Firewall\RemoteUserAuthenticationListener" public="false" abstract="true">
190190
<tag name="monolog.logger" channel="security" />
191-
<argument type="service" id="security.context" />
191+
<argument type="service" id="security.token_storage" />
192192
<argument type="service" id="security.authentication.manager" />
193193
<argument /> <!-- Provider-shared Key -->
194194
<argument /> <!-- REMOTE_USER server env var -->
@@ -198,7 +198,7 @@
198198

199199
<service id="security.authentication.listener.basic" class="%security.authentication.listener.basic.class%" public="false" abstract="true">
200200
<tag name="monolog.logger" channel="security" />
201-
<argument type="service" id="security.context" />
201+
<argument type="service" id="security.token_storage" />
202202
<argument type="service" id="security.authentication.manager" />
203203
<argument /> <!-- Provider-shared Key -->
204204
<argument /> <!-- Entry Point -->
@@ -207,7 +207,7 @@
207207

208208
<service id="security.authentication.listener.digest" class="%security.authentication.listener.digest.class%" public="false" abstract="true">
209209
<tag name="monolog.logger" channel="security" />
210-
<argument type="service" id="security.context" />
210+
<argument type="service" id="security.token_storage" />
211211
<argument /> <!-- User Provider -->
212212
<argument /> <!-- Provider-shared Key -->
213213
<argument /> <!-- Entry Point -->
@@ -235,7 +235,7 @@
235235

236236
<service id="security.exception_listener" class="%security.exception_listener.class%" public="false" abstract="true">
237237
<tag name="monolog.logger" channel="security" />
238-
<argument type="service" id="security.context"< 10000 /span> />
238+
<argument type="service" id="security.token_storage" />
239239
<argument type="service" id="security.authentication.trust_resolver" />
240240
<argument type="service" id="security.http_utils" />
241241
<argument />
@@ -247,7 +247,7 @@
247247

248248
<service id="security.authentication.switchuser_listener" class="%security.authentication.switchuser_listener.class%" public="false" abstract="true">
249249
<tag name="monolog.logger" channel="security" />
250-
<argument type="service" id="security.context" />
250+
<argument type="service" id="security.token_storage" />
251251
<argument /> <!-- User Provider -->
252252
<argument type="service" id="security.user_checker" />
253253
<argument /> <!-- Provider Key -->
@@ -260,7 +260,7 @@
260260

261261
<service id="security.access_listener" class="%security.access_listener.class%" public="false">
262262
<tag name="monolog.logger" channel="security" />
263-
<argument type="service" id="security.context" />
263+
<argument type="service" id="security.token_storage" />
264264
<argument type="service" id="security.access.decision_manager" />
265265
<argument type="service" id="security.access_map" />
266266
<argument type="service" id="security.authentication.manager" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<services>
2020
<service id="security.authentication.listener.rememberme" class="%security.authentication.listener.rememberme.class%" public="false" abstract="true">
2121
<tag name="monolog.logger" channel="security" />
22-
<argument type="service" id="security.context" />
22+
<argument type="service" id="security.token_storage" />
2323
<argument type="service" id="security.authentication.rememberme" />
2424
<argument type="service" id="security.authentication.manager" />
2525
<argument type="service" id="logger" on-invalid="null" />

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

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

1919
<service id="templating.helper.security" class="%templating.helper.security.class%">
2020
<tag name="templating.helper" alias="security" />
21-
<argument type="service" id="security.context" on-invalid="ignore" />
21+
<argument type="service" id="security.authorization_checker" on-invalid="ignore" />
2222
</service>
2323
</services>
2424
</container>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<service id="twig.extension.security" class="%twig.extension.security.class%" public="false">
1919
<tag name="twig.extension" />
20-
<argument type="service" id="security.context" on-invalid="ignore" />
20+
<argument type="service" id="security.authorization_checker" on-invalid="ignore" />
2121
</service>
2222
</services>
2323
</container>

src/Symfony/Bundle/SecurityBundle/Templating/Helper/SecurityHelper.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,33 @@
1313

1414
use Symfony\Component\Security\Acl\Voter\FieldVote;
1515
use Symfony\Component\Templating\Helper\Helper;
16-
use Symfony\Component\Security\Core\SecurityContextInterface;
16+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1717

1818
/**
19-
* SecurityHelper provides read-only access to the security context.
19+
* SecurityHelper provides read-only access to the security checker.
2020
*
2121
* @author Fabien Potencier <fabien@symfony.com>
2222
*/
2323
class SecurityHelper extends Helper
2424
{
25-
private $context;
25+
private $securityChecker;
2626

27-
/**
28-
* Constructor.
29-
*
30-
* @param SecurityContextInterface $context A SecurityContext instance
31-
*/
32-
public function __construct(SecurityContextInterface $context = null)
27+
public function __construct(AuthorizationCheckerInterface $securityChecker = null)
3328
{
34-
$this->context = $context;
29+
$this->securityChecker = $securityChecker;
3530
}
3631

3732
public function isGranted($role, $object = null, $field = null)
3833
{
39-
if (null === $this->context) {
34+
if (null === $this->securityChecker) {
4035
return false;
4136
}
4237

4338
if (null !== $field) {
4439
$object = new FieldVote($object, $field);
4540
}
4641

47-
return $this->context->isGranted($role, $object);
42+
return $this->securityChecker->isGranted($role, $object);
4843
}
4944

5045
/**

src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function testCollectWhenSecurityIsDisabled()
2525
$this->assertEmpty($collector->getUser());
2626
}
2727

28-
/** @dataProvider provideTokenStorage */
29-
public function testCollectWhenAuthenticationTokenIsNull($tokenStorage)
28+
public function testCollectWhenAuthenticationTokenIsNull()
3029
{
30+
$tokenStorage = new TokenStorage();
3131
$collector = new SecurityDataCollector($tokenStorage, $this->getRoleHierarchy());
3232
$collector->collect($this->getRequest(), $this->getResponse());
3333

@@ -40,12 +40,21 @@ public function testCollectWhenAuthenticationTokenIsNull($tokenStorage)
4040
$this->assertEmpty($collector->getUser());
4141
}
4242

43-
public function provideTokenStorage()
43+
public function testLegacyCollectWhenAuthenticationTokenIsNull()
4444
{
45-
return array(
46-
array(new TokenStorage()),
47-
array($this->getMock('Symfony\Component\Security\Core\SecurityContextInterface')),
48-
);
45+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
46+
47+
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
48+
$collector = new SecurityDataCollector($tokenStorage, $this->getRoleHierarchy());
49+
$collector->collect($this->getRequest(), $this->getResponse());
50+
51+
$this->assertTrue($collector->isEnabled());
52+
$this->assertFalse($collector->isAuthenticated());
53+
$this->assertNull($collector->getTokenClass());
54+
$this->assertTrue($collector->supportsRoleHierarchy());
55+
$this->assertCount(0, $collector->getRoles());
56+
$this->assertCount(0, $collector->getInheritedRoles());
57+
$this->assertEmpty($collector->getUser());
4958
}
5059

5160
/** @dataProvider provideRoles */

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LocalizedController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
1313

14-
use Symfony\Component\Security\Core\SecurityContext;
14+
use Symfony\Component\Security\Core\Security;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\DependencyInjection\ContainerAware;
@@ -21,15 +21,15 @@ class LocalizedController extends ContainerAware
2121
public function loginAction(Request $request)
2222
{
2323
// get the login error if there is one
24-
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
25-
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
24+
if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
25+
$error = $request->attributes->get(Security::AUTHENTICATION_ERROR);
2626
} else {
27-
$error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
27+
$error = $request->getSession()->get(Security::AUTHENTICATION_ERROR);
2828
}
2929

3030
return $this->container->get('templating')->renderResponse('FormLoginBundle:Localized:login.html.twig', array(
3131
// last username entered by the user
32-
'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
32+
'last_username' => $request->getSession()->get(Security::LAST_USERNAME),
3333
'error' => $error,
3434
));
3535
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LoginController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
17-
use Symfony\Component\Security\Core\SecurityContext;
17+
use Symfony\Component\Security\Core\Security;
1818
use Symfony\Component\DependencyInjection\ContainerAware;
1919

2020
class LoginController extends ContainerAware
2121
{
2222
public function loginAction(Request $request)
2323
{
2424
// get the login error if there is one
25-
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
26-
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
25+
if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
26+
$error = $request->attributes->get(Security::AUTHENTICATION_ERROR);
2727
} else {
28-
$error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
28+
$error = $request->getSession()->get(Security::AUTHENTICATION_ERROR);
2929
}
3030

3131
return $this->container->get('templating')->renderResponse('FormLoginBundle:Login:login.html.twig', array(
3232
// last username entered by the user
33-
'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
33+
'last_username' => $request->getSession()->get(Security::LAST_USERNAME),
3434
'error' => $error,
3535
));
3636
}

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20-
"symfony/security": "~2.6|~3.0.0",
20+
"symfony/security": "~2.7|~3.0.0",
2121
"symfony/http-kernel": "~2.2|~3.0.0"
2222
},
2323
"require-dev": {

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114

115115
<service id="twig.form.renderer" class="%twig.form.renderer.class%" public="false">
116116
<argument type="service" id="twig.form.engine" />
117-
<argument type="service" id="form.csrf_provider" on-invalid="null" />
117+
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
118118
</service>
119119

120120
<service id="twig.translation.extractor" class="%twig.translation.extractor.class%">

0 commit comments

Comments
 (0)
0