-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[SecurityBundle] Move cache of the firewall context into the request parameters #22943
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
Conversation
private function getFirewallContext(Request $request) | ||
{ | ||
if ($this->contexts->contains($request)) { | ||
return $this->contexts[$request]; | ||
if ($request->attributes->has('_firewall_context')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should validate that $request->attributes->get('_firewall_context')
is a valid key of $this->map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. And added test assertions on the value of this attribute.
why is it opened against the master branch if you want it for 3.4 ? master is 4.0 |
return $this->contexts[$request]; | ||
if ($request->attributes->has('_firewall_context')) { | ||
$contextId = $request->attributes->get('_firewall_context'); | ||
if (array_key_exists($contextId, $this->map)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->map
can be Traversable
(and it is)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build failures unrelated
Is it possible that a sub-request get created with all the attributes of its master request? In that case, using the request attributes as a cache would be wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it target 3.4. Looks like a bug fix to me, so it should be done in earliest branches as well.
@@ -141,15 +139,29 @@ public function getFirewallConfig(Request $request) | |||
return $context->getConfig(); | |||
} | |||
|
|||
/** | |||
* @param Request $request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed
/** | ||
* @param Request $request | ||
* | ||
* @return \Symfony\Bundle\SecurityBundle\Security\FirewallContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add a use
statement and use FirewallContext
here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this change, fabbot reports is as an unused import and removes the use
statement.
f335537
to
e306ec0
Compare
@fabpot The cache was introduced in 3.2. I've updated the PR. |
@@ -11,6 +11,8 @@ | |||
|
|||
namespace Symfony\Bundle\SecurityBundle\Security; | |||
|
|||
use Psr\Container\ContainerInterface; | |||
use Symfony\Bundle\SecurityBundle\Security\FirewallContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing ;
at then end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, fixed.
aa9745d
to
3108023
Compare
Validate that _firewall_context attribute is in the map keys
3108023
to
ffaceb1
Compare
Tests are broken. |
|
||
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock(); | ||
$firewallContext->expects($this->once())->method('getConfig')->willReturn('CONFIG'); | ||
$firewallContext->expects($this->once())->method('getContext')->willReturn(array('LISTENERS', 'EXCEPTION LISTENER')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merging into 3.3, getContext
is replaced by getListeners
and getExceptionListener
, update this line to:
$firewallContext->expects($this->once())->method('getListeners')->willReturn('LISTENERS');
$firewallContext->expects($this->once())->method('getExceptionListener')->willReturn('EXCEPTION LISTENER');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks
Thank you @GromNaN. |
…he request parameters (GromNaN) This PR was squashed before being merged into the 3.2 branch (closes #22943). Discussion ---------- [SecurityBundle] Move cache of the firewall context into the request parameters Following [this proposal](#22605 (comment)). Since the matching context relates to the request, this information should have been cached inside the request parameters. | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22605 | License | MIT | Doc PR | n/a * Avoid memory leak when handling multiple requests * Adding the new request parameter `_firewall_context` might be considered as a breaking change. That adds a new "public" property that could be used by end developers. Commits ------- b3203cb [SecurityBundle] Move cache of the firewall context into the request parameters
should be closed |
…ncyweb) This PR was merged into the 3.4 branch. Discussion ---------- [SecurityBundle][FirewallMap] Remove unused property | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | no | License | MIT | Doc PR | - This property is unused. It was removed in #22943. It was likely reintroduced in a merge commit. It is still on master. Commits ------- 0904e57 [SecurityBundle][FirewallMap] Remove unused property
Following this proposal. Since the matching context relates to the request, this information should have been cached inside the request parameters.
_firewall_context
might be considered as a breaking change. That adds a new "public" property that could be used by end developers.