Skip to content

Commit 1c7b338

Browse files
committed
[Security] Rename UsernameNotFoundException to UserNotFoundException
1 parent 92c28de commit 1c7b338

37 files changed

+242
-181
lines changed

UPGRADE-5.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Security
169169
* Deprecate `UserInterface::getUsername()` in favor of `UserInterface::getUserIdentifier()`
170170
* Deprecate `TokenInterface::getUsername()` in favor of `TokenInterface::getUserIdentifier()`
171171
* Deprecate `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
172+
* Deprecate `UsernameNotFoundException` in favor of `UserNotFoundException` and `getUsername()`/`setUsername()` in favor of `getUserIdentifier()`/`setUserIdentifier()`
172173
* Deprecate calling `PasswordUpgraderInterface::upgradePassword()` with a `UserInterface` instance that does not implement `PasswordAuthenticatedUserInterface`
173174
* Deprecate calling methods `hashPassword()`, `isPasswordValid()` and `needsRehash()` on `UserPasswordHasherInterface` with a `UserInterface` instance that does not implement `PasswordAuthenticatedUserInterface`
174175
* Deprecate all classes in the `Core\Encoder\` sub-namespace, use the `PasswordHasher` component instead

UPGRADE-6.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ Security
256256

257257
* Remove `UserInterface::getUsername()` in favor of `UserInterface::getUserIdentifier()`
258258
* Remove `TokenInterface::getUsername()` in favor of `TokenInterface::getUserIdentifier()`
259-
* Deprecate `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
259+
* Remove `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
260+
* Remove `UsernameNotFoundException` in favor of `UserNotFoundException` and `getUsername()`/`setUsername()` in favor of `getUserIdentifier()`/`setUserIdentifier()`
260261
* Calling `PasswordUpgraderInterface::upgradePassword()` with a `UserInterface` instance that
261262
does not implement `PasswordAuthenticatedUserInterface` now throws a `\TypeError`.
262263
* Calling methods `hashPassword()`, `isPasswordValid()` and `needsRehash()` on `UserPasswordHasherInterface`

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\Persistence\ObjectManager;
1717
use Doctrine\Persistence\ObjectRepository;
1818
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
19-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
19+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2020
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
2121
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
2222
use Symfony\Component\Security\Core\User\UserInterface;
@@ -70,8 +70,8 @@ public function loadUserByIdentifier(string $identifier): UserInterface
7070
}
7171

7272
if (null === $user) {
73-
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $identifier));
74-
$e->setUsername($identifier);
73+
$e = new UserNotFoundException(sprintf('User "%s" not found.', $identifier));
74+
$e->setUserIdentifier($identifier);
7575

7676
throw $e;
7777
}
@@ -103,8 +103,8 @@ public function refreshUser(UserInterface $user)
103103

104104
$refreshedUser = $repository->find($id);
105105
if (null === $refreshedUser) {
106-
$e = new UsernameNotFoundException('User with id '.json_encode($id).' not found.');
107-
$e->setUsername(json_encode($id));
106+
$e = new UserNotFoundException('User with id '.json_encode($id).' not found.');
107+
$e->setUserIdentifier(json_encode($id));
108108

109109
throw $e;
110110
}

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
2222
use Symfony\Bridge\Doctrine\Tests\DoctrineTestHelper;
2323
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
24-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
24+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2525
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
2626
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
2727
use Symfony\Component\Security\Core\User\UserInterface;
@@ -126,7 +126,7 @@ public function testRefreshInvalidUser()
126126
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
127127

128128
$user2 = new User(1, 2, 'user2');
129-
$this->expectException(UsernameNotFoundException::class);
129+
$this->expectException(UserNotFoundException::class);
130130
$this->expectExceptionMessage('User with id {"id1":1,"id2":2} not found');
131131

132132
$provider->refreshUser($user2);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Symfony\Bundle\SecurityBundle\Tests\Functional\UserWithoutEquatable;
66
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
7-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
7+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
88
use Symfony\Component\Security\Core\User\User;
99
use Symfony\Component\Security\Core\User\UserInterface;
1010
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -39,7 +39,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface
3939
$user = $this->getUser($identifier);
4040

4141
if (null === $user) {
42-
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $identifier));
42+
$e = new UserNotFoundException(sprintf('User "%s" not found.', $identifier));
4343
$e->setUsername($identifier);
4444

4545
throw $e;

src/Symfony/Component/Ldap/Security/LdapUserProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Ldap\LdapInterface;
1818
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
1919
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
20-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
20+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2121
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
2222
use Symfony\Component\Security\Core\User\UserInterface;
2323
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -80,8 +80,8 @@ public function loadUserByIdentifier(string $identifier): UserInterface
8080
$query = str_replace(['{username}', '{user_identifier}'], $identifier, $this->defaultSearch);
8181
$search = $this->ldap->query($this->baseDn, $query);
8282
} catch (ConnectionException $e) {
83-
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $identifier), 0, $e);
84-
$e->setUsername($identifier);
83+
$e = new UserNotFoundException(sprintf('User "%s" not found.', $identifier), 0, $e);
84+
$e->setUserIdentifier($identifier);
8585

8686
throw $e;
8787
}
@@ -90,15 +90,15 @@ public function loadUserByIdentifier(string $identifier): UserInterface
9090
$count = \count($entries);
9191

9292
if (!$count) {
93-
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $identifier));
94-
$e->setUsername($identifier);
93+
$e = new UserNotFoundException(sprintf('User "%s" not found.', $identifier));
94+
$e->setUserIdentifier($identifier);
9595

9696
throw $e;
9797
}
9898

9999
if ($count > 1) {
100-
$e = new UsernameNotFoundException('More than one user found.');
101-
$e->setUsername($identifier);
100+
$e = new UserNotFoundException('More than one user found.');
101+
$e->setUserIdentifier($identifier);
102102

103103
throw $e;
104104
}

src/Symfony/Component/Ldap/Tests/Security/LdapUserProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Symfony\Component\Ldap\Security\LdapUser;
2121
use Symfony\Component\Ldap\Security\LdapUserProvider;
2222
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
23-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
23+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2424

2525
/**
2626
* @requires extension ldap
@@ -29,7 +29,7 @@ class LdapUserProviderTest extends TestCase
2929
{
3030
public function testLoadUserByUsernameFailsIfCantConnectToLdap()
3131
{
32-
$this->expectException(UsernameNotFoundException::class);
32+
$this->expectException(UserNotFoundException::class);
3333

3434
$ldap = $this->createMock(LdapInterface::class);
3535
$ldap
@@ -44,7 +44,7 @@ public function testLoadUserByUsernameFailsIfCantConnectToLdap()
4444

4545
public function testLoadUserByUsernameFailsIfNoLdapEntries()
4646
{
47-
$this->expectException(UsernameNotFoundException::class);
47+
$this->expectException(UserNotFoundException::class);
4848

4949
$result = $this->createMock(CollectionInterface::class);
5050
$query = $this->createMock(QueryInterface::class);
@@ -76,7 +76,7 @@ public function testLoadUserByUsernameFailsIfNoLdapEntries()
7676

7777
public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
7878
{
79-
$this->expectException(UsernameNotFoundException::class);
79+
$this->expectException(UserNotFoundException::class);
8080

8181
$result = $this->createMock(CollectionInterface::class);
8282
$query = $this->createMock(QueryInterface::class);

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.3
55
---
66

7+
* Deprecate `UsernameNotFoundException` in favor of `UserNotFoundException` and `getUsername()`/`setUsername()` in favor of `getUserIdentifier()`/`setUserIdentifier()`
78
* Deprecate `UserProviderInterface::loadUserByUsername()` in favor of `UserProviderInterface::loadUserByIdentifier()`
89
* Deprecate `TokenInterface::getUsername()` in favor of `TokenInterface::getUserIdentifier()`
910
* Deprecate `UserInterface::getUsername()` in favor of `getUserIdentifier()`

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
1717
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
1818
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
19-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
19+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2020
use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
2121
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
2222
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
@@ -129,8 +129,8 @@ protected function retrieveUser(string $userIdentifier, UsernamePasswordToken $t
129129
}
130130

131131
return $user;
132-
} catch (UsernameNotFoundException $e) {
133-
$e->setUsername($userIdentifier);
132+
} catch (UserNotFoundException $e) {
133+
$e->setUserIdentifier($userIdentifier);
134134
throw $e;
135135
} catch (\Exception $e) {
136136
$e = new AuthenticationServiceException($e->getMessage(), 0, $e);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1717
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1818
use Symfony\Component\Security\Core\Exception\LogicException;
19-
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
19+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2020
use Symfony\Component\Security\Core\User\UserCheckerInterface;
2121
use Symfony\Component\Security\Core\User\UserInterface;
2222
use Symfony\Component\Security\Core\User\UserProviderInterface;
@@ -63,7 +63,7 @@ public function setQueryString(string $queryString)
6363
protected function retrieveUser(string $userIdentifier, UsernamePasswordToken $token)
6464
{
6565
if (AuthenticationProviderInterface::USERNAME_NONE_PROVIDED === $userIdentifier) {
66-
throw new UsernameNotFoundException('User identifier can not be null.');
66+
throw new UserNotFoundException('User identifier can not be null.');
6767
}
6868

6969
if (method_exists($this->userProvider, 'loadUserByIdentifier')) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy