Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 2 commits into from

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented May 29, 2017

Following this proposal. 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.

private function getFirewallContext(Request $request)
{
if ($this->contexts->contains($request)) {
return $this->contexts[$request];
if ($request->attributes->has('_firewall_context')) {
Copy link
Member

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

Copy link
Member Author

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.

@stof
Copy link
Member

stof commented May 29, 2017

why is it opened against the master branch if you want it for 3.4 ? master is 4.0

@GromNaN GromNaN changed the base branch from master to 3.4 May 29, 2017 17:25
@GromNaN GromNaN changed the base branch from 3.4 to master May 29, 2017 17:26
@GromNaN GromNaN force-pushed the firewall-context branch from 9aa00ce to 664b413 Compare May 29, 2017 17:26
@GromNaN GromNaN changed the base branch from master to 3.4 May 29, 2017 17:26
@GromNaN GromNaN force-pushed the firewall-context branch from aef5787 to 1622703 Compare May 29, 2017 17:37
return $this->contexts[$request];
if ($request->attributes->has('_firewall_context')) {
$contextId = $request->attributes->get('_firewall_context');
if (array_key_exists($contextId, $this->map)) {
Copy link
Member

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)

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone May 30, 2017
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build failures unrelated

@GromNaN GromNaN force-pushed the firewall-context branch from d9625f4 to e4e7454 Compare June 5, 2017 20:27
@GromNaN
Copy link
Member Author

GromNaN commented Jun 5, 2017

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.

Copy link
Member

@fabpot fabpot left a 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
Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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.

@GromNaN GromNaN force-pushed the firewall-context branch 2 times, most recently from f335537 to e306ec0 Compare June 9, 2017 12:19
@GromNaN GromNaN changed the base branch from 3.4 to 3.2 June 9, 2017 12:19
@GromNaN GromNaN force-pushed the firewall-context branch from e306ec0 to aa9745d Compare June 9, 2017 12:23
@GromNaN
Copy link
Member Author

GromNaN commented Jun 9, 2017

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing ; at then end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, fixed.

@GromNaN GromNaN force-pushed the firewall-context branch from aa9745d to 3108023 Compare June 10, 2017 16:32
Validate that _firewall_context attribute is in the map keys
@GromNaN GromNaN force-pushed the firewall-context branch from 3108023 to ffaceb1 Compare June 10, 2017 16:41
@fabpot
Copy link
Member

fabpot commented Jun 10, 2017

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'));
Copy link
Member Author

@GromNaN GromNaN Jun 10, 2017

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');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks

@fabpot
Copy link
Member

fabpot commented Jun 14, 2017

Thank you @GromNaN.

fabpot added a commit that referenced this pull request Jun 14, 2017
…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
@chalasr
Copy link
Member

chalasr commented Jun 14, 2017

should be closed

@fabpot fabpot closed this Jun 14, 2017
This was referenced Jul 4, 2017
nicolas-grekas added a commit that referenced this pull request Dec 13, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants