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

Skip to content

[Security] remove support for defining voters that don't implement VoterInterface. #23324

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 29, 2017

Conversation

hhamon
Copy link
Contributor

@hhamon hhamon commented Jun 28, 2017

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

@hhamon hhamon force-pushed the security-voterinterface branch 2 times, most recently from 84f6f5c to 4b91fb5 Compare June 28, 2017 22:32
UPGRADE-4.0.md Outdated
@@ -455,6 +455,8 @@ Security
* The `AccessDecisionManager::setVoters()` method has been removed. Pass the
voters to the constructor instead.

* Defining voters that don't implement the `VoterInterface` interface has been removed.
Copy link
Member

Choose a reason for hiding this comment

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

Support for defining [...]

if (!method_exists($class, 'vote')) {
// in case the vote method is completely missing, to prevent exceptions when voting
throw new LogicException(sprintf('%s should implement the %s interface when used as voter.', $class, VoterInterface::class));
throw new LogicException(sprintf('%s must implement the %s interface when used as voter.', $class, VoterInterface::class));
Copy link
Member

Choose a reason for hiding this comment

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

I would remove the "interface" here (it's already part of the interface name)

Copy link
Member

Choose a reason for hiding this comment

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

[...] used as a voter.

@@ -8,7 +8,8 @@ CHANGELOG
You should implement this method yourself in your concrete authenticator.
* removed the `AccessDecisionManager::setVoters()` method
* removed the `RoleInterface`
* added a sixth `string $context` argument to`LogoutUrlGenerator::registerListener()`
* removed support for voters that don't implement the `VoterInterface` interface
Copy link
Member

Choose a reason for hiding this comment

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

I would remove "interface" here

*
* @deprecated as of 3.4 and will be removed in 4.0. Call the voter directly as the instance will always be a VoterInterface
*/
private function vote($voter, TokenInterface $token, $subject, $attributes)
Copy link
Member

Choose a reason for hiding this comment

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

we could now update the docblock of the constructor so that the type hint for the $voters argument is now VoterInterface[] instead of iterable|VoterInterface[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum I'm not sure! It seems that SecurityBundle passes an iterator argument to the access decision manager so that voters can be lazy loaded.

Copy link
Contributor Author

@hhamon hhamon Jun 29, 2017

Choose a reason for hiding this comment

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

// AddSecurityVotersPass.php
$adm = $container->getDefinition('security.access.decision_manager');
$adm->replaceArgument(0, new IteratorArgument($voters));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can only change the dockblock but not the signature as passing iterators must still be allowed.

Copy link
Member

Choose a reason for hiding this comment

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

VoterInterface[] means array of VoterInterface instances. So we cannot remove iterable from the phpdoc, otherwise we effectively remove the support of iterators from our supported usage (and so from our BC promise). This is quite problematic when our own usage relies on it.

Copy link
Member

Choose a reason for hiding this comment

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

Hum, I thought VoterInterface[] means something I can iterate over.

@hhamon hhamon force-pushed the security-voterinterface branch from 4b91fb5 to 7c400d9 Compare June 29, 2017 09:31
@hhamon
Copy link
Contributor Author

hhamon commented Jun 29, 2017

Changes applied.

@hhamon hhamon force-pushed the security-voterinterface branch from 7c400d9 to 1bb6f73 Compare June 29, 2017 09:36
@@ -8,7 +8,8 @@ CHANGELOG
You should implement this method yourself in your concrete authenticator.
* removed the `AccessDecisionManager::setVoters()` method
* removed the `RoleInterface`
* added a sixth `string $context` argument to`LogoutUrlGenerator::registerListener()`
* removed support for voters that don't implement the `VoterInterface`
* added a sixth `string $context` argument to`LogoutUrlGenerator::registerListener()`
Copy link
Member

Choose a reason for hiding this comment

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

please don't add a trailing whitespace in this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oups was a mistake.

@@ -33,7 +32,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
private $allowIfEqualGrantedDeniedDecisions;

/**
* @param iterable|VoterInterface[] $voters An iterator of VoterInterface instances
* @param iterable|VoterInterface[] $voters An array (or an iterator) of VoterInterface instances
Copy link
Member

Choose a reason for hiding this comment

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

I would not put t in braces

@hhamon hhamon force-pushed the security-voterinterface branch from 1bb6f73 to 3db09a6 Compare June 29, 2017 09:47
@hhamon
Copy link
Contributor Author

hhamon commented Jun 29, 2017

@stof fixed

@hhamon hhamon force-pushed the security-voterinterface branch from 3db09a6 to f527790 Compare June 29, 2017 09:48
@fabpot
Copy link
Member

fabpot commented Jun 29, 2017

Thank you @hhamon.

@fabpot fabpot merged commit f527790 into symfony:master Jun 29, 2017
fabpot added a commit that referenced this pull request Jun 29, 2017
…'t implement VoterInterface. (hhamon)

This PR was merged into the 4.0-dev branch.

Discussion
----------

[Security] remove support for defining voters that don't implement VoterInterface.

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

Commits
-------

f527790 [Security] remove support for defining voters that don't implement the VoterInterface interface.
@hhamon hhamon deleted the security-voterinterface branch June 30, 2017 07:29
@fabpot fabpot mentioned this pull request Oct 19, 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