Skip to content

Commit 6d521d4

Browse files
committed
feature #37942 [Security] Renamed provider key to firewall name (wouterj)
This PR was merged into the 5.2-dev branch. Discussion ---------- [Security] Renamed provider key to firewall name | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Fix #15207 | License | MIT | Doc PR | tbd This fixes the `$providerKey` argument names on the classes that will remain in use, even when the new Security system will take over. @fabpot do you think these changes are worth it? Officially, all token classes are not marked as `@final`. Do I need to take into account when someone is overriding the `getProviderKey()` method? Also, I couldn't find a way to trigger a deprecation notice for deprecated properties, is this a problem? Commits ------- 91b2763 Renamed $providerKey to $firewallName
2 parents c642b8f + 91b2763 commit 6d521d4

File tree

42 files changed

+195
-109
lines changed

Some content is hidden

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

42 files changed

+195
-109
lines changed

UPGRADE-5.2.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ Security
7474

7575
* [BC break] `AccessListener::PUBLIC_ACCESS` has been removed in favor of
7676
`AuthenticatedVoter::PUBLIC_ACCESS`.
77+
78+
* Deprecated `setProviderKey()`/`getProviderKey()` in favor of `setFirewallName()/getFirewallName()`
79+
in `PreAuthenticatedToken`, `RememberMeToken`, `SwitchUserToken`, `UsernamePasswordToken`,
80+
`DefaultAuthenticationSuccessHandler`, the old methods will be removed in 6.0.
81+
82+
* Deprecated the `AbstractRememberMeServices::$providerKey` property in favor of
83+
`AbstractRememberMeServices::$firewallName`, the old property will be removed
84+
in 6.0.
85+

