-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Check provider supports user class #29653
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,11 +164,21 @@ protected function refreshUser(TokenInterface $token) | |
$userDeauthenticated = false; | ||
|
||
foreach ($this->userProviders as $provider) { | ||
|
||
$providerClass = \get_class($provider); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes should be reverted. |
||
if (!$provider instanceof UserProviderInterface) { | ||
throw new \InvalidArgumentException(sprintf('User provider "%s" must implement "%s".', \get_class($provider), UserProviderInterface::class)); | ||
throw new \InvalidArgumentException(sprintf('User provider "%s" must implement "%s".', $providerClass, UserProviderInterface::class)); | ||
} | ||
|
||
try { | ||
$userClass = \get_class($user); | ||
if( !$provider->supportsClass($userClass) ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this outside the foreach ($this->userProviders as $provider) {
if (!$provider->supportsClass(\get_class($user)) {
continue;
}
// ...
} |
||
{ | ||
throw new UnsupportedUserException( | ||
sprintf('Instances of "%s" are not supported by %s.', $userClass, $providerClass) | ||
); | ||
} | ||
|
||
$refreshedUser = $provider->refreshUser($user); | ||
$newToken = clone $token; | ||
$newToken->setUser($refreshedUser); | ||
|
@@ -178,7 +188,7 @@ protected function refreshUser(TokenInterface $token) | |
$userDeauthenticated = true; | ||
|
||
if (null !== $this->logger) { | ||
$this->logger->debug('Cannot refresh token because user has changed.', array('username' => $refreshedUser->getUsername(), 'provider' => \get_class($provider))); | ||
$this->logger->debug('Cannot refresh token because user has changed.', array('username' => $refreshedUser->getUsername(), 'provider' => $providerClass)); | ||
} | ||
|
||
continue; | ||
|
@@ -187,7 +197,7 @@ protected function refreshUser(TokenInterface $token) | |
$token->setUser($refreshedUser); | ||
|
||
if (null !== $this->logger) { | ||
$context = array('provider' => \get_class($provider), 'username' => $refreshedUser->getUsername()); | ||
$context = array('provider' => $providerClass, 'username' => $refreshedUser->getUsername()); | ||
|
||
foreach ($token->getRoles() as $role) { | ||
if ($role instanceof SwitchUserRole) { | ||
|
@@ -204,7 +214,7 @@ protected function refreshUser(TokenInterface $token) | |
// let's try the next user provider | ||
} catch (UsernameNotFoundException $e) { | ||
if (null !== $this->logger) { | ||
$this->logger->warning('Username could not be found in the selected user provider.', array('username' => $e->getUsername(), 'provider' => \get_class($provider))); | ||
$this->logger->warning('Username could not be found in the selected user provider.', array('username' => $e->getUsername(), 'provider' => $providerClass)); | ||
} | ||
|
||
$userNotFoundByProvider = true; | ||
|
@@ -223,7 +233,7 @@ protected function refreshUser(TokenInterface $token) | |
return null; | ||
} | ||
|
||
throw new \RuntimeException(sprintf('There is no user provider for user "%s".', \get_class($user))); | ||
throw new \RuntimeException(sprintf('There is no user provider for user "%s".', $userClass)); | ||
} | ||
|
||
private function safelyUnserialize($serializedToken) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be reverted, if this is a bugfix it should be based off the
3.4
branch. And for bugfixes we do not add entries to the components changelog files. If this is a new feature, it will be part of 4.3.