Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DoctrineBridge] Add username to UserNameNotFoundException #39880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public function loadUserByUsername($username)
}

if (null === $user) {
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
$e->setUsername($username);

throw $e;
}

return $user;
Expand Down Expand Up @@ -92,7 +95,10 @@ public function refreshUser(UserInterface $user)

$refreshedUser = $repository->find($id);
if (null === $refreshedUser) {
throw new UsernameNotFoundException('User with id '.json_encode($id).' not found.');
$e = new UsernameNotFoundException('User with id '.json_encode($id).' not found.');
$e->setUsername(json_encode($id));

throw $e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public function loadUserByUsername($username)
$user = $this->getUser($username);

if (null === $user) {
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
$e->setUsername($username);

throw $e;
}

return $user;
Expand Down
15 changes: 12 additions & 3 deletions 15 src/Symfony/Component/Ldap/Security/LdapUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,27 @@ public function loadUserByUsername($username)
$query = str_replace('{username}', $username, $this->defaultSearch);
$search = $this->ldap->query($this->baseDn, $query);
} catch (ConnectionException $e) {
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username), 0, $e);
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username), 0, $e);
$e->setUsername($username);

throw $e;
}

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

if (!$count) {
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
$e->setUsername($username);

throw $e;
}

if ($count > 1) {
qurben marked this conversation as resolved.
Show resolved Hide resolved
throw new UsernameNotFoundException('More than one user found.');
$e = new UsernameNotFoundException('More than one user found.');
$e->setUsername($username);

throw $e;
}

$entry = $entries[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ private function authenticateViaGuard(AuthenticatorInterface $guardAuthenticator
$user = $guardAuthenticator->getUser($token->getCredentials(), $this->userProvider);

if (null === $user) {
throw new UsernameNotFoundException(sprintf('Null returned from "%s::getUser()".', \get_class($guardAuthenticator)));
$e = new UsernameNotFoundException(sprintf('Null returned from "%s::getUser()".', \get_class($guardAuthenticator)));
$e->setUsername($token->getUsername());

throw $e;
}

if (!$user instanceof UserInterface) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.