Skip to content
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

[SecurityBundle] Set request stateless when firewall is stateless #48044

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Deprecate enabling bundle and not configuring it
* Add `_stateless` attribute to the request when firewall is stateless

6.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ private function getFirewallContext(Request $request): ?FirewallContext
if (null === $requestMatcher || $requestMatcher->matches($request)) {
$request->attributes->set('_firewall_context', $contextId);

return $this->container->get($contextId);
/** @var FirewallContext $context */
$context = $this->container->get($contextId);

if ($context->getConfig()?->isStateless()) {
$request->attributes->set('_stateless', true);
}

return $context;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testGetListenersWithInvalidParameter()
$this->assertEquals([[], null, null], $firewallMap->getListeners($request));
$this->assertNull($firewallMap->getFirewallConfig($request));
$this->assertFalse($request->attributes->has(self::ATTRIBUTE_FIREWALL_CONTEXT));
$this->assertFalse($request->attributes->has('_stateless'));
}

public function testGetListeners()
Expand All @@ -62,8 +63,8 @@ public function testGetListeners()

$firewallContext = $this->createMock(FirewallContext::class);

$firewallConfig = new FirewallConfig('main', 'user_checker');
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
$firewallConfig = new FirewallConfig('main', 'user_checker', null, true, true);
$firewallContext->expects($this->exactly(2))->method('getConfig')->willReturn($firewallConfig);

$listener = function () {};
$firewallContext->expects($this->once())->method('getListeners')->willReturn([$listener]);
Expand All @@ -88,5 +89,6 @@ public function testGetListeners()
$this->assertEquals([[$listener], $exceptionListener, $logoutListener], $firewallMap->getListeners($request));
$this->assertEquals($firewallConfig, $firewallMap->getFirewallConfig($request));
$this->assertEquals('security.firewall.map.context.foo', $request->attributes->get(self::ATTRIBUTE_FIREWALL_CONTEXT));
$this->assertTrue($request->attributes->get('_stateless'));
}
}