-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Security] Add strategy resolvers #21178
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
fancyweb
wants to merge
3
commits into
symfony:master
from
fancyweb:access-decision-strategy-resolver
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
[Security] Add strategy resolvers
- Loading branch information
commit 3eafdf2b4ca61e885bf4fce364a4e2fb1ea8eaf5
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddStrategyResolversPass.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
class AddStrategyResolversPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('security.access.decision_manager')) { | ||
return; | ||
} | ||
|
||
$strategyResolvers = new \SplPriorityQueue(); | ||
foreach ($container->findTaggedServiceIds('security.strategy_resolver') as $id => $attributes) { | ||
$class = $container->getDefinition($id)->getClass(); | ||
$interface = 'Symfony\Component\Security\Core\Authorization\StrategyResolverInterface'; | ||
if (!is_subclass_of($class, $interface)) { | ||
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface)); | ||
} | ||
|
||
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0; | ||
$strategyResolvers->insert(new Reference($id), $priority); | ||
} | ||
|
||
$strategyResolvers = iterator_to_array($strategyResolvers); | ||
ksort($strategyResolvers); | ||
|
||
$container->getDefinition('security.access.decision_manager')->replaceArgument(4, array_values($strategyResolvers)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Symfony/Component/Security/Core/Authorization/StrategyResolverInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Core\Authorization; | ||
|
||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
|
||
interface StrategyResolverInterface | ||
{ | ||
< 6456 td class="blob-code blob-code-addition js-file-line"> /** | ||
* This method must return one of the following constants from the AccessDecisionManager : | ||
* STRATEGY_AFFIRMATIVE, STRATEGY_CONSENSUS, or STRATEGY_UNANIMOUS. | ||
* | ||
* @param TokenInterface $token | ||
* @param array $attributes | ||
* @param mixed $object | ||
* | ||
* @return string | ||
*/ | ||
public function getStrategy(TokenInterface $token, array $attributes, $object = null); | ||
|
||
/** | ||
* @param TokenInterface $token | ||
* @param array $attributes | ||
* @param null $object | ||
* | ||
* @return bool | ||
*/ | ||
public function supports(TokenInterface $token, array $attributes, $object = null); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a new feature you're PR should be based on master, you will then be able to use the trait, instead of relying on this as it does not preserve the original order in which the services have been registered (ref #20995).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry I didn't know new feature have to be on master, I only did patch PR until now
I rebased my branch and realized there is still some work that needs to be done because of the
TraceableAccessDecisionManager
(the fact that the strategy is not unique now).Unrelated but about your comment on the
PriorityTaggedServiceTrait
trait : I actually almost copy / pasted theAddSecurityVotersPass
when I did mine. I just checked and this one is not using the trait... Should it be done in a separate PR as there might be problems of order too ?