diff options
author | Nicolas Grekas <nicolas.grekas@gmail.com> | 2015-07-01 22:40:29 +0200 |
---|---|---|
committer | Nicolas Grekas <nicolas.grekas@gmail.com> | 2015-07-01 22:40:29 +0200 |
commit | 3b3cfe0bb49fc0e330dd731705bff6cd8d6f93f6 (patch) | |
tree | 09ed3c057911dca238932f4886d4a3f58a10e60c | |
parent | 96932d004f5a2355b8a5691092bfda75c6cf6d0e (diff) | |
parent | 93bccca789d9afdc88ec04bfae28a12e7ded3837 (diff) | |
download | symfony-security-3b3cfe0bb49fc0e330dd731705bff6cd8d6f93f6.zip symfony-security-3b3cfe0bb49fc0e330dd731705bff6cd8d6f93f6.tar.gz symfony-security-3b3cfe0bb49fc0e330dd731705bff6cd8d6f93f6.tar.bz2 |
Merge branch '2.8'
* 2.8: (65 commits)
[VarDumper] Fix tests for HHVM
Update DateTimeToArrayTransformer.php
Mock microtime() and time() in transient tests
Azerbaijani language pluralization rule
Move HHVM tests out of the allowed failures
Fix merge
[2.6] Towards 100% HHVM compat
[Security/Http] Fix test
[Stopwatch] Fix test
Minor fixes
[Validator] Added missing error codes and turned codes into UUIDs
Towards 100% HHVM compat
Warmup twig templates in non-standard paths (closes #12507)
[Bridge/PhpUnit] Enforce a consistent locale
Fix param order of assertEquals (expected, actual) in test for Finder\Glob
Fix choice translation domain for expanded choice widget
unify default AccessDeniedExeption message
trigger event with right user (add test)
[Security] Initialize SwitchUserEvent::targetUser on attemptExitUser
fixed CS
...
Conflicts:
UPGRADE-2.8.md
src/Symfony/Bridge/ProxyManager/composer.json
src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
src/Symfony/Bundle/FrameworkBundle/Resources/config/old_assets.xml
src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml
src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.xml
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.xml
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.xml
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.xml
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.txt
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.xml
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.json
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.md
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.txt
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.xml
src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php
src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml
src/Symfony/Bundle/SecurityBundle/composer.json
src/Symfony/Component/Debug/ErrorHandler.php
src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php
src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php
src/Symfony/Component/DependencyInjection/Definition.php
src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container9.php
src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/legacy-services9.dot
src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services6.xml
src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml
src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services6.yml
src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml
src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
src/Symfony/Component/Form/ResolvedFormType.php
src/Symfony/Component/Form/Tests/CompoundFormTest.php
src/Symfony/Component/Process/Tests/AbstractProcessTest.php
src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php
-rw-r--r-- | Core/Exception/AccessDeniedException.php | 2 | ||||
-rw-r--r-- | Http/Firewall/SwitchUserListener.php | 3 | ||||
-rw-r--r-- | Http/Tests/Firewall/SwitchUserListenerTest.php | 58 |
3 files changed, 61 insertions, 2 deletions
diff --git a/Core/Exception/AccessDeniedException.php b/Core/Exception/AccessDeniedException.php index 7c16afb..736a36b 100644 --- a/Core/Exception/AccessDeniedException.php +++ b/Core/Exception/AccessDeniedException.php @@ -18,7 +18,7 @@ namespace Symfony\Component\Security\Core\Exception; */ class AccessDeniedException extends \RuntimeException { - public function __construct($message = 'Access Denied', \Exception $previous = null) + public function __construct($message = 'Access Denied.', \Exception $previous = null) { parent::__construct($message, 403, $previous); } diff --git a/Http/Firewall/SwitchUserListener.php b/Http/Firewall/SwitchUserListener.php index 5fc56e7..8746d2b 100644 --- a/Http/Firewall/SwitchUserListener.php +++ b/Http/Firewall/SwitchUserListener.php @@ -162,7 +162,8 @@ class SwitchUserListener implements ListenerInterface } if (null !== $this->dispatcher) { - $switchEvent = new SwitchUserEvent($request, $original->getUser()); + $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 3b6442d..f43b564 100644 --- a/Http/Tests/Firewall/SwitchUserListenerTest.php +++ b/Http/Tests/Firewall/SwitchUserListenerTest.php @@ -11,7 +11,9 @@ namespace Symfony\Component\Security\Http\Tests\Firewall; +use Symfony\Component\Security\Http\Event\SwitchUserEvent; use Symfony\Component\Security\Http\Firewall\SwitchUserListener; +use Symfony\Component\Security\Http\SecurityEvents; class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase { @@ -100,6 +102,62 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase $listener->handle($this->event); } + public function testExitUserDispatchesEventWithRefreshedUser() + { + $originalUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); + $refreshedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface'); + $this + ->userProvider + ->expects($this->any()) + ->method('refreshUser') + ->with($originalUser) + ->willReturn($refreshedUser); + $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('get') + ->with('_switch_user') + ->willReturn('_exit'); + $this + ->request + ->expects($this->any()) + ->method('getUri') + ->willReturn('/'); + $this + ->request + ->query + ->expects($this->any()) + ->method('all') + ->will($this->returnValue(array())); + + $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $dispatcher + ->expects($this->once()) + ->method('dispatch') + ->with(SecurityEvents::SWITCH_USER, $this->callback(function (SwitchUserEvent $event) use ($refreshedUser) { + return $event->getTargetUser() === $refreshedUser; + })) + ; + + $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 */ |