8000 [Security] User refreshment from identical users provider type by mykiwi · Pull Request #21737 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] User refreshment from identical users provider type #21737

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fixes
  • Loading branch information
mykiwi committed Feb 23, 2017
commit 1e3df1989ead8136e20999e6723e3a4dbe43977a
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected function refreshUser(TokenInterface $token)
return $token;
}

$exceptions = [];
$exceptions = array();
foreach ($this->userProviders as $provider) {
try {
$refreshedUser = $provider->refreshUser($user);
Expand All @@ -165,7 +165,7 @@ protected function refreshUser(TokenInterface $token)
// let's try the next user provider
} catch (UsernameNotFoundException $notFound) {
// let's try the next user provider
$exceptions[] = [$notFound, $provider];
$exceptions[] = array($notFound, $provider);
}
}

Expand All @@ -179,6 +179,8 @@ protected function refreshUser(TokenInterface $token)
$this->logger->warning('Username could not be found in the selected user provider.', array('username' => $notFound->getUsername(), 'provider' => get_class($provider)));
}
}

return;
}

throw new \RuntimeException(sprintf('There is no user provider for user "%s".', get_class($user)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
use Symfony\Component\Security\Http\Firewall\ContextListener;
use Symfony\Component\Security\Tests\Fixtures\Core\SimpleSecurityContext;
use Symfony\Component\Security\Http\Tests\Fixtures\SimpleSecurityContext;

class ContextListenerTest extends TestCase
{
Expand Down Expand Up @@ -254,7 +254,9 @@ public function testCanRefreshUserWithIdenticalSupportedProviders()
$session = new Session(new MockArraySessionStorage());

/** @var \Symfony\Component\HttpFoundation\Request $request */
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
->disableOriginalConstructor()
->getMock();
$request->expects($this->any())->method('hasPreviousSession')->will($this->returnValue(true));
$request->expects($this->any())->method('getSession')->will($this->returnValue($session));

Expand All @@ -266,21 +268,21 @@ public function testCanRefreshUserWithIdenticalSupportedProviders()
$context = new SimpleSecurityContext();

/**
* We are trying to refresh the "foo" user
* We are trying to refresh the "foo" user.
*/
$user = new UsernamePasswordToken($provider1->loadUserByUsername('foo'), '123456', 'memory');
$session->set('_security_' . $key = 'key123', serialize($user));
$session->set('_security_'.$key = 'key123', serialize($user));

$listener = new ContextListener($context, $providers, $key);
$listener->handle($event);

$this->assertNotNull($context->getToken());

/**
* We are trying to refresh the "bar" user
* We are trying to refresh the "bar" user.
*/
$user = new UsernamePasswordToken($provider2->loadUserByUsername('bar'), '123456', 'memory');
$session->set('_security_' . $key = 'key123', serialize($user));
$session->set('_security_'.$key = 'key123', serialize($user));

$listener = new ContextListener($context, $providers, $key);
$listener->handle($event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Tests\Fixtures\Core;
namespace Symfony\Component\Security\Http\Tests\Fixtures;

use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class SimpleSecurityContext implements SecurityContextInterface
class SimpleSecurityContext implements AuthorizationCheckerInterface, TokenStorageInterface
{
protected $token;

Expand Down
0