Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Security] Make AccessDecisionStrategy extensible. And add highestnotabstainedvoter strategy #15295

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

Conversation

solilokiam
Copy link

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14049
License MIT
Doc PR
  • submit changes to the documentation

This PR adds a new access decision strategy, called highest not abstained voter. The main idea of the voter is documented on issue #14049 .

At the same time the PR tries to make access decision strategy extensible. The way it's done is via any service that implements the newly created AccessDecisionManagerInterface and has the tag security.access_strategy

@solilokiam solilokiam force-pushed the extensible-accessdecision-strategy branch 3 times, most recently from e28edf1 to 52042eb Compare July 16, 2015 16:29
$strategy = $this->getStrategy($this->strategy);
$strategy->setVoters($this->voters);
$strategy->setAllowIfAllAbstainDecisions($this->allowIfAllAbstainDecisions);
$strategy->setAllowIfEqualGrantedDeniedDecisions($this->allowIfEqualGrantedDeniedDecisions);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is the desired way, why set it every decision? Why not just do it when building the container?

@stof
Copy link
Member

stof commented Jul 16, 2015

Actually, each strategy is just a different implementation of the AccessDecisionManagerInterface (especially if we remove supportsClass and supportsAttribute in 3.0 as we never use them in Symfony).

So I suggest refactoring this as 3 separate implementations, and having the existing class being a proxy class instantiating the right implementation in its constructor and then delegating decision calls.
This would avoid the need to introduce a new concept of a StrategyInterface with a weird API making it mutable just because of the need to enforce sharing the same state.

@solilokiam
Copy link
Author

Yes, I like the idea of getting rid of the StrategyInterface. I'm working on it.

foreach ($this->voters as $voter) {
if ($voter->supportsAttribute($attribute)) {
return true;
if(!array_key_exists($strategyName,$this->strategies))
Copy link
Contributor

Choose a reason for hiding this comment

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

Space missing before (

@wouterj
Copy link
Member

wouterj commented Jul 21, 2015

I like the idea of making this extendable, so a big thanks for starting this!

I've left some comments, most of them are really debatable things so if you don't agree with them, don't hesitate to comment instead of apply the change :)

Status: Needs Work

@solilokiam solilokiam force-pushed the extensible-accessdecision-strategy branch 2 times, most recently from 16bee34 to 74142ac Compare July 27, 2015 15:23
@solilokiam
Copy link
Author

Hi, one of the tests is failing in travis and I've got no idea why. Can anyone help me?

@wouterj
Copy link
Member

wouterj commented Jul 29, 2015

Afaik, it's failing because this tests installs 3.0-dev. In 3.0-dev, the new constrant in the Security component does not exists, so there is an error. After this PR is merged, it will be merged into master/3.0-dev as well. This means that after merging, the tests should pass.

/**
* {@inheritdoc}
*/
public function setVoters(array $voters)
Copy link
Member

Choose a reason for hiding this comment

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

there should be not setter here. this should be a constructor argument

Copy link
Member

Choose a reason for hiding this comment

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

ah no sorry, we have a setter currently

@solilokiam solilokiam force-pushed the extensible-accessdecision-strategy branch from 74142ac to c62e0bc Compare July 31, 2015 09:36
@solilokiam solilokiam force-pushed the extensible-accessdecision-strategy branch from c62e0bc to 5d5f4ef Compare July 31, 2015 09:38
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

/**
* Grants access depending on the first not abstained voter decission.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo in decission word!

Copy link
Member

Choose a reason for hiding this comment

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

by the way, the class is called Highest ... and here we mention first ... Should we change HighestNotAbstainedVoterAccessDecisionManager by FirstNotAbstainedVoterAccessDecisionManager ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I like the idea of calling it FirstNotAbstainedVoterAccessDecisionManager maybe it makes it clearer on what it does.

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

@solilokiam Can you rebase this one on current master and submit a new PR? As master is going to be 3.1, deprecated feature have been removed and this should make this PR easier.

@fabpot
Copy link
Member

fabpot commented Mar 2, 2016

@solilokiam Are you still interested in finishing this one?

@fabpot
Copy link
Member

fabpot commented Jun 9, 2016

Closing as there is no more activity here. Feel free to reopen with a new version of the patch that applies on current master.

@fabpot fabpot closed this Jun 9, 2016
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
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.

8 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.