You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of the effort to move features of SensioFrameworkExtraBundle #44705 into code, we are considering not moving @Security and instead improving #[IsGranted].
Also, I would not migrated the Security attribute as is. The implementation of this attribute is currently a hack, as it does not rely on triggering the authorization system to perform the security check (instead, it duplicates part of that system, which broke when switching to the new security system).
The best practice for using that attribute is to restrict yourselves to using is_granted inside the expression (or to switch to IsGranted for all cases where it can be used, as that attribute does not hack the authorization system).
To me, this should rather be left out, adding a few advanced features to IsGranted:
The one I would need personally is having a subject_expression feature, allowing to use ExpressionLanguage to build the subject being voted on (but with a better approach than Security where we have clashes between controller argument names and built-in variables of the expression) when we need a more complex vote.
Another one that could be needed is a way to specify that the permission being checked is an expression for ExpressionVoter (but this may be supported already on PHP 8.1 when using attributes rather than annotations, but using new Expression)
Let's discuss what we want to do. Help wanted to make it happen.
Example
No response
The text was updated successfully, but these errors were encountered:
…d] attribute (HypeMC)
This PR was merged into the 6.2 branch.
Discussion
----------
[Security] Allow using expressions with the #[IsGranted] attribute
| Q | A
| ------------- | ---
| Branch? | 6.2
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fix#46912
| License | MIT
| Doc PR | -
Allows using the expression language with the `#[IsGranted]` attribute:
```php
#[IsGranted(
attribute: new Expression('"ROLE_ADMIN" in role_names or is_granted("POST_VIEW", subject)'),
subject: 'post',
)]
public function index(Post $post)
{
}
#[IsGranted(
attribute: new Expression('user === subject'),
subject: new Expression('args["post"].getAuthor()'),
)]
public function index(Post $post)
{
}
#[IsGranted(
attribute: new Expression('user === subject["author"] and subject["post"].isPublished()'),
subject: [
'author' => new Expression('args["post"].getAuthor()'),
'post' => 'post',
],
)]
public function index(Post $post)
{
}
```
Commits
-------
f5cee77 [Security] Allow using expressions with the #[IsGranted] attribute
Description
As part of the effort to move features of SensioFrameworkExtraBundle #44705 into code, we are considering not moving
@Security
and instead improving#[IsGranted]
.A first idea has been described by @stof in #45415 (comment):
Let's discuss what we want to do. Help wanted to make it happen.
Example
No response
The text was updated successfully, but these errors were encountered: