core icon indicating copy to clipboard operation
core copied to clipboard

How I can grant access for many roles using annotation?

Open victor-felix opened this issue 7 years ago • 2 comments

I can grant access for many roles, but the forms below not work.

Example:

/**

  • @ApiResource(
  • attributes={
    
  •      "access_control"="is_granted('ROLE_STUDENT')",
    
  •      "access_control"="is_granted('ROLE_TEACHER')"
    
  • }
    
  • ) ...

/**

  • @ApiResource(
  • attributes={
    
  •      "access_control"="is_granted('ROLE_STUDENT, ROLE_TEACHER')"
    
  • }
    
  • ) ...

/**

  • @ApiResource(
  • attributes={
    
  •      "access_control"="is_granted('ROLE_STUDENT', 'ROLE_TEACHER')"
    
  • }
    
  • ) ...

victor-felix avatar Jun 07 '19 20:06 victor-felix

You can use logical operators in expression language, so the following should work:

@ApiResource(
    attributes={
        "access_control"="is_granted('ROLE_STUDENT') or is_granted('ROLE_TEACHER')"
    }
)

lukasluecke avatar Jun 08 '19 20:06 lukasluecke

@lukasluecke its work!! Thank u bro!!

victor-felix avatar Jun 12 '19 11:06 victor-felix