Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Deprecated passing more than one attribute to @IsGranted #648

Conversation

wouterj
Copy link
Contributor

@wouterj wouterj commented Oct 22, 2019

Fixes #645

I'm not so sure about the version, but looking at the tags, I expected the next version will be 5.6 (as 5.5 is already released?).

@wouterj wouterj force-pushed the issue-645/is-granted-multiple-attributes branch from bf946fe to 05f8154 Compare October 22, 2019 21:55
CHANGELOG.md Outdated Show resolved Hide resolved
Co-Authored-By: Jérôme <jerome.vasseur@jhome.fr>
@wouterj
Copy link
Contributor Author

wouterj commented Nov 8, 2019

Thanks @jvasseur! I'm not using this bundle, so wasn't aware of the difference between those annotations.

---

* Deprecated passing more than one attribute to `@IsGranted()`. Use an expression instead
(e.g. `@Security("has_role('ROLE_USER') or has_role('ROLE_ADMIN')")`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(e.g. `@Security("has_role('ROLE_USER') or has_role('ROLE_ADMIN')")`).
(e.g. `@Security("is_granted('ROLE_USER') or is_granted('ROLE_ADMIN')")`).

I think is_granted() is a more accurate replacement

@@ -73,7 +73,7 @@ public function onKernelControllerArguments(KernelEvent $event)
}
}

if (!$this->authChecker->isGranted($configuration->getAttributes(), $subject)) {
if (!$this->authChecker->isGranted($configuration->getAttribute(), $subject)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're passing an array of attributes and are using Symfony 5, you will see the deprecation from this bundle, but the feature won't work correctly because Symfony 5 doesn't support an array of attributes, right?

I think we need to either:

A) "Mimic" the "or" behavior here - i.e. if it's an array, we call isGranted() twice in an "or" kind of way
B) Throw an actual exception if you're using Symfony 5 with this bundle and are passing an array of attributes. That's a BC Break, but an obvious one (better than the silent one of it just not working) AND the user should have seen deprecation warnings on Symfony 4.4 anyways. I think this would prevent WTF's like this one: https://github.com/sensiolabs/SensioFrameworkExtraBundle/issues/645#issuecomment-569914831

nicolas-grekas added a commit to symfony/symfony that referenced this pull request Aug 2, 2022
…nted] (HypeMC)

This PR was merged into the 6.2 branch.

Discussion
----------

[Security] Remove using multiple attributes with #[IsGranted]

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #46978 (comment)
| License       | MIT
| Doc PR        | -

Passing multiple attributes to `isGranted()` has been removed in #33584, so the following doesn't work any more:

```php
#[IsGranted(attributes: ['ROLE_ADMIN'])]
public function index(Post $post)
{
}

#[IsGranted(attributes: ['ROLE_USER', 'ROLE_ADMIN'])]
public function index(Post $post)
{
}
```

As mentioned in sensiolabs/SensioFrameworkExtraBundle#648 , expressions should be used instead, see #46978 . This PR removes the possibility of using multiple attributes with `#[IsGranted]`.

Also, it's currently possible to use `#[IsGranted()]` with no attributes (`null`). Since this doesn't seem to work either, nor can I find a reason why it even should, this PR removes that option as well. If I'm wrong about this one, please let me know.

Commits
-------

663dc3e [Security] Remove using multiple attributes with #[IsGranted]
@fabpot
Copy link
Member

fabpot commented Dec 2, 2022

Closing as this repository is not maintained anymore. As of Symfony 6.2, all features have been moved to Symfony core now.
See #783

@fabpot fabpot closed this Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants