Skip to content

[SecurityBundle] Integrate current firewall in Profiler #19490

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

Merged
merged 1 commit into from
Nov 2, 2016

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Jul 30, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT

Based on #19398.

This integrates current firewall information into the Profiler.

Toolbar
Profiler toolbar

Panel
Profiler panel

Examples:

Show config

main:
    pattern:   ^/
    anonymous: false
    stateless: true
    provider: in_memory
    access_denied_url: /access_denied
    http_basic: ~

Panel

Show config

main:
    pattern:   ^/
    anonymous: true
    stateless: false
    provider: in_memory
    context: dummy
    access_denied_url: /access_denied
    http_basic: ~

Panel

Show config

api:
    pattern:   ^/
    security: false

Panel

{% if collector.firewall|default([]) is not empty %}
<div class="sf-toolbar-info-piece">
<b>Firewall name</b>
<span>{{ collector.firewall.name }}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you should use the default filter as below

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

@HeahDude
Copy link
Contributor

HeahDude commented Jul 30, 2016

I've left some minor comments but that's a really nice PR, thanks!

@chalasr
Copy link
Member Author

chalasr commented Jul 30, 2016

Thank you @HeahDude, especially for your inputs about what it could be nice to see. I let you know when I made changes.

@chalasr chalasr force-pushed the firewalls_profiler_infos branch from fd9a5d2 to 6c706b7 Compare July 30, 2016 14:02
@chalasr
Copy link
Member Author

chalasr commented Jul 30, 2016

@HeahDude I did the changes and updated the description accordingly.
Hope I didn't forget anything.

@chalasr chalasr force-pushed the firewalls_profiler_infos branch from 6c706b7 to acd4cea Compare July 30, 2016 14:24
$this->data['firewall'] = $firewallContext->getConfig();
}
} else {
$this->data['firewall'] = array();
Copy link
Contributor

@ogizanagi ogizanagi Jul 30, 2016

Choose a reason for hiding this comment

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

So $this->data['firewall'] may either contain a FirewallConfig instance or an empty array if unavailable ? It's quite strange, isn't it ?
What about not setting it at all if unavailable, and returning false or null in getFirewall() ?

Twig checks will also make more sense:

- {% if collector.firewall|default([]) is not empty %}
+ {% if collector.firewall %}

What do you think ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally agreed.

Copy link
Contributor

Choose a reason for hiding this comment

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

While my preference would be to set it to null, the twig check should already work with an empty array:

> var_dump((bool) []);
bool(false)

Copy link
Member Author

Choose a reason for hiding this comment

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

I confirm it works, but let's do object or null.

@chalasr
Copy link
Member Author

chalasr commented Aug 2, 2016

I made the change and updated the description accordingly (screenshots).
Thanks to reviewers!

@chalasr chalasr force-pushed the firewalls_profiler_infos branch from 73fe755 to 54a4ec3 Compare August 2, 2016 18:27
@chalasr
Copy link
Member Author

chalasr commented Aug 2, 2016

Tests have been updated.

@@ -33,6 +33,12 @@
<span>{{ collector.tokenClass|abbr_class }}</span>
</div>
{% endif %}
{% if collector.firewall|default([]) is not empty %}
Copy link
Contributor

Choose a reason for hiding this comment

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

- {% if collector.firewall|default([]) is not empty %}
+ {% if collector.firewall %}

Copy link
Member Author

Choose a reason for hiding this comment

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

oops...

@chalasr chalasr force-pushed the firewalls_profiler_infos branch from 54a4ec3 to bab3497 Compare August 2, 2016 18:55
</div>
{% else %}
<div class="empty">
<p>The security component is disabled.</p>
Copy link
Member Author

@chalasr chalasr Aug 2, 2016

Choose a reason for hiding this comment

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

I'm thinking to remove this else statement. As is, this message would appear in both Security Token and Security Firewall sections. Maybe should I move the existing one in a higher position to make it hide the two sections?

@chalasr chalasr force-pushed the firewalls_profiler_infos branch 3 times, most recently from 16a7d92 to da9bc66 Compare August 2, 2016 23:28
@chalasr chalasr force-pushed the firewalls_profiler_infos branch 2 times, most recently from 3677070 to 0bcf5a2 Compare August 11, 2016 09:21
@chalasr
Copy link
Member Author

chalasr commented Aug 15, 2016

This PR and the base one are good to merge (or close).

@chalasr chalasr force-pushed the firewalls_profiler_infos branch 2 times, most recently from d1e1fb2 to 9a95c6e Compare September 21, 2016 23:27
@chalasr
Copy link
Member Author

chalasr commented Sep 21, 2016

Updated after #19614

@@ -132,6 +137,16 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data['voter_strategy'] = 'unknown';
$this->data['voters'] = array();
}

// collect firewall context informations
Copy link
Member

Choose a reason for hiding this comment

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

information

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@chalasr chalasr force-pushed the firewalls_profiler_infos branch 2 times, most recently from cd6c6b7 to 35cd6cd Compare September 25, 2016 14:24
@chalasr
Copy link
Member Author

chalasr commented Sep 25, 2016

I made the changes for using profiler_dump() properly and updated the description accordingly.

