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

Skip to content

Show more information in the security profiler #17887

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 15 commits into from

Conversation

javiereguiluz
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #17856
License MIT
Doc PR -

This is an early prototype to explore the feature of displaying more information in the security panel. Example:

profiler_security

@HeahDude
Copy link
Contributor

Really awesome ! Many thanks for that feature !


/**
* AccessDecisionManager is the base class for all access decision managers
* that use decision voters.
Copy link
Member

Choose a reason for hiding this comment

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

This docblock looks wrong.

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. Thanks.

@fabpot
Copy link
Member

fabpot commented Feb 29, 2016

@javiereguiluz Can you rebase as tests have been fixed since your submitted the PR.

*
* @author Javier Eguiluz <[email protected]>
*/
class DebugAccessDecisionManager implements AccessDecisionManagerInterface //extends AccessDecisionManager
Copy link
Member

Choose a reason for hiding this comment

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

The comment should probably be removed here, right?

@fabpot
Copy link
Member

fabpot commented Feb 29, 2016

Apart from my minor comments, 👍

@javiereguiluz
Copy link
Member Author

I've made all the requested changes (thanks for the review!) ... but before merging this, it should be tested by someone which works on Symfony apps with complex security needs (maybe @iltar could help us?)

@linaori
Copy link
Contributor

linaori commented Feb 29, 2016

@javiereguiluz sadly still running on 2.8 in the application I can test it on properly. The 3.0 upgrade will be done somewhere starting in 2 weeks as we are still gathering deprecations in our production env. Maybe I'll be able to upgrade just the security bundle as most (if not all) of those are already fixed.

@linaori
Copy link
Contributor

linaori commented Mar 1, 2016

@javiereguiluz I've downloaded your branch as zip, extracted it and symlinked vendor/symfony/symfony to your branch. However, I cannot get it to work. The error I'm getting is Warning: Invalid argument supplied for foreach():

issue 1

Most important part of the stacktrace:

in SecurityDataCollector.php line 117
at ErrorHandler->handleError('2', 'Invalid argument supplied for foreach()', '/home/ivanderberg/projects/forks/symfony-fix_17856/src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php', '117', ...)

I've checked the service and it has the DebugAccessDecisionManager which is correct. However, getVoters() returns null. I've checked and setVoters() is never called. I've traced that back to AddSecurityVotersPass:48:

$container->getDefinition('security.access.decision_manager')->addMethodCall('setVoters', array(array_values($voters)));

