Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8c46b95

Browse filesBrowse files
committed
[Security] Added type-hints to auth providers, tokens and voters.
1 parent cc9778e commit 8c46b95
Copy full SHA for 8c46b95

17 files changed

+40
-64
lines changed

‎src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Connection $conn)
4848
/**
4949
* {@inheritdoc}
5050
*/
51-
public function loadTokenBySeries($series)
51+
public function loadTokenBySeries(string $series)
5252
{
5353
// the alias for lastUsed works around case insensitivity in PostgreSQL
5454
$sql = 'SELECT class, username, value, lastUsed AS last_used'
@@ -68,7 +68,7 @@ public function loadTokenBySeries($series)
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function deleteTokenBySeries($series)
71+
public function deleteTokenBySeries(string $series)
7272
{
7373
$sql = 'DELETE FROM rememberme_token WHERE series=:series';
7474
$paramValues = ['series' => $series];
@@ -79,7 +79,7 @@ public function deleteTokenBySeries($series)
7979
/**
8080
* {@inheritdoc}
8181
*/
82-
public function updateToken($series, $tokenValue, \DateTime $lastUsed)
82+
public function updateToken(string $series, string $tokenValue, \DateTime $lastUsed)
8383
{
8484
$sql = 'UPDATE rememberme_token SET value=:value, lastUsed=:lastUsed'
8585
.' WHERE series=:series';

‎src/Symfony/Bridge/Doctrine/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/composer.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"symfony/property-access": "^4.4|^5.0",
3434
"symfony/property-info": "^4.4|^5.0",
3535
"symfony/proxy-manager-bridge": "^4.4|^5.0",
36-
"symfony/security-core": "^4.4|^5.0",
36+
"symfony/security-core": "^5.0",
3737
"symfony/expression-language": "^4.4|^5.0",
3838
"symfony/validator": "^4.4|^5.0",
3939
"symfony/translation": "^4.4|^5.0",
@@ -49,7 +49,8 @@
4949
"phpunit/phpunit": "<5.4.3",
5050
"symfony/dependency-injection": "<4.4",
5151
"symfony/form": "<4.4",
52-
"symfony/messenger": "<4.4"
52+
"symfony/messenger": "<4.4",
53+
"symfony/security-core": "<5"
5354
},
5455
"suggest": {
5556
"symfony/form": "",

‎src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
6363
/**
6464
* {@inheritdoc}
6565
*/
66-
protected function retrieveUser($username, UsernamePasswordToken $token)
66+
protected function retrieveUser(string $username, UsernamePasswordToken $token)
6767
{
6868
$user = $token->getUser();
6969
if ($user instanceof UserInterface) {

‎src/Symfony/Component/Security/Core/Authentication/Provider/LdapBindAuthenticationProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/Provider/LdapBindAuthenticationProvider.php
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ public function __construct(UserProviderInterface $userProvider, UserCheckerInte
4646

4747
/**
4848
* Set a query string to use in order to find a DN for the username.
49-
*
50-
* @param string $queryString
5149
*/
52-
public function setQueryString($queryString)
50+
public function setQueryString(string $queryString)
5351
{
5452
$this->queryString = $queryString;
5553
}
5654

5755
/**
5856
* {@inheritdoc}
5957
*/
60-
protected function retrieveUser($username, UsernamePasswordToken $token)
58+
protected function retrieveUser(string $username, UsernamePasswordToken $token)
6159
{
6260
if (AuthenticationProviderInterface::USERNAME_NONE_PROVIDED === $username) {
6361
throw new UsernameNotFoundException('Username can not be null');

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,11 @@ public function supports(TokenInterface $token)
109109
/**
110110
* Retrieves the user from an implementation-specific location.
111111
*
112-
* @param string $username The username to retrieve
113-
* @param UsernamePasswordToken $token The Token
114-
*
115112
* @return UserInterface The user
116113
*
117114
* @throws AuthenticationException if the credentials could not be validated
118115
*/
119-
abstract protected function retrieveUser($username, UsernamePasswordToken $token);
116+
abstract protected function retrieveUser(string $username, UsernamePasswordToken $token);
120117

121118
/**
122119
* Does additional checks on the user and token (like validating the

‎src/Symfony/Component/Security/Core/Authentication/RememberMe/InMemoryTokenProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/RememberMe/InMemoryTokenProvider.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InMemoryTokenProvider implements TokenProviderInterface
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function loadTokenBySeries($series)
28+
public function loadTokenBySeries(string $series)
2929
{
3030
if (!isset($this->tokens[$series])) {
3131
throw new TokenNotFoundException('No token found.');
@@ -37,7 +37,7 @@ public function loadTokenBySeries($series)
3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function updateToken($series, $tokenValue, \DateTime $lastUsed)
40+
public function updateToken(string $series, string $tokenValue, \DateTime $lastUsed)
4141
{
4242
if (!isset($this->tokens[$series])) {
4343
throw new TokenNotFoundException('No token found.');
@@ -56,7 +56,7 @@ public function updateToken($series, $tokenValue, \DateTime $lastUsed)
5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function deleteTokenBySeries($series)
59+
public function deleteTokenBySeries(string $series)
6060
{
6161
unset($this->tokens[$series]);
6262
}

‎src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php
+3-11Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,23 @@ interface TokenProviderInterface
2323
/**
2424
* Loads the active token for the given series.
2525
*
26-
* @param string $series
27-
*
2826
* @return PersistentTokenInterface
2927
*
3028
* @throws TokenNotFoundException if the token is not found
3129
*/
32-
public function loadTokenBySeries($series);
30+
public function loadTokenBySeries(string $series);
3331

3432
/**
3533
* Deletes all tokens belonging to series.
36-
*
37-
* @param string $series
3834
*/
39-
public function deleteTokenBySeries($series);
35+
public function deleteTokenBySeries(string $series);
4036

4137
/**
4238
* Updates the token according to this data.
4339
*
44-
* @param string $series
45-
* @param string $tokenValue
46-
* @param \DateTime $lastUsed
47-
*
4840
* @throws TokenNotFoundException if the token is not found
4941
*/
50-
public function updateToken($series, $tokenValue, \DateTime $lastUsed);
42+
public function updateToken(string $series, string $tokenValue, \DateTime $lastUsed);
5143

5244
/**
5345
* Creates a new token.

‎src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
+6-11Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public function isAuthenticated()
108108
/**
109109
* {@inheritdoc}
110110
*/
111-
public function setAuthenticated($authenticated)
111+
public function setAuthenticated(bool $authenticated)
112112
{
113-
$this->authenticated = (bool) $authenticated;
113+
$this->authenticated = $authenticated;
114114
}
115115

116116
/**
@@ -187,25 +187,21 @@ public function setAttributes(array $attributes)
187187
/**
188188
* Returns true if the attribute exists.
189189
*
190-
* @param string $name The attribute name
191-
*
192190
* @return bool true if the attribute exists, false otherwise
193191
*/
194-
public function hasAttribute($name)
192+
public function hasAttribute(string $name)
195193
{
196194
return \array_key_exists($name, $this->attributes);
197195
}
198196

199197
/**
200198
* Returns an attribute value.
201199
*
202-
* @param string $name The attribute name
203-
*
204200
* @return mixed The attribute value
205201
*
206202
* @throws \InvalidArgumentException When attribute doesn't exist for this token
207203
*/
208-
public function getAttribute($name)
204+
public function getAttribute(string $name)
209205
{
210206
if (!\array_key_exists($name, $this->attributes)) {
211207
throw new \InvalidArgumentException(sprintf('This token has no "%s" attribute.', $name));
@@ -217,10 +213,9 @@ public function getAttribute($name)
217213
/**
218214
* Sets an attribute.
219215
*
220-
* @param string $name The attribute name
221-
* @param mixed $value The attribute value
216+
* @param mixed $value The attribute value
222217
*/
223-
public function setAttribute($name, $value)
218+
public function setAttribute(string $name, $value)
224219
{
225220
$this->attributes[$name] = $value;
226221
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(UserInterface $user, string $providerKey, string $se
5252
/**
5353
* {@inheritdoc}
5454
*/
55-
public function setAuthenticated($authenticated)
55+
public function setAuthenticated(bool $authenticated)
5656
{
5757
if ($authenticated) {
5858
throw new \LogicException('You cannot set this token to authenticated after creation.');

‎src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php
+5-12Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ public function isAuthenticated();
8080

8181
/**
8282
* Sets the authenticated flag.
83-
*
84-
* @param bool $isAuthenticated The authenticated flag
8583
*/
86-
public function setAuthenticated($isAuthenticated);
84+
public function setAuthenticated(bool $isAuthenticated);
8785

8886
/**
8987
* Removes sensitive information from the token.
@@ -107,30 +105,25 @@ public function setAttributes(array $attributes);
107105
/**
108106
* Returns true if the attribute exists.
109107
*
110-
* @param string $name The attribute name
111-
*
112108
* @return bool true if the attribute exists, false otherwise
113109
*/
114-
public function hasAttribute($name);
110+
public function hasAttribute(string $name);
115111

116112
/**
117113
* Returns an attribute value.
118114
*
119-
* @param string $name The attribute name
120-
*
121115
* @return mixed The attribute value
122116
*
123117
* @throws \InvalidArgumentException When attribute doesn't exist for this token
124118
*/
125-
public function getAttribute($name);
119+
public function getAttribute(string $name);
126120

127121
/**
128122
* Sets an attribute.
129123
*
130-
* @param string $name The attribute name
131-
* @param mixed $value The attribute value
124+
* @param mixed $value The attribute value
132125
*/
133-
public function setAttribute($name, $value);
126+
public function setAttribute(string $name, $value);
134127

135128
/**
136129
* Returns all the necessary state of the object for serialization purposes.

‎src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct($user, $credentials, string $providerKey, array $rol
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function setAuthenticated($isAuthenticated)
50+
public function setAuthenticated(bool $isAuthenticated)
5151
{
5252
if ($isAuthenticated) {
5353
throw new \LogicException('Cannot set this token to trusted after instantiation.');

‎src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function vote(TokenInterface $token, $subject, array $attributes)
5454
*
5555
* @return bool True if the attribute and subject are supported, false otherwise
5656
*/
57-
abstract protected function supports($attribute, $subject);
57+
abstract protected function supports(string $attribute, $subject);
5858

5959
/**
6060
* Perform a single access check operation on a given attribute, subject and token.
@@ -66,5 +66,5 @@ abstract protected function supports($attribute, $subject);
6666
*
6767
* @return bool
6868
*/
69-
abstract protected function voteOnAttribute($attribute, $subject, TokenInterface $token);
69+
abstract protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token);
7070
}

‎src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function isAuthenticated()
159159
{
160160
}
161161

162-
public function setAuthenticated($isAuthenticated)
162+
public function setAuthenticated(bool $isAuthenticated)
163163
{
164164
}
165165

@@ -175,15 +175,15 @@ public function setAttributes(array $attributes)
175175
{
176176
}
177177

178-
public function hasAttribute($name)
178+
public function hasAttribute(string $name)
179179
{
180180
}
181181

182-
public function getAttribute($name)
182+
public function getAttribute(string $name)
183183
{
184184
}
185185

186-
public function setAttribute($name, $value)
186+
public function setAttribute(string $name, $value)
187187
{
188188
}
189189
}

‎src/Symfony/Component/Security/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testRetrieveUserReturnsUserFromTokenOnReauthentication()
8383
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());
8484
$reflection = new \ReflectionMethod($provider, 'retrieveUser');
8585
$reflection->setAccessible(true);
86-
$result = $reflection->invoke($provider, null, $token);
86+
$result = $reflection->invoke($provider, 'someUser', $token);
8787

8888
$this->assertSame($user, $result);
8989
}

‎src/Symfony/Component/Security/Core/Tests/Authorization/Voter/VoterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Tests/Authorization/Voter/VoterTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public function testVote(array $attributes, $expectedVote, $object, $message)
5959

6060
class VoterTest_Voter extends Voter
6161
{
62-
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
62+
protected function voteOnAttribute(string $attribute, $object, TokenInterface $token)
6363
{
6464
return 'EDIT' === $attribute;
6565
}
6666

67-
protected function supports($attribute, $object)
67+
protected function supports(string $attribute, $object)
6868
{
6969
return $object instanceof \stdClass && \in_array($attribute, ['EDIT', 'CREATE']);
7070
}

‎src/Symfony/Component/Security/Guard/Token/PreAuthenticationGuardToken.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Guard/Token/PreAuthenticationGuardToken.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getCredentials()
5858
return $this->credentials;
5959
}
6060

61-
public function setAuthenticated($authenticated)
61+
public function setAuthenticated(bool $authenticated)
6262
{
6363
throw new \LogicException('The PreAuthenticationGuardToken is *never* authenticated.');
6464
}

‎src/Symfony/Component/Security/Guard/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Guard/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.2.9",
20-
"symfony/security-core": "^4.4|^5.0",
20+
"symfony/security-core": "^5.0",
2121
"symfony/security-http": "^4.4|^5.0"
2222
},
2323
"require-dev": {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.