Skip to content

Commit 9016ce6

Browse files
Merge branch '7.4' into 8.0
* 7.4: [Security] Fix deprecation [Serializer] Don't fallback to default serializer if tags specify a named one make RoutingControllerPass and AttributeServicesLoader final fix tests [Security] Preserve ordering of roles in RoleHierarchy [Messenger] Fix Oracle errors 'ORA-00955: Name is already used by an existing object' with Doctrine transport [FrameworkBundle] Only show relevant columns in `debug:router` call and adding colors [Security] Improve performance of `RoleHierarchy::buildRoleMap` method chore: add exclude-receivers consume parameters [ObjectMapper] embed collection transformer [SecurityHttp] Removes final keyword from IsGranted attribute [String] Fix nodes singular [Console] Fix testing multiline question [Security][Validator] Review translations. [Security] Ignore target route when exiting impersonation [Console] Restore SHELL_VERBOSITY after a command is ran
2 parents f735f1b + 9cf27a9 commit 9016ce6

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

Attribute/IsGranted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @author Ryan Weaver <ryan@knpuniversity.com>
2323
*/
2424
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
25-
final class IsGranted
25+
class IsGranted
2626
{
2727
/** @var string[] */
2828
public readonly array $methods;

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CHANGELOG
1818
* Deprecate callable firewall listeners, extend `AbstractListener` or implement `FirewallListenerInterface` instead
1919
* Deprecate `AbstractListener::__invoke`
2020
* Add `$methods` argument to `#[IsGranted]` to restrict validation to specific HTTP methods
21+
* Remove `final` keyword from `#[IsGranted]` to allow implementation of custom attributes
2122

2223
7.3
2324
---

Firewall/SwitchUserListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function authenticate(RequestEvent $event): void
111111
if (!$this->stateless) {
112112
$request->query->remove($this->usernameParameter);
113113
$request->server->set('QUERY_STRING', http_build_query($request->query->all(), '', '&'));
114-
$response = new RedirectResponse($this->urlGenerator && $this->targetRoute ? $this->urlGenerator->generate($this->targetRoute) : $request->getUri(), 302);
114+
$response = new RedirectResponse($this->urlGenerator && $this->targetRoute && self::EXIT_VALUE !== $username ? $this->urlGenerator->generate($this->targetRoute) : $request->getUri(), 302);
115115

116116
$event->setResponse($response);
117117
}

Tests/Firewall/SwitchUserListenerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpKernel\Event\RequestEvent;
1919
use Symfony\Component\HttpKernel\HttpKernelInterface;
20+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2021
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
2122
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
2223
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -109,6 +110,21 @@ public function testExitUserUpdatesToken()
109110
$this->assertSame($originalToken, $this->tokenStorage->getToken());
110111
}
111112

113+
public function testExitUserDoesNotRedirectToTargetRoute()
114+
{
115+
$originalToken = new UsernamePasswordToken(new InMemoryUser('username', '', []), 'key', []);
116+
$this->tokenStorage->setToken(new SwitchUserToken(new InMemoryUser('username', '', ['ROLE_USER']), 'key', ['ROLE_USER'], $originalToken));
117+
118+
$this->request->query->set('_switch_user', SwitchUserListener::EXIT_VALUE);
119+
120+
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, urlGenerator: $this->createMock(UrlGeneratorInterface::class), targetRoute: 'whatever');
121+
$this->assertTrue($listener->supports($this->event->getRequest()));
122+
$listener->authenticate($this->event);
123+
124+
$this->assertInstanceOf(RedirectResponse::class, $this->event->getResponse());
125+
$this->assertSame($this->request->getUri(), $this->event->getResponse()->getTargetUrl());
126+
}
127+
112128
public function testExitUserDispatchesEventWithRefreshedUser()
113129
{
114130
$originalUser = new InMemoryUser('username', null);

0 commit comments

Comments
 (0)