Skip to content

[Security] make it possible to configure a custom access decision manager service #19034

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

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Jun 12, 2016

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #942, #14049, #15295, #16828, #16843,
License MIT
Doc PR TODO

These changes will make it possible to let users define their own voting strategies without the need for custom compiler passes that replace the built-in AccessDecisionManager (see linked issues in the PR table for some use cases).

*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class StrategyAwareAccessDecisionManager implements AccessDecisionManagerInterface
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 really like this name. So I welcome any suggestions for something better.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not really sure why you introduced a new class here, it looks like the old class has equal behaviour?

Copy link
Member

Choose a reason for hiding this comment

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

If we want to deprecate the old one in favor of this one, I would call it VotingAccessDecisionManager or the like. The special thing about this implementation is that it uses voters to decide the access.

@xabbuh
Copy link
Member Author

xabbuh commented Jun 12, 2016

I just realised that @hhamon suggested almost the same years ago (see #942) which was closed in favour of creating more specialised access decision managers (though that never happened). What do you think about that idea? Should we create one class per access decision strategy instead and then make it easier to inject your own access decision manager by introducing a new config option in the SecurityBundle?

@xabbuh
Copy link
Member Author

xabbuh commented Jun 23, 2016

@symfony/deciders What are your thoughts on this?

@fabpot
Copy link
Member

fabpot commented Jun 23, 2016

Not sure if we need to create classes for existing strategies, we could keep them inline as today. If not, I would make those classes final.


if ($strategy instanceof VoteStrategyInterface) {
$this->voteStrategy = $strategy;
} elseif (self::STRATEGY_AFFIRMATIVE === $strategy) {
Copy link
Member

Choose a reason for hiding this comment

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

what about deprecating passing a string as strategy?

Copy link
Contributor

Choose a reason for hiding this comment

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

And maybe removing allowIfAllAbstainDecisions, allowIfEqualGrantedDeniedDecisions from constructor of this class in future?

@wouterj
Copy link
Member

wouterj commented Jul 2, 2016

I like the idea of having all strategies in seperate classes and configuring the service ID of the strategy to use (with a shortcut for security.strategy.%s IDs, so affirmative will set the security.strategy.affirmative service and app.custom_strategy will use that ID).

@wouterj
Copy link
Member

wouterj commented Jul 2, 2016

Status: needs work

@xabbuh
Copy link
Member Author

xabbuh commented Jul 4, 2016

I like the idea of having all strategies in seperate classes and configuring the service ID of the strategy to use [...]

@wouterj My main concern is if we really need to go the way of custom strategies then or if it wasn't enough to configure a service implementing the AuthenticationManagerInterface and then making it easy to change that service?

@fabpot
Copy link
Member

fabpot commented Nov 9, 2016

@xabbuh Any interest in finishing this one by taking into account comments?

@xabbuh
Copy link
Member Author

xabbuh commented Nov 10, 2016

Well, we should first decide which way we would like to go (i.e. making the vote strategy configurable or making it possible to configure the access decision manager like suggested in #942). I think my favourite solution is to keep the separated vote strategies for greater flexibility (as they are now in this PR), but remove the StrategyAwareAccessDecisionManager and instead allow just configure the access decision manager service in the SecurityBundle (you will only be able to configure either the access decision manager or the vote strategy). What do you think?

@wouterj
Copy link
Member

wouterj commented Nov 10, 2016

On second thought, I think we should remove the strategy stuff and just allow to configure the AccessDecisionManager service ID. With the VoteStrategyInterface, we add an extra layer of complexity for almost nothing. The AccessDecisionManager simply only proxies it's decide() call to the VoteStrategy and there is no other code in the manager.

So simply creating a custom manager and setting it through a service should be more than enough.

@xabbuh xabbuh force-pushed the configurable-access-decision-strategy branch from 6ef3459 to 7ec99f0 Compare November 16, 2016 08:09
@xabbuh xabbuh force-pushed the configurable-access-decision-strategy branch 2 times, most recently from 6417e74 to c28ca0a Compare November 28, 2016 08:09
@xabbuh
Copy link
Member Author

xabbuh commented Nov 28, 2016

I pushed an update that reverts the changes made to the AccessDecisionManager, but makes it possible to configure a service providing an AccessDecisionManagerInterface implementation.

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@xabbuh
Copy link
Member Author

xabbuh commented Dec 14, 2016

ping @symfony/deciders

@HeahDude
Copy link
Contributor

Does it make sense to keep the strategy configurable for a custom access decision manager as a service?

@xabbuh
Copy link
Member Author

xabbuh commented Dec 17, 2016

@HeahDude I first thought when I introduced the VoteStrategyInterface. But thinking about it again I don't think there's much value in having reusable voting strategies. Reusing them wouldn't be much different from using the built-in access decision manager IMO.

@xabbuh xabbuh force-pushed the configurable-access-decision-strategy branch from c28ca0a to 4abe705 Compare December 27, 2016 10:47
@xabbuh
Copy link
Member Author

xabbuh commented Dec 27, 2016

Status: Needs Review

@xabbuh xabbuh force-pushed the configurable-access-decision-strategy branch 2 times, most recently from 099c769 to 9a8779f Compare January 30, 2017 16:08
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

@nicolas-grekas nicolas-grekas modified the milestones: 3.3, 3.x Mar 7, 2017
@xabbuh xabbuh force-pushed the configurable-access-decision-strategy branch from 9a8779f to 1d5a5c6 Compare April 3, 2017 15:27
@nicolas-grekas
Copy link
Member

Moving to milestone as this is not a blocker for 3.3. If you don't agree, please explain why.

@nicolas-grekas nicolas-grekas modified the milestones: 3.3, 3.4 Apr 28, 2017
@xabbuh xabbuh changed the base branch from master to 3.4 May 18, 2017 07:16
@xabbuh xabbuh force-pushed the configurable-access-decision-strategy branch from 1d5a5c6 to ba9fd2f Compare June 3, 2017 07:52
@xabbuh
Copy link
Member Author

xabbuh commented Jun 3, 2017

PR description updated to match the actual state of this PR (the idea of a VoteStrategyInterface was dropped in favour of being able to configure your own AccessDecisionManager service).

@xabbuh xabbuh changed the title [Security] make it possible to configure the voting strategy [Security] make it possible to configure a custom access decision manager service Jun 3, 2017
@xabbuh xabbuh force-pushed the configurable-access-decision-strategy branch from ba9fd2f to e0913a2 Compare July 3, 2017 16:47
@nicolas-grekas
Copy link
Member

ping @symfony/deciders

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit e0913a2 into symfony:3.4 Jul 12, 2017
@nicolas-grekas
Copy link
Member

Doc PR welcomed ;)

nicolas-grekas added a commit that referenced this pull request Jul 12, 2017
…ss decision manager service (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Security] make it possible to configure a custom access decision manager service

| Q | A |
| --- | --- |
| Branch? | 3.4 |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #942, #14049, #15295, #16828, #16843, |
| License | MIT |
| Doc PR | TODO |

These changes will make it possible to let users define their own voting strategies without the need for custom compiler passes that replace the built-in `AccessDecisionManager` (see linked issues in the PR table for some use cases).

Commits
-------

e0913a2 add option to define the access decision manager
@xabbuh xabbuh deleted the configurable-access-decision-strategy branch July 12, 2017 16:19
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.

9 participants