Skip to content

Commit 1554d02

Browse files
committed
Renamed $providerKey to $firewallName
1 parent 684b5f0 commit 1554d02

15 files changed

+77
-46
lines changed

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
}

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
}

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
/**

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
}

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
}

Authentication/Token/SwitchUserToken.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ class SwitchUserToken extends UsernamePasswordToken
2323
/**
2424
* @param string|object $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method
2525
* @param mixed $credentials This usually is the password of the user
26-
* @param string $providerKey The provider key
27-
* @param string[] $roles An array of roles
2826
*
2927
* @throws \InvalidArgumentException
3028
*/
31-
public function __construct($user, $credentials, string $providerKey, array $roles, TokenInterface $originalToken)
29+
public function __construct($user, $credentials, string $firewallName, array $roles, TokenInterface $originalToken)
3230
{
33-
parent::__construct($user, $credentials, $providerKey, $roles);
31+
parent::__construct($user, $credentials, $firewallName, $roles);
3432

3533
$this->originalToken = $originalToken;
3634
}

Authentication/Token/UsernamePasswordToken.php

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

2626
/**
2727
* @param string|\Stringable|UserInterface $user The username (like a nickname, email address, etc.) or a UserInterface instance
@@ -30,17 +30,17 @@ class UsernamePasswordToken extends AbstractToken
3030
*
3131
* @throws \InvalidArgumentException
3232
*/
33-
public function __construct($user, $credentials, string $providerKey, array $roles = [])
33+
public function __construct($user, $credentials, string $firewallName, array $roles = [])
3434
{
3535
parent::__construct($roles);
3636

37-
if (empty($providerKey)) {
38-
throw new \InvalidArgumentException('$providerKey must not be empty.');
37+
if ('' === $firewallName) {
38+
throw new \InvalidArgumentException('$firewallName must not be empty.');
3939
}
4040

4141
$this->setUser($user);
4242
$this->credentials = $credentials;
43-
$this->providerKey = $providerKey;
43+
$this->firewallName = $firewallName;
4444

4545
parent::setAuthenticated(\count($roles) > 0);
4646
}
@@ -69,10 +69,21 @@ public function getCredentials()
6969
* Returns the provider key.
7070
*
7171
* @return string The provider key
72+
*
73+
* @deprecated since 5.2, use getFirewallName() instead
7274
*/
7375
public function getProviderKey()
7476
{
75-
return $this->providerKey;
77+
if (1 !== \func_num_args() || true !== func_get_arg(0)) {
78+
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s" is deprecated, use "getFirewallName()" instead.', __METHOD__);
79+
}
80+
81+
return $this->firewallName;
82+
}
83+
84+
public function getFirewallName(): string
85+
{
86+
return $this->getProviderKey(true);
7687
}
7788

7889
/**
@@ -90,15 +101,15 @@ public function eraseCredentials()
90101
*/
91102
public function __serialize(): array
92103
{
93-
return [$this->credentials, $this->providerKey, parent::__serialize()];
104+
return [$this->credentials, $this->firewallName, parent::__serialize()];
94105
}
95106

96107
/**
97108
* {@inheritdoc}
98109
*/
99110
public function __unserialize(array $data): void
100111
{
101-
[$this->credentials, $this->providerKey, $parentData] = $data;
112+
[$this->credentials, $this->firewallName, $parentData] = $data;
102113
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
103114
parent::__unserialize($parentData);
104115
}

Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testSupports()
3030
;
3131
$token
3232
->expects($this->once())
33-
->method('getProviderKey')
33+
->method('getFirewallName')
3434
->willReturn('foo')
3535
;
3636
$this->assertFalse($provider->supports($token));
@@ -65,7 +65,7 @@ public function testAuthenticate()
6565
$token = $provider->authenticate($this->getSupportedToken('fabien', 'pass'));
6666
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken', $token);
6767
$this->assertEquals('pass', $token->getCredentials());
68-
$this->assertEquals('key', $token->getProviderKey());
68+
$this->assertEquals('key', $token->getFirewallName());
6969
$this->assertEquals([], $token->getRoleNames());
7070
$this->assertEquals(['foo' => 'bar'], $token->getAttributes(), '->authenticate() copies token attributes');
7171
$this->assertSame($user, $token->getUser());
@@ -89,7 +89,7 @@ public function testAuthenticateWhenUserCheckerThrowsException()
8989

9090
protected function getSupportedToken($user = false, $credentials = false)
9191
{
92-
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken')->setMethods(['getUser', 'getCredentials', 'getProviderKey'])->disableOriginalConstructor()->getMock();
92+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken')->setMethods(['getUser', 'getCredentials', 'getFirewallName'])->disableOriginalConstructor()->getMock();
9393
if (false !== $user) {
9494
$token->expects($this->once())
9595
->method('getUser')
@@ -105,7 +105,7 @@ protected function getSupportedToken($user = false, $credentials = false)
105105

106106
$token
107107
->expects($this->any())
108-
->method('getProviderKey')
108+
->method('getFirewallName')
109109
->willReturn('key')
110110
;
111111

Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ protected function getSupportedToken($user = null, $secret = 'test')
9999
->willReturn([]);
100100
}
101101

102-
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->setMethods(['getProviderKey'])->setConstructorArgs([$user, 'foo', $secret])->getMock();
102+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->setMethods(['getFirewallName'])->setConstructorArgs([$user, 'foo', $secret])->getMock();
103103
$token
104104
->expects($this->once())
105-
->method('getProviderKey')
105+
->method('getFirewallName')
106106
->willReturn('foo');
107107

108108
return $token;

Tests/Authentication/Provider/UserAuthenticationProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ public function testAuthenticatePreservesOriginalToken()
202202

203203
protected function getSupportedToken()
204204
{
205-
$mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')->setMethods(['getCredentials', 'getProviderKey', 'getRoles'])->disableOriginalConstructor()->getMock();
205+
$mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')->setMethods(['getCredentials', 'getFirewallName', 'getRoles'])->disableOriginalConstructor()->getMock();
206206
$mock
207207
->expects($this->any())
208-
->method('getProviderKey')
208+
->method('getFirewallName')
209209
->willReturn('key')
210210
;
211211

0 commit comments

Comments
 (0)