Skip to content

Commit 883cd52

Browse files
committed
[Security] Rename User to InMemoryUser
1 parent 6c0102c commit 883cd52

File tree

76 files changed

+566
-162
lines changed

Some content is hidden

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

76 files changed

+566
-162
lines changed

UPGRADE-5.3.md

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Routing
8787
Security
8888
--------
8989

90+
* Deprecate class `User`, use `InMemoryUser` or your own implementation instead
91+
* Deprecate class `UserChecker`, use `InMemoryUserChecker` or your own implementation instead
9092
* Deprecate `UserInterface::getPassword()`
9193
If your `getPassword()` method does not return `null` (i.e. you are using password-based authentication),
9294
you should implement `PasswordAuthenticatedUserInterface`.

UPGRADE-6.0.md

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ Routing
175175
Security
176176
--------
177177

178+
* Remove class `User`, use `InMemoryUser` or your own implementation instead
179+
* Remove class `UserChecker`, use `InMemoryUserChecker` or your own implementation instead
178180
* Remove `UserInterface::getPassword()`
179181
If your `getPassword()` method does not return `null` (i.e. you are using password-based authentication),
180182
you should implement `PasswordAuthenticatedUserInterface`.

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
use Symfony\Component\HttpFoundation\StreamedResponse;
3939
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
4040
use Symfony\Component\HttpKernel\HttpKernelInterface;
41+
use Symfony\Component\Routing\RouterInterface;
4142
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
4243
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
4344
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
4445
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
4546
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
46-
use Symfony\Component\Security\Core\User\User;
47+
use Symfony\Component\Security\Core\User\InMemoryUser;
4748
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
4849
use Symfony\Component\Serializer\SerializerInterface;
49-
use Symfony\Component\Routing\RouterInterface;
5050
use Symfony\Component\WebLink\Link;
5151
use Twig\Environment;
5252

@@ -137,7 +137,7 @@ public function testForward()
137137

138138
public function testGetUser()
139139
{
140-
$user = new User('user', 'pass');
140+
$user = new InMemoryUser('user', 'pass');
141141
$token = new UsernamePasswordToken($user, 'pass', 'default', ['ROLE_USER']);
142142

143143
$controller = $this->createController();

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SecurityTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14-
use Symfony\Component\Security\Core\User\User;
14+
use Symfony\Component\Security\Core\User\InMemoryUser;
1515

1616
class SecurityTest extends AbstractWebTestCase
1717
{
@@ -20,7 +20,7 @@ class SecurityTest extends AbstractWebTestCase
2020
*/
2121
public function testLoginUser(string $username, array $roles, ?string $firewallContext)
2222
{
23-
$user = new User($username, 'the-password', $roles);
23+
$user = new InMemoryUser($username, 'the-password', $roles);
2424
$client = $this->createClient(['test_case' => 'Security', 'root_config' => 'config.yml']);
2525

2626
if (null === $firewallContext) {
@@ -45,7 +45,7 @@ public function getUsers()
4545

4646
public function testLoginUserMultipleRequests()
4747
{
48-
$user = new User('the-username', 'the-password', ['ROLE_FOO']);
48+
$user = new InMemoryUser('the-username', 'the-password', ['ROLE_FOO']);
4949
$client = $this->createClient(['test_case' => 'Security', 'root_config' => 'config.yml']);
5050
$client->loginUser($user);
5151

@@ -58,7 +58,7 @@ public function testLoginUserMultipleRequests()
5858

5959
public function testLoginInBetweenRequests()
6060
{
61-
$user = new User('the-username', 'the-password', ['ROLE_FOO']);
61+
$user = new InMemoryUser('the-username', 'the-password', ['ROLE_FOO']);
6262
$client = $this->createClient(['test_case' => 'Security', 'root_config' => 'config.yml']);
6363

6464
$client->request('GET', '/main/user_profile');

src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function configure()
7373
# app/config/security.yml
7474
security:
7575
encoders:
76-
Symfony\Component\Security\Core\User\User: plaintext
76+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
7777
App\Entity\User: auto
7878
</comment>
7979

src/Symfony/Bundle/SecurityBundle/Resources/config/security.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
4242
use Symfony\Component\Security\Core\Security;
4343
use Symfony\Component\Security\Core\User\ChainUserProvider;
44+
use Symfony\Component\Security\Core\User\InMemoryUserChecker;
4445
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
4546
use Symfony\Component\Security\Core\User\MissingUserProvider;
46-
use Symfony\Component\Security\Core\User\UserChecker;
4747
use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator;
4848
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
4949
use Symfony\Component\Security\Http\Controller\UserValueResolver;
@@ -126,7 +126,7 @@
126126
->alias(UserPasswordEncoderInterface::class, 'security.password_encoder')
127127
->deprecate('symfony/security-bundle', '5.3', 'The "%alias_id%" service is deprecated, use "'.UserPasswordHasherInterface::class.'" instead.')
128128

129-
->set('security.user_checker', UserChecker::class)
129+
->set('security.user_checker', InMemoryUserChecker::class)
130130

131131
->set('security.expression_language', ExpressionLanguage::class)
132132
->args([service('cache.security_expression_language')->nullOnInvalid()])

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use Symfony\Component\HttpFoundation\Response;
3232
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
3333
use Symfony\Component\Security\Core\Exception\AuthenticationException;
34-
use Symfony\Component\Security\Core\User\UserChecker;
34+
use Symfony\Component\Security\Core\User\InMemoryUserChecker;
3535
use Symfony\Component\Security\Core\User\UserCheckerInterface;
3636
use Symfony\Component\Security\Core\User\UserInterface;
3737
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -626,7 +626,7 @@ public function testUserCheckerWithAuthenticatorManager(array $config, string $e
626626

627627
public function provideUserCheckerConfig()
628628
{
629-
yield [[], UserChecker::class];
629+
yield [[], InMemoryUserChecker::class];
630630
yield [['user_checker' => TestUserChecker::class], TestUserChecker::class];
631631
}
632632

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AuthenticatorBundle/ApiAuthenticator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1818
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1919
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
20-
use Symfony\Component\Security\Core\User\User;
20+
use Symfony\Component\Security\Core\User\InMemoryUser;
2121
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
2222
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
2323
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
@@ -46,7 +46,7 @@ public function authenticate(Request $request): PassportInterface
4646

4747
$userLoader = null;
4848
if ($this->selfLoadingUser) {
49-
$userLoader = function ($username) { return new User($username, 'test', ['ROLE_USER']); };
49+
$userLoader = function ($username) { return new InMemoryUser($username, 'test', ['ROLE_USER']); };
5050
}
5151

5252
return new SelfValidatingPassport(new UserBadge($email, $userLoader));

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/GuardedBundle/AuthenticationController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
16-
use Symfony\Component\Security\Core\User\User;
16+
use Symfony\Component\Security\Core\User\InMemoryUser;
1717
use Symfony\Component\Security\Core\User\UserInterface;
1818
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
1919
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
@@ -22,7 +22,7 @@ class AuthenticationController
2222
{
2323
public function manualLoginAction(GuardAuthenticatorHandler $guardAuthenticatorHandler, Request $request)
2424
{
25-
$guardAuthenticatorHandler->authenticateWithToken(new PostAuthenticationGuardToken(new User('Jane', 'test', ['ROLE_USER']), 'secure', ['ROLE_USER']), $request, 'secure');
25+
$guardAuthenticatorHandler->authenticateWithToken(new PostAuthenticationGuardToken(new InMemoryUser('Jane', 'test', ['ROLE_USER']), 'secure', ['ROLE_USER']), $request, 'secure');
2626

2727
return new Response('Logged in.');
2828
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/SecuredPageBundle/Security/Core/User/ArrayUserProvider.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Bundle\SecurityBundle\Tests\Functional\UserWithoutEquatable;
66
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
77
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
8-
use Symfony\Component\Security\Core\User\User;
8+
use Symfony\Component\Security\Core\User\InMemoryUser;
99
use Symfony\Component\Security\Core\User\UserInterface;
1010
use Symfony\Component\Security\Core\User\UserProviderInterface;
1111

@@ -52,11 +52,11 @@ public function refreshUser(UserInterface $user)
5252
$storedUser = $this->getUser($user->getUsername());
5353
$class = \get_class($storedUser);
5454

55-
return new $class($storedUser->getUsername(), $storedUser->getPassword(), $storedUser->getRoles(), $storedUser->isEnabled(), $storedUser->isAccountNonExpired(), $storedUser->isCredentialsNonExpired() && $storedUser->getPassword() === $user->getPassword(), $storedUser->isAccountNonLocked());
55+
return new $class($storedUser->getUsername(), $storedUser->getPassword(), $storedUser->getRoles(), $storedUser->isEnabled());
5656
}
5757

5858
public function supportsClass($class)
5959
{
60-
return User::class === $class || UserWithoutEquatable::class === $class;
60+
return InMemoryUser::class === $class || UserWithoutEquatable::class === $class;
6161
}
6262
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/ClearRememberMeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
1313

1414
use Symfony\Component\HttpFoundation\Response;
15+
use Symfony\Component\Security\Core\User\InMemoryUser;
1516
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
16-
use Symfony\Component\Security\Core\User\User;
1717
use Symfony\Component\Security\Core\User\UserInterface;
1818
use Symfony\Component\Security\Core\User\UserProviderInterface;
1919

@@ -73,7 +73,7 @@ public function refreshUser(UserInterface $user)
7373
{
7474
$user = $this->inner->refreshUser($user);
7575

76-
$alterUser = \Closure::bind(function (User $user) { $user->password = 'foo'; }, null, User::class);
76+
$alterUser = \Closure::bind(function (InMemoryUser $user) { $user->password = 'foo'; }, null, InMemoryUser::class);
7777
$alterUser($user);
7878

7979
return $user;

src/Symfony/Bundle/SecurityBundle/Tests/Functional/LoginLinkAuthenticationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\RequestStack;
16-
use Symfony\Component\Security\Core\User\User;
16+
use Symfony\Component\Security\Core\User\InMemoryUser;
1717
use Symfony\Component\Security\Http\LoginLink\LoginLinkHandler;
1818
use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface;
1919

@@ -36,7 +36,7 @@ public function testLoginLinkSuccess()
3636

3737
/** @var LoginLinkHandlerInterface $loginLinkHandler */
3838
$loginLinkHandler = self::getContainer()->get(LoginLinkHandlerInterface::class);
39-
$user = new User('weaverryan', 'foo');
39+
$user = new InMemoryUser('weaverryan', 'foo');
4040
$loginLink = $loginLinkHandler->createLoginLink($user);
4141
$this->assertStringContainsString('user=weaverryan', $loginLink);
4242
$this->assertStringContainsString('hash=', $loginLink);

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\SecuredPageBundle\Security\Core\User\ArrayUserProvider;
1515
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
16+
use Symfony\Component\Security\Core\User\InMemoryUser;
1617
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
17-
use Symfony\Component\Security\Core\User\User;
1818
use Symfony\Component\Security\Core\User\UserInterface;
1919

2020
class SecurityTest extends AbstractWebTestCase
@@ -26,7 +26,7 @@ public function testServiceIsFunctional()
2626
$container = $kernel->getContainer();
2727

2828
// put a token into the storage so the final calls can function
29-
$user = new User('foo', 'pass');
29+
$user = new InMemoryUser('foo', 'pass');
3030
$token = new UsernamePasswordToken($user, '', 'provider', ['ROLE_USER']);
3131
$container->get('security.token_storage')->setToken($token);
3232

@@ -39,8 +39,8 @@ public function userWillBeMarkedAsChangedIfRolesHasChangedProvider()
3939
{
4040
return [
4141
[
42-
new User('user1', 'test', ['ROLE_ADMIN']),
43-
new User('user1', 'test', ['ROLE_USER']),
42+
new InMemoryUser('user1', 'test', ['ROLE_ADMIN']),
43+
new InMemoryUser('user1', 'test', ['ROLE_USER']),
4444
],
4545
[
4646
new UserWithoutEquatable('user1', 'test', ['ROLE_ADMIN']),

src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder;
2020
use Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder;
2121
use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder;
22+
use Symfony\Component\Security\Core\User\InMemoryUser;
2223

2324
/**
2425
* Tests UserPasswordEncoderCommand.
@@ -36,7 +37,7 @@ public function testEncodePasswordEmptySalt()
3637
$this->passwordEncoderCommandTester->execute([
3738
'command' => 'security:encode-password',
3839
'password' => 'password',
39-
'user-class' => 'Symfony\Component\Security\Core\User\User',
40+
'user-class' => InMemoryUser::class,
4041
'--empty-salt' => true,
4142
], ['decorated' => false]);
4243
$expected = str_replace("\n", \PHP_EOL, file_get_contents(__DIR__.'/app/PasswordEncode/emptysalt.txt'));
@@ -189,7 +190,7 @@ public function testEncodePasswordEmptySaltOutput()
189190
$this->passwordEncoderCommandTester->execute([
190191
'command' => 'security:encode-password',
191192
'password' => 'p@ssw0rd',
192-
'user-class' => 'Symfony\Component\Security\Core\User\User',
193+
'user-class' => InMemoryUser::class,
193194
'--empty-salt' => true,
194195
]);
195196

@@ -282,7 +283,7 @@ public function testEncodePasswordAsksNonProvidedUserClass()
282283
[0] Custom\Class\Native\User
283284
[1] Custom\Class\Pbkdf2\User
284285
[2] Custom\Class\Test\User
285-
[3] Symfony\Component\Security\Core\User\User
286+
[3] Symfony\Component\Security\Core\User\InMemoryUser
286287
EOTXT
287288
, $this->passwordEncoderCommandTester->getDisplay(true));
288289
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Authenticator/security.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ security:
22
enable_authenticator_manager: true
33

44
password_hashers:
5-
Symfony\Component\Security\Core\User\User: plaintext
5+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
66

77
providers:
88
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ClearRememberMe/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33

44
security:
55
password_hashers:
6-
Symfony\Component\Security\Core\User\User: plaintext
6+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
77

88
providers:
99
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/base_config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616

1717
security:
1818
password_hashers:
19-
Symfony\Component\Security\Core\User\User: plaintext
19+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
2020

2121
providers:
2222
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ security:
2929
users:
3030
john: { password: doe, roles: [ROLE_SECURE] }
3131
password_hashers:
32-
Symfony\Component\Security\Core\User\User: plaintext
32+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Guarded/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515

1616
security:
1717
password_hashers:
18-
Symfony\Component\Security\Core\User\User: plaintext
18+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
1919

2020
providers:
2121
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLogin/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ framework:
66

77
security:
88
password_hashers:
9-
Symfony\Component\Security\Core\User\User: plaintext
9+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
1010

1111
providers:
1212
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/JsonLogin/custom_handlers.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33

44
security:
55
password_hashers:
6-
Symfony\Component\Security\Core\User\User: plaintext
6+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
77

88
providers:
99
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Logout/config_access.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33

44
security:
55
password_hashers:
6-
Symfony\Component\Security\Core\User\User: plaintext
6+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
77

88
providers:
99
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Logout/config_cookie_clearing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33

44
security:
55
password_hashers:
6-
Symfony\Component\Security\Core\User\User: plaintext
6+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
77

88
providers:
99
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/LogoutWithoutSessionInvalidation/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33

44
security:
55
password_hashers:
6-
Symfony\Component\Security\Core\User\User: plaintext
6+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
77

88
providers:
99
in_memory:

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/PasswordEncode/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ imports:
33

44
security:
55
encoders:
6-
Symfony\Component\Security\Core\User\User: plaintext
6+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
77
Custom\Class\Native\User:
88
algorithm: native
99
cost: 10

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/RememberMeLogout/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ framework:
99

1010
security:
1111
password_hashers:
12-
Symfony\Component\Security\Core\User\User: plaintext
12+
Symfony\Component\Security\Core\User\InMemoryUser: plaintext
1313

1414
providers:
1515
in_memory:

0 commit comments

Comments
 (0)