Skip to content

Commit 41a61a2

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Security] Deprecate remaining anonymous checks [Security] Deprecate AnonymousToken, non-UserInterface users, and token credentials Fix deprecation messages Fix deprecation messages Do not use str_start_with Add the Path class Add Estonian (et) translations [SecurityBundle] Simplify LDAP factories
2 parents dc02111 + 760993a commit 41a61a2

33 files changed

+444
-111
lines changed

Authentication/AuthenticationProviderManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function authenticate(TokenInterface $token)
110110
$this->eventDispatcher->dispatch(new AuthenticationSuccessEvent($result), AuthenticationEvents::AUTHENTICATION_SUCCESS);
111111
}
112112

113-
// @deprecated since 5.3
113+
// @deprecated since Symfony 5.3
114114
if ($user = $result->getUser() instanceof UserInterface && !method_exists($result->getUser(), 'getUserIdentifier')) {
115115
trigger_deprecation('symfony/security-core', '5.3', 'Not implementing method "getUserIdentifier(): string" in user class "%s" is deprecated. This method will replace "getUsername()" in Symfony 6.0.', get_debug_type($result->getUser()));
116116
}

Authentication/AuthenticationTrustResolver.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@
2323
*/
2424
class AuthenticationTrustResolver implements AuthenticationTrustResolverInterface
2525
{
26+
public function isAuthenticated(TokenInterface $token = null): bool
27+
{
28+
return null !== $token && !$token instanceof NullToken
29+
// @deprecated since Symfony 5.4, TokenInterface::isAuthenticated() and AnonymousToken no longer exists in 6.0
30+
&& !$token instanceof AnonymousToken && $token->isAuthenticated(false);
31+
}
32+
2633
/**
2734
* {@inheritdoc}
2835
*/
29-
public function isAnonymous(TokenInterface $token = null)
36+
public function isAnonymous(TokenInterface $token = null/*, $deprecation = true*/)
3037
{
38+
if (1 === \func_num_args() || false !== func_get_arg(1)) {
39+
trigger_deprecation('symfony/security-core', '5.4', 'The "%s()" method is deprecated, use "isAuthenticated()" or "isFullFledged()" if you want to check if the request is (fully) authenticated.', __METHOD__);
40+
}
41+
3142
if (null === $token) {
3243
return false;
3344
}
@@ -56,6 +67,6 @@ public function isFullFledged(TokenInterface $token = null)
5667
return false;
5768
}
5869

59-
return !$this->isAnonymous($token) && !$this->isRememberMe($token);
70+
return !$this->isAnonymous($token, false) && !$this->isRememberMe($token);
6071
}
6172
}

Authentication/AuthenticationTrustResolverInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* Interface for resolving the authentication status of a given token.
1818
*
1919
* @author Johannes M. Schmitt <[email protected]>
20+
*
21+
* @method bool isAuthenticated(TokenInterface $token = null)
2022
*/
2123
interface AuthenticationTrustResolverInterface
2224
{
@@ -27,6 +29,8 @@ interface AuthenticationTrustResolverInterface
2729
* If null is passed, the method must return false.
2830
*
2931
* @return bool
32+
*
33+
* @deprecated since Symfony 5.4, use !isAuthenticated() instead
3034
*/
3135
public function isAnonymous(TokenInterface $token = null);
3236

Authentication/Provider/DaoAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function retrieveUser(string $userIdentifier, UsernamePasswordToken $t
9595
}
9696

9797
try {
98-
// @deprecated since 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
98+
// @deprecated since Symfony 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
9999
if (method_exists($this->userProvider, 'loadUserByIdentifier')) {
100100
$user = $this->userProvider->loadUserByIdentifier($userIdentifier);
101101
} else {

Authentication/Provider/LdapBindAuthenticationProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function retrieveUser(string $userIdentifier, UsernamePasswordToken $t
7070
throw new UserNotFoundException('User identifier can not be null.');
7171
}
7272

73-
// @deprecated since 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
73+
// @deprecated since Symfony 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
7474
if (method_exists($this->userProvider, 'loadUserByIdentifier')) {
7575
return $this->userProvider->loadUserByIdentifier($userIdentifier);
7676
} else {
@@ -85,7 +85,7 @@ protected function retrieveUser(string $userIdentifier, UsernamePasswordToken $t
8585
*/
8686
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
8787
{
88-
// @deprecated since 5.3, change to $token->getUserIdentifier() in 6.0
88+
// @deprecated since Symfony 5.3, change to $token->getUserIdentifier() in 6.0
8989
$userIdentifier = method_exists($token, 'getUserIdentifier') ? $token->getUserIdentifier() : $token->getUsername();
9090
$password = $token->getCredentials();
9191

Authentication/Provider/PreAuthenticatedAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function authenticate(TokenInterface $token)
5959
}
6060

6161
$userIdentifier = method_exists($token, 'getUserIdentifier') ? $token->getUserIdentifier() : $token->getUsername();
62-
// @deprecated since 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
62+
// @deprecated since Symfony 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
6363
if (method_exists($this->userProvider, 'loadUserByIdentifier')) {
6464
$user = $this->userProvider->loadUserByIdentifier($userIdentifier);
6565
} else {

Authentication/Token/AbstractToken.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getUserIdentifier(): string
7676
}
7777

7878
if ($this->user instanceof UserInterface) {
79-
// @deprecated since 5.3, change to $user->getUserIdentifier() in 6.0
79+
// @deprecated since Symfony 5.3, change to $user->getUserIdentifier() in 6.0
8080
return method_exists($this->user, 'getUserIdentifier') ? $this->user->getUserIdentifier() : $this->user->getUsername();
8181
}
8282

@@ -96,6 +96,10 @@ public function getUser()
9696
*/
9797
public function setUser(string|\Stringable|UserInterface $user)
9898
{
99+
if (!$user instanceof UserInterface) {
100+
trigger_deprecation('symfony/security-core', '5.4', 'Using an object that is not an instance of "%s" as $user in "%s" is deprecated.', UserInterface::class, static::class);
101+
}
102+
99103
// @deprecated since Symfony 5.4, remove the whole block if/elseif/else block in 6.0
100104
if (1 < \func_num_args() && !func_get_arg(1)) {
101105
// ContextListener checks if the user has changed on its own and calls `setAuthenticated()` subsequently,

Authentication/Token/AnonymousToken.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* AnonymousToken represents an anonymous token.
1818
*
1919
* @author Fabien Potencier <[email protected]>
20+
*
21+
* @deprecated since 5.4, anonymous is now represented by the absence of a token
2022
*/
2123
class AnonymousToken extends AbstractToken
2224
{
@@ -28,6 +30,8 @@ class AnonymousToken extends AbstractToken
2830
*/
2931
public function __construct(string $secret, string|\Stringable|UserInterface $user, array $roles = [])
3032
{
33+
trigger_deprecation('symfony/security-core', '5.4', 'The "%s" class is deprecated.', __CLASS__);
34+
3135
parent::__construct($roles);
3236

3337
$this->secret = $secret;

Authentication/Token/PreAuthenticatedToken.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,24 @@ class PreAuthenticatedToken extends AbstractToken
2626
/**
2727
* @param string[] $roles
2828
*/
29-
public function __construct(string|\Stringable|UserInterface $user, mixed $credentials, string $firewallName, array $roles = [])
29+
public function __construct(string|\Stringable|UserInterface $user, /*string*/ $firewallName, /*array*/ $roles = [])
3030
{
31+
if (\is_string($roles)) {
32+
trigger_deprecation('symfony/security-core', '5.4', 'Argument $credentials of "%s()" is deprecated.', __METHOD__);
33+
34+
$credentials = $firewallName;
35+
$firewallName = $roles;
36+
$roles = \func_num_args() > 3 ? func_get_arg(3) : [];
37+
}
38+
3139
parent::__construct($roles);
3240

3341
if ('' === $firewallName) {
3442
throw new \InvalidArgumentException('$firewallName must not be empty.');
3543
}
3644

3745
$this->setUser($user);
38-
$this->credentials = $credentials;
46+
$this->credentials = $credentials ?? null;
3947
$this->firewallName = $firewallName;
4048

4149
if ($roles) {
@@ -48,12 +56,12 @@ public function __construct(string|\Stringable|UserInterface $user, mixed $crede
4856
*
4957
* @return string The provider key
5058
*
51-
* @deprecated since 5.2, use getFirewallName() instead
59+
* @deprecated since Symfony 5.2, use getFirewallName() instead
5260
*/
5361
public function getProviderKey()
5462
{
5563
if (1 !== \func_num_args() || true !== func_get_arg(0)) {
56-
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s" is deprecated, use "getFirewallName()" instead.', __METHOD__);
64+
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s()" is deprecated, use "getFirewallName()" instead.', __METHOD__);
5765
}
5866

5967
return $this->firewallName;
@@ -69,6 +77,8 @@ public function getFirewallName(): string
6977
*/
7078
public function getCredentials()
7179
{
80+
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s()" is deprecated.', __METHOD__);
81+
7282
return $this->credentials;
7383
}
7484

Authentication/Token/RememberMeToken.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public function setAuthenticated(bool $authenticated)
6464
*
6565
* @return string The provider secret
6666
*
67-
* @deprecated since 5.2, use getFirewallName() instead
67+
* @deprecated since Symfony 5.2, use getFirewallName() instead
6868
*/
6969
public function getProviderKey()
7070
{
7171
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__);
72+
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s()" is deprecated, use "getFirewallName()" instead.', __METHOD__);
7373
}
7474

7575
return $this->firewallName;
@@ -95,6 +95,8 @@ public function getSecret()
9595
*/
9696
public function getCredentials()
9797
{
98+
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s()" is deprecated.', __METHOD__);
99+
98100
return '';
99101
}
100102

0 commit comments

Comments
 (0)