Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Security] Add#[IsGranted()]#46907

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@nicolas-grekas
Copy link
Member

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
TicketsPart of#44705
LicenseMIT
Doc PR-

Extracted from#45415 (and modernized a lot).

I did not implement the proposals from Stof to keep this first iteration simple. I'd appreciate help to improve the attribute in a follow up PR 🙏

namespace Symfony\Component\Security\Http\Attribute;

/**
* @author Ryan Weaver <ryan@knpuniversity.com>
Copy link
Member

Choose a reason for hiding this comment

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

I'm getting credit without even opening a PR 😎

kbond, alexislefebvre, chalasr, yceruto, artyuum, alirezamirsepassi, and TomasVotruba reacted with laugh emoji
@chalasr
Copy link
Member

I did not implement the proposals from Stof to keep this first iteration simple

👍 just to be sure, the proposal you're talking about is the expression-language related part of#45415 (comment)?

@nicolas-grekas
Copy link
MemberAuthor

the proposal you're talking about is the expression-language related part

yep

@nicolas-grekasnicolas-grekas merged commit3edca67 intosymfony:6.2Jul 12, 2022
@nicolas-grekasnicolas-grekas deleted the sec-granted-attr branchJuly 12, 2022 07:11
* @author Ryan Weaver <ryan@knpuniversity.com>
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
class IsGranted
Copy link
Member

Choose a reason for hiding this comment

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

should probably be final, because the usage of$event->getAttributes()[IsGranted::class] means that the listener does not support subclasses of that attribute.

chalasr reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

@ZhukV
Copy link
Contributor

Maybe add possible to useBackedEnum?

enum AdminRoles: string{case PostList ='ROLE_POST_LIST';case PostEdit = 'ROLE_POST_EDIT;}class MyControllers{  #[IsGranted(AdminRoles::PostList)]  public function handleAction(): Response  {  }}

@wouterj
Copy link
Member

No, seephp/php-src#8825 and alsohttps://peakd.com/hive-168588/@crell/on-the-use-of-enums . Enums in PHP are meant to limit accepted values, and Symfony cannot limit accepted roles (as an application is free to define their own set of roles). As such, Symfony can not support enums here.

In PHP 8.2, you will be able to do#[IsGranted(AdminRoles::PostList->value)].

derrabus reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@chalasrchalasrchalasr approved these changes

@weaverryanweaverryanweaverryan approved these changes

@kbondkbondkbond approved these changes

@derrabusderrabusderrabus approved these changes

@ycerutoycerutoyceruto approved these changes

@wouterjwouterjAwaiting requested review from wouterjwouterj is a code owner

+1 more reviewer

@alamiraultalamiraultalamirault left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

11 participants

@nicolas-grekas@chalasr@ZhukV@wouterj@weaverryan@kbond@stof@derrabus@yceruto@alamirault@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp