Skip to content

[SecurityBundle][Profiler] Give info about called security listeners in profiler #23105

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
Jun 13, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Jun 8, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #11134
License MIT
Doc PR n/a

Currently the profiler gives no info about security listeners (see fixed ticket), this displays each called listener with the time spent at calling it and its response if any.

preview

@@ -56,4 +56,12 @@ public function onKernelFinishRequest(FinishRequestEvent $event)

parent::onKernelFinishRequest($event);
}

/**
* @internal
Copy link
Member

Choose a reason for hiding this comment

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

I think it's OK to not atg this as internal (same below)

@chalasr chalasr force-pushed the secu-record-listeners branch 2 times, most recently from 493097e to 813ce0a Compare June 8, 2017 13:23
*/
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null)
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, TraceableFirewallListener $firewall = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a BC break, right? What about removing the typehint for now with proper deprecation and BC support, and re-add it on 4.0?

Copy link
Member Author

@chalasr chalasr Jun 8, 2017

Choose a reason for hiding this comment

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

Seems like. We could also inject both FirewallMap and TraceableFirewallListener distinctively, removing the getter added here. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me to inject both and remove the getter, yes.


public function getInfo()
{
$pretty = get_class($this->listener);
Copy link
Contributor

Choose a reason for hiding this comment

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

- $pretty
+ $class

? (I spotted this comes from Symfony\Component\EventDispatcher\Debug\WrappedListener, but there isn't the same treatment here. Let's be more explicit). Do you even need it ?

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 suffixing by ::handle() for finally removing it, ok for $class

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 don't need it :) good catch

@chalasr chalasr force-pushed the secu-record-listeners branch 3 times, most recently from 48f5e96 to 1f36aa8 Compare June 8, 2017 21:37
@chalasr
Copy link
Member Author

chalasr commented Jun 9, 2017

Comments addressed. Build failure on deps=high is normal because the security component is updated here.

@@ -14,6 +14,7 @@
<argument type="service" id="security.logout_url_generator" />
<argument type="service" id="security.access.decision_manager" />
<argument type="service" id="security.firewall.map" />
<argument type="service" id="security.firewall" />
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't inject explicitly debug.security.firewall here, you can't typehint TraceableFirewallListener, but should add an instanceof check in the collector, otherwise it'll break in non debug mode when the TraceableFirewallListener does not decorates security.firewall (I still don't get why we would have collectors in non-debug mode though...).

IMHO, it's better to keep your collector as you did, but inject debug.security.firewall with on-invalid="null" here.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to inject debug.security.firewall or null as suggested

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jun 9, 2017
@chalasr chalasr force-pushed the secu-record-listeners branch 3 times, most recently from b549295 to 6065367 Compare June 9, 2017 13:08
@chalasr
Copy link
Member Author

chalasr commented Jun 11, 2017

This is ready.

@chalasr chalasr force-pushed the secu-record-listeners branch 2 times, most recently from f4be835 to aef1b6f Compare June 11, 2017 12:32
*
* @author Robin Chalas <robin.chalas@gmail.com>
*
* @final since version 3.4
Copy link
Member

Choose a reason for hiding this comment

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

Why are you using the tag here instead of marking the class as being final directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

To ease maintenance while keeping extensibility: one could add more info per listener and if a day we don't need this method for dumping the object, the breaking change would be free

Copy link
Member

Choose a reason for hiding this comment

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

I don't get it. This class could even be marked as being internal. I would definitely mark it as final.

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

*
* @author Robin Chalas <robin.chalas@gmail.com>
*
* @final since version 3.4
Copy link
Member

Choose a reason for hiding this comment

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

same here

*/
class WrappedListener implements ListenerInterface
{
public $response;
Copy link
Member

Choose a reason for hiding this comment

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

Why is it public?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not anymore

@chalasr chalasr force-pushed the secu-record-listeners branch from aef1b6f to a7514fc Compare June 12, 2017 08:10
@@ -10,5 +10,11 @@
<service id="debug.security.access.decision_manager" class="Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager" decorates="security.access.decision_manager">
<argument type="service" id="debug.security.access.decision_manager.inner" />
</service>

<service id="debug.security.firewall" class="Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener" decorates="security.firewall" public="true">
Copy link
Member

Choose a reason for hiding this comment

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

this service should not be public. There is no reason to do a `$container->get('debug.security.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.

done but that means the bundle needs a conflict for the dispatcher as event subscribers must be public before 3.3

@@ -10,5 +10,11 @@
<service id="debug.security.access.decision_manager" class="Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager" decorates="security.access.decision_manager">
<argument type="service" id="debug.security.access.decision_manager.inner" />
</service>

<service id="debug.security.firewall" class="Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener" decorates="security.firewall" public="true">
Copy link
Member

Choose a reason for hiding this comment

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

Using a decorator is weird here, as it does not perform decoration actually (it never uses the inner service).

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 secu-record-listeners branch 3 times, most recently from c72a273 to 3ff46f1 Compare June 13, 2017 00:18
@chalasr chalasr force-pushed the secu-record-listeners branch from 3ff46f1 to e767231 Compare June 13, 2017 00:24
@chalasr chalasr force-pushed the secu-record-listeners branch from e767231 to 369f19f Compare June 13, 2017 08:31
@chalasr
Copy link
Member Author

chalasr commented Jun 13, 2017

rebased

@fabpot
Copy link
Member

fabpot commented Jun 13, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 369f19f into symfony:3.4 Jun 13, 2017
fabpot added a commit that referenced this pull request Jun 13, 2017
…rity listeners in profiler (chalasr)

This PR was merged into the 3.4 branch.

Discussion
----------

[SecurityBundle][Profiler] Give info about called security listeners in profiler

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

Currently the profiler gives no info about security listeners (see fixed ticket), this displays each called listener with the time spent at calling it and its response if any.

![preview](https://image.prntscr.com/image/Wx-n-Ni_RQK5JGTdTZsdGw.png)

Commits
-------

369f19f Give info about called security listeners in profiler
@chalasr chalasr deleted the secu-record-listeners branch June 13, 2017 16:29
This was referenced Oct 18, 2017
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.

6 participants