@chalasr chalasr force-pushed the firewalls_profiler_infos branch from 35cd6cd to 5100137 Compare October 3, 2016 17:19
@chalasr
Copy link
Member Author

chalasr commented Oct 4, 2016

@fabpot I think this one is ready

fabpot added a commit that referenced this pull request Oct 12, 2016
…ap (chalasr)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[SecurityBundle] Cache contexts per request in FirewallMap

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19819 (comment)
| License       | MIT
| Doc PR        | n/a

From @HeahDude in #19819 (comment), I propose to store and retrieve `Context` objects per `Request` using `SplObjectStorage`.

At the moment, contexts are consumed by the `Symfony\Components\Security\Http\Firewall` class only, but they could be indirectly by end users if #19490 and/or #19819 come to be merged.

Commits
-------

ffacec1 [SecurityBundle] Cache contexts per request in FirewallMap
@chalasr chalasr force-pushed the firewalls_profiler_infos branch 2 times, most recently from 83970b3 to fd82a18 Compare October 12, 2016 09:21
@rvanlaak
Copy link
Contributor

rvanlaak commented Oct 25, 2016

This one would be great, because it also would allow to add a "user logout link" to the profiler. Before this PR the required firewall wasn't available. Also see #17037 for a poc.

@chalasr
Copy link
Member Author

chalasr commented Nov 2, 2016

Imho Security is the most complex thing for beginners. The fact we don't provide informations about it (i.e. the current firewall and all the logic behind it) involves that any security issue requires to look deeper in the core, which leads to misunderstandings and lots of support issues (just answered one by saying to the user to change the order on which firewalls are defined, it would have been easy to debug with this in the profiler).

The lack of feedbacks is too bad here. Shall I close this?

@javiereguiluz
Copy link
Member

@chalasr please don't close it! You are right about the poor contents of the security profiler panel and debug toolbar.

private $userChecker;
private $listeners;

public function __construct($name, $requestMatcher, $securityEnabled = true, $stateless = false, $provider = null, $context = null, $entryPoint = null, $accessDeniedHandler = null, $accessDeniedUrl = null, $userChecker = null, $listeners = array())
Copy link
Contributor

Choose a reason for hiding this comment

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

So.. what about __construct(array $config)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I started with exactly what you propose and came to this.
Having distinct arguments is imho more structuring and gives more visibility about what the class provides. Also it avoids lots of isset($key) ? $key : null, we would have to build $config from SecurityExtension anyway.

Also, please see #19398 for this part, this depends on :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see :):) Think you're right.. this represents a config so the arguments dont add much complexity anyway.

if (null === $config) {
@trigger_error(sprintf('"%s()" expects an instance of "%s" as third argument since version 3.2 and will trigger an error in 4.0 if not provided.', __METHOD__, FirewallConfig::class), E_USER_DEPRECATED);

return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be removed. Perhaps put the deprecation on top.

@fabpot
Copy link
Member

fabpot commented Nov 2, 2016

Can you rebase now that the related PR is merged?

@chalasr chalasr force-pushed the firewalls_profiler_infos branch from fd82a18 to be2a55b Compare November 2, 2016 23:15
@chalasr chalasr force-pushed the firewalls_profiler_infos branch from be2a55b to 75e208e Compare November 2, 2016 23:16
@chalasr
Copy link
Member Author

chalasr commented Nov 2, 2016

Rebased

@fabpot
Copy link
Member

fabpot commented Nov 2, 2016

Thank you @chalasr.

@fabpot fabpot merged commit 75e208e into symfony:master Nov 2, 2016
fabpot added a commit that referenced this pull request Nov 2, 2016
…r (chalasr)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[SecurityBundle] Integrate current firewall in Profiler

| Q | A |
| --- | --- |
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | n/a |
| License | MIT |

 Based on #19398.

This integrates current firewall information into the Profiler.

**Toolbar**
![Profiler toolbar](http://image.prntscr.com/image/bedec39cea4945e994c8531b80241cf6.png)

**Panel**
![Profiler panel](http://image.prntscr.com/image/3b656c1346844c6194a0db42cb8f9fdc.png)

Examples:

<details>
 <summary>

Show config</summary>

``` yaml
main:
    pattern:   ^/
    anonymous: false
    stateless: true
    provider: in_memory
    access_denied_url: /access_denied
    http_basic: ~
```

</details>

![Panel](http://image.prntscr.com/image/057062a1da744f3c8e00c3c77ded46a8.png)

<details>
 <summary>

Show config</summary>

``` yaml
main:
    pattern:   ^/
    anonymous: true
    stateless: false
    provider: in_memory
    context: dummy
    access_denied_url: /access_denied
    http_basic: ~
```

</details>

![Panel](http://image.prntscr.com/image/a44e54cf018d4bc98c3e0ecf92c37416.png)

<details>
 <summary>

Show config</summary>

``` yaml
api:
    pattern:   ^/
    security: false
```

</details>

![Panel](http://image.prntscr.com/image/c4ea3d7c792447b2ae2b18cd4e08d0dd.png)

Commits
-------

75e208e Integrate current firewall in profiler
@chalasr chalasr deleted the firewalls_profiler_infos branch November 2, 2016 23:44
@fabpot fabpot mentioned this pull request Nov 17, 2016
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.

9 participants