UPGRADE-6.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ Security
133133
* Removed `LogoutSuccessHandlerInterface` and `LogoutHandlerInterface`, register a listener on the `LogoutEvent` event instead.
134134
* Removed `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
135135
* Added a `logout(Request $request, Response $response, TokenInterface $token)` method to the `RememberMeServicesInterface`.
136+
* Removed `setProviderKey()`/`getProviderKey()` in favor of `setFirewallName()/getFirewallName()`
137+
in `PreAuthenticatedToken`, `RememberMeToken`, `SwitchUserToken`, `UsernamePasswordToken`,
138+
`DefaultAuthenticationSuccessHandler`.
139+
* Removed the `AbstractRememberMeServices::$providerKey` property in favor of `AbstractRememberMeServices::$firewallName`
136140

137141
TwigBundle
138142
----------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected function createAuthenticationSuccessHandler(ContainerBuilder $containe
170170
} else {
171171
$successHandler = $container->setDefinition($successHandlerId, new ChildDefinition('security.authentication.success_handler'));
172172
$successHandler->addMethodCall('setOptions', [$options]);
173-
$successHandler->addMethodCall('setProviderKey', [$id]);
173+
$successHandler->addMethodCall('setFirewallName', [$id]);
174174
}
175175

176176
return $successHandlerId;

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Security/Factory/AbstractFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testDefaultSuccessHandler($serviceId, $defaultHandlerInjection)
110110
if ($defaultHandlerInjection) {
111111
$this->assertEquals('setOptions', $methodCalls[0][0]);
112112
$this->assertEquals(['default_target_path' => '/bar'], $methodCalls[0][1][0]);
113-
$this->assertEquals('setProviderKey', $methodCalls[1][0]);
113+
$this->assertEquals('setFirewallName', $methodCalls[1][0]);
114114
$this->assertEquals(['foo'], $methodCalls[1][1]);
115115
} else {
116116
$this->assertCount(0, $methodCalls);

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Changed `AuthorizationChecker` to call the access decision manager in unauthenticated sessions with a `NullToken`
99
* [BC break] Removed `AccessListener::PUBLIC_ACCESS` in favor of `AuthenticatedVoter::PUBLIC_ACCESS`
1010
* Added `Passport` to `LoginFailureEvent`.
11+
* Deprecated `setProviderKey()`/`getProviderKey()` in favor of `setFirewallName()/getFirewallName()` in `PreAuthenticatedToken`, `RememberMeToken`, `SwitchUserToken`, `UsernamePasswordToken`, `DefaultAuthenticationSuccessHandler`; and deprecated the `AbstractRememberMeServices::$providerKey` property in favor of `AbstractRememberMeServices::$firewallName`
1112

1213
5.1.0
1314
-----

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public function authenticate(TokenInterface $token)
6969
*/
7070
public function supports(TokenInterface $token)
7171
{
72-
return $token instanceof PreAuthenticatedToken && $this->providerKey === $token->getProviderKey();
72+
return $token instanceof PreAuthenticatedToken && $this->providerKey === $token->getFirewallName();
7373
}
7474
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public function authenticate(TokenInterface $token)
6969
*/
7070
public function supports(TokenInterface $token)
7171
{
72-
return $token instanceof RememberMeToken && $token->getProviderKey() === $this->providerKey;
72+
return $token instanceof RememberMeToken && $token->getFirewallName() === $this->providerKey;
7373
}
7474
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function authenticate(TokenInterface $token)
103103
*/
104104
public function supports(TokenInterface $token)
105105
{
106-
return $token instanceof UsernamePasswordToken && $this->providerKey === $token->getProviderKey();
106+
return $token instanceof UsernamePasswordToken && $this->providerKey === $token->getFirewallName();
107107
}
108108

109109
/**

src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@
2121
class PreAuthenticatedToken extends AbstractToken
2222
{
2323
private $credentials;
24-
private $providerKey;
24+
private $firewallName;
2525

2626
/**
2727
* @param string|\Stringable|UserInterface $user
2828
* @param mixed $credentials
2929
* @param string[] $roles
3030
*/
31-
public function __construct($user, $credentials, string $providerKey, array $roles = [])
31+
public function __construct($user, $credentials, string $firewallName, array $roles = [])
3232
{
3333
parent::__construct($roles);
3434

35-
if (empty($providerKey)) {
36-
throw new \InvalidArgumentException('$providerKey must not be empty.');
35+
if ('' === $firewallName) {
36+
throw new \InvalidArgumentException('$firewallName must not be empty.');
3737
}
3838

3939
$this->setUser($user);
4040
$this->credentials = $credentials;
41-
$this->providerKey = $providerKey;
41+
$this->firewallName = $firewallName;
4242

4343
if ($roles) {
4444
$this->setAuthenticated(true);
@@ -49,10 +49,21 @@ public function __construct($user, $credentials, string $providerKey, array $rol
4949
* Returns the provider key.
5050
*
5151
* @return string The provider key
52+
*
53+
* @deprecated since 5.2, use getFirewallName() instead
5254
*/
5355
public function getProviderKey()
5456
{
55-
return $this->providerKey;
57+
if (1 !== \func_num_args() || true !== func_get_arg(0)) {
58+
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s" is deprecated, use "getFirewallName()" instead.', __METHOD__);
59+
}
60+
61+
return $this->firewallName;
62+
}
63+
64+
public function getFirewallName(): string
65+
{
66+
return $this->getProviderKey(true);
5667
}
5768

5869
/**
@@ -78,15 +89,15 @@ public function eraseCredentials()
7889
*/
7990
public function __serialize(): array
8091
{
81-
return [$this->credentials, $this->providerKey, parent::__serialize()];
92+
return [$this->credentials, $this->firewallName, parent::__serialize()];
8293
}
8394

8495
/**
8596
* {@inheritdoc}
8697
*/
8798
public function __unserialize(array $data): void
8899
{
89-
[$this->credentials, $this->providerKey, $parentData] = $data;
100+
[$this->credentials, $this->firewallName, $parentData] = $data;
90101
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
91102
parent::__unserialize($parentData);
92103
}

src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
class RememberMeToken extends AbstractToken
2222
{
2323
private $secret;
24-
private $providerKey;
24+
private $firewallName;
2525

2626
/**
2727
* @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
2828
*
2929
* @throws \InvalidArgumentException
3030
*/
31-
public function __construct(UserInterface $user, string $providerKey, string $secret)
31+
public function __construct(UserInterface $user, string $firewallName, string $secret)
3232
{
3333
parent::__construct($user->getRoles());
3434

3535
if (empty($secret)) {
3636
throw new \InvalidArgumentException('$secret must not be empty.');
3737
}
3838

39-
if (empty($providerKey)) {
40-
throw new \InvalidArgumentException('$providerKey must not be empty.');
39+
if ('' === $firewallName) {
40+
throw new \InvalidArgumentException('$firewallName must not be empty.');
4141
}
4242

43-
$this->providerKey = $providerKey;
43+
$this->firewallName = $firewallName;
4444
$this->secret = $secret;
4545

4646
$this->setUser($user);
@@ -63,10 +63,21 @@ public function setAuthenticated(bool $authenticated)
6363
* Returns the provider secret.
6464
*
6565
* @return string The provider secret
66+
*
67+
* @deprecated since 5.2, use getFirewallName() instead
6668
*/
6769
public function getProviderKey()
6870
{
69-
return $this->providerKey;
71+
if (1 !== \func_num_args() || true !== func_get_arg(0)) {
72+
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s" is deprecated, use "getFirewallName()" instead.', __METHOD__);
73+
}
74+
75+
return $this->firewallName;
76+
}
77+
78+
public function getFirewallName(): string
79+
{
80+
return $this->getProviderKey(true);
7081
}
7182

7283
/**
@@ -92,15 +103,15 @@ public function getCredentials()
92103
*/
93104
public function __serialize(): array
94105
{
95-
return [$this->secret, $this->providerKey, parent::__serialize()];
106+
return [$this->secret, $this->firewallName, parent::__serialize()];
96107
}
97108

98109
/**
99110
* {@inheritdoc}
100111
*/
101112
public function __unserialize(array $data): void
102113
{
103-
[$this->secret, $this->providerKey, $parentData] = $data;
114+
[$this->secret, $this->firewallName, $parentData] = $data;
104115
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
105116
parent::__unserialize($parentData);
106117
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy