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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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
}

0 commit comments

Comments
 (0)