summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2016-04-05 18:36:54 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2016-04-05 18:36:54 +0200
commit7e3a8dc21102d0e024f093e84b0cde5786a7e804 (patch)
treee10d6935259fcebc37716626423e0694c9bc5cfe
parent9e038d16ad625623a11131795119c6866aed783b (diff)
parent5176f267ee3c8ae80e9b2e45c7b681855e3ac56c (diff)
downloadsymfony-security-7e3a8dc21102d0e024f093e84b0cde5786a7e804.zip
symfony-security-7e3a8dc21102d0e024f093e84b0cde5786a7e804.tar.gz
symfony-security-7e3a8dc21102d0e024f093e84b0cde5786a7e804.tar.bz2
Merge branch '2.7' into 2.8
* 2.7: [HttpFoundation] Improve phpdoc [Logging] Add support for firefox in ChromePhpHandler Windows 10 version check in just one line Detect CLI color support for Windows 10 build 10586 [Security] Fixed SwitchUserListener when exiting an impersonication with AnonymousToken [EventDispatcher] Try first if the event is Stopped [FrameworkBundle] fixes grammar in container:debug command manual. [Form] fix "prototype" not required when parent form is not required
-rw-r--r--Http/Firewall/SwitchUserListener.php3
-rw-r--r--Http/Tests/Firewall/SwitchUserListenerTest.php48
2 files changed, 50 insertions, 1 deletions
diff --git a/Http/Firewall/SwitchUserListener.php b/Http/Firewall/SwitchUserListener.php
index 7c068fe..7de83d2 100644
--- a/Http/Firewall/SwitchUserListener.php
+++ b/Http/Firewall/SwitchUserListener.php
@@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Http\Firewall;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
+use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
@@ -161,7 +162,7 @@ class SwitchUserListener implements ListenerInterface
throw new AuthenticationCredentialsNotFoundException('Could not find original Token object.');
}
- if (null !== $this->dispatcher) {
+ if (null !== $this->dispatcher && $original->getUser() instanceof UserInterface) {
$user = $this->provider->refreshUser($original->getUser());
$switchEvent = new SwitchUserEvent($request, $user);
$this->dispatcher->dispatch(SecurityEvents::SWITCH_USER, $switchEvent);
diff --git a/Http/Tests/Firewall/SwitchUserListenerTest.php b/Http/Tests/Firewall/SwitchUserListenerTest.php
index f43b564..bca2c4a 100644
--- a/Http/Tests/Firewall/SwitchUserListenerTest.php
+++ b/Http/Tests/Firewall/SwitchUserListenerTest.php
@@ -158,6 +158,54 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($this->event);
}
+ public function testExitUserDoesNotDispatchEventWithStringUser()
+ {
+ $originalUser = 'anon.';
+ $refreshedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $this
+ ->userProvider
+ ->expects($this->never())
+ ->method('refreshUser');
+ $originalToken = $this->getToken();
+ $originalToken
+ ->expects($this->any())
+ ->method('getUser')
+ ->willReturn($originalUser);
+ $role = $this
+ ->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $role
+ ->expects($this->any())
+ ->method('getSource')
+ ->willReturn($originalToken);
+ $this
+ ->tokenStorage
+ ->expects($this->any())
+ ->method('getToken')
+ ->willReturn($this->getToken(array($role)));
+ $this
+ ->request
+ ->expects($this->any())
+ ->method('all')
+ ->with('_switch_user')
+ ->willReturn('_exit');
+ $this
+ ->request
+ ->expects($this->any())
+ ->method('getUri')
+ ->willReturn('/');
+
+ $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $dispatcher
+ ->expects($this->never())
+ ->method('dispatch')
+ ;
+
+ $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher);
+ $listener->handle($this->event);
+ }
+
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
*/