There's 2 possible solutions:

  • DebugAccessDecisionManager setVoters()should be removed andgetVoters()should forward the call to$this->manager. Sadly this class doesn't havegetVoters()` yet so it will have to be added.
  • The setVoters() should also be called on the decorating service. It seems like this is not added because the decoration pass is later (correct me if I'm wrong)

issue 2

After patching either one of the above issues, I have a serialization issue "You cannot serialize or unserialize PDO instances". The @template is being cached now and causes the bug I fixed in this pending PR: sensiolabs/SensioFrameworkExtraBundle#404. However, fixing this issue didn't solve my serialization issue. After digging a bit deeper it made sense... The request also contains your session. This means that if you use a database session storage like I do, it will try to serialize this. This will also fail if you use the @ParamConverter and put objects in your attribute bag.

I've changed DebugAccessDecisionManager:50 to 'object' => is_object($object) ? get_class($object) : gettype($object), and now it works. In the actual PR you might want to use the ClassUtils from doctrine to fetch the actual class though, otherwise you'll see useless proxy names.


After fixing

The following screens are on my login page. The first thing I notice is that the Token column might be redundant.


When I'm logged in, it shows more information on my dashboard. The things I notice:

  • The attributes are not shown in the most readable format for the most common case (1 attribute).
  • Column numbers get put on multiple lines
  • The Token column is redundant
  • I'm unable to trace back where it came from (but this could be a future PR)



When viewing a page which as a lot of isGranted() checks, it becomes hard to trace back the data. Maybe it could be grouped but that would be annoying to trace back either way. A nice feature that I'm missing is the ability to show the "identifier" of an entity in this case. In this list it looks like I have inconsistent results while in fact it's 80 different entities being checked in a list. Finding the identifier might be nice as it will help debugging a lot but you will run into the same issue I have: linaori/http-bundle#12.


and the list goes on


Looking at a page with less different objects, it becomes a bit of a mess as well.


Conclusion

It's a nice start but with lots of information it becomes a mess really quick. A possible solution would be to group the checks per object (via object hash?) and to add the ID of an object if managed by doctrine (plug & play system so people can hook in?). Additionally the last column could be removed and the attributes shown with the just attribute as comma imploded string.

@javiereguiluz
Copy link
Member Author

@iltar thank you very much for your incredible review!!

I've made some changes as requested:

  • Removed the token column in the decision log
  • Improved the way we display attributes when there is only 1 attribute
  • Tried to improve the way objects are represented (this needs to be tested)
  • Related to previous one: don't store objects to avoid serializing errors
  • Other minor design tweaks

I still need to fix the setVoters() problem.

@linaori
Copy link
Contributor

linaori commented Mar 1, 2016

Once the setVoters() is fixed I'll run it through the application again if I have some time today, otherwise it will be tomorrow. Can you ping me when it's ready to be tested?

@javiereguiluz
Copy link
Member Author

@iltar it should be ready for review. Thanks!

@linaori
Copy link
Contributor

linaori commented Mar 1, 2016

Not sure if the Request gives the desired effect now, but works for me:

The list is a lot easier to read now but differences between objects is still hard to find. I suppose getting the actual ID field + the value of the object in question (if entity) would be too hard to implement in this patch for now. It's already an improvement but it takes a lot of time to see the different objects.

2 different objects

Many different objects

Found one with a basic type, someone found it necessary to use an ID instead of an object...
image

Besides of the minor comments (which are hard to fix), I think this shows a lot of usable information already. What I would still like to see is a way to identify an Entity in a generic fashion; I need it mysel and it could be re-used here to show useful info.


I hope this helps 👍

@javiereguiluz
Copy link
Member Author

@iltar great! We're making progress here. I've just added a special case to check if getId() method exists to use it instead of the object hash. I think it's worth it because getId() is used very commonly.

@linaori
Copy link
Contributor

linaori commented Mar 1, 2016

I agree that this covers most use-cases. In a later stage I would like to ask the entity metadata what the identifier is, but I want this done in a generic fashion as not everything is a doctrine entity for example which probably blows up the scope of this PR.

@fabpot
Copy link
Member

fabpot commented Mar 1, 2016

Good to merge? ping @symfony/deciders

// collect voters and access decision manager information
if (null !== $this->accessDecisionManager) {
$this->data['access_decision_log'] = $this->accessDecisionManager->getDecisionLog();
$this->data['voter_strategy'] = $this->accessDecisionManager->getStrategy();
Copy link
Member

Choose a reason for hiding this comment

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

Both the getDecisionLog() and getStrategy() methods may not exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could typehint against the DebugAccessDecisionManager, good to let it crash if you run this incorrectly imo

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've made this change. Is this what you suggested?

-if (null !== $this->accessDecisionManager) {
+if ($this->accessDecisionManager instance of DebugAccessDecisionManager) {

@javiereguiluz
Copy link
Member Author

I've tested all kinds of attributes and objects and it seems to work as expected:

access_decision_log

The Travis errors are unrelated.

@linaori
Copy link
Contributor

linaori commented Mar 3, 2016

That looks really nice and useful! 👍

@fabpot
Copy link
Member

fabpot commented Mar 4, 2016

Thank you @javiereguiluz.

@fabpot fabpot closed this Mar 4, 2016
fabpot added a commit that referenced this pull request Mar 4, 2016
…eguiluz)

This PR was squashed before being merged into the 3.1-dev branch (closes #17887).

Discussion
----------

Show more information in the security profiler

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17856
| License       | MIT
| Doc PR        | -

This is an early prototype to explore the feature of displaying more information in the security panel. Example:

![profiler_security](https://cloud.githubusercontent.com/assets/73419/13221929/0235fc46-d97e-11e5-981a-249b7148f3a6.png)

Commits
-------

b12152d Show more information in the security profiler
@felipsmartins
Copy link

Great great great!!! Congrats @javiereguiluz @iltar

fabpot added a commit that referenced this pull request Mar 10, 2016
…on (xabbuh)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[SecurityBundle] fix lowest required Security Core version

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17887
| License       | MIT
| Doc PR        |

Commits
-------

4283cd7 fix lowest required Security Core version
@fabpot fabpot mentioned this pull request May 13, 2016
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
…(javiereguiluz)

This PR was squashed before being merged into the 3.1-dev branch (closes symfony#17887).

Discussion
----------

Show more information in the security profiler

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#17856
| License       | MIT
| Doc PR        | -

This is an early prototype to explore the feature of displaying more information in the security panel. Example:

![profiler_security](https://cloud.githubusercontent.com/assets/73419/13221929/0235fc46-d97e-11e5-981a-249b7148f3a6.png)

Commits
-------

b12152d Show more information in the security profiler
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