Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee5b51a

Browse files
committed
bug #39878 [doctrine-bridge] Add username to UserNameNotFoundException
1 parent 6af4446 commit ee5b51a

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ public function loadUserByUsername($username)
6262
}
6363

6464
if (null === $user) {
65-
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
65+
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
66+
$e->setUsername($username);
67+
68+
throw $e;
6669
}
6770

6871
return $user;
@@ -92,7 +95,10 @@ public function refreshUser(UserInterface $user)
9295

9396
$refreshedUser = $repository->find($id);
9497
if (null === $refreshedUser) {
95-
throw new UsernameNotFoundException('User with id '.json_encode($id).' not found.');
98+
$e = new UsernameNotFoundException('User with id '.json_encode($id).' not found.');
99+
$e->setUsername(json_encode($id));
100+
101+
throw $e;
96102
}
97103
}
98104

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public function loadUserByUsername($username)
3434
$user = $this->getUser($username);
3535

3636
if (null === $user) {
37-
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
37+
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
38+
$e->setUsername($username);
39+
40+
throw $e;
3841
}
3942

4043
return $user;

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,27 @@ public function loadUserByUsername($username)
7373
$query = str_replace('{username}', $username, $this->defaultSearch);
7474
$search = $this->ldap->query($this->baseDn, $query);
7575
} catch (ConnectionException $e) {
76-
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username), 0, $e);
76+
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username), 0, $e);
77+
$e->setUsername($username);
78+
79+
throw $e;
7780
}
7881

7982
$entries = $search->execute();
8083
$count = \count($entries);
8184

8285
if (!$count) {
83-
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
86+
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
87+
$e->setUsername($username);
88+
89+
throw $e;
8490
}
8591

8692
if ($count > 1) {
87-
throw new UsernameNotFoundException('More than one user found.');
93+
$e = new UsernameNotFoundException('More than one user found.');
94+
$e->setUsername($username);
95+
96+
throw $e;
8897
}
8998

9099
$entry = $entries[0];

src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ private function authenticateViaGuard(AuthenticatorInterface $guardAuthenticator
105105
$user = $guardAuthenticator->getUser($token->getCredentials(), $this->userProvider);
106106

107107
if (null === $user) {
108-
throw new UsernameNotFoundException(sprintf('Null returned from "%s::getUser()".', \get_class($guardAuthenticator)));
108+
$e = new UsernameNotFoundException(sprintf('Null returned from "%s::getUser()".', \get_class($guardAuthenticator)));
109+
$e->setUsername($token->getUsername());
110+
111+
throw $e;
109112
}
110113

111114
if (!$user instanceof UserInterface) {

0 commit comments

Comments
 (0)