Symfony sensio/framework-extra-bundle 已被放弃,我找不到 IsGranted 替代方案

pok*_*net 5 access-control package deprecated symfony

(在 Symfony 5.4 PHP 7.4 项目上)
到目前为止,我正在使用IsGranted限制每个角色的控制器访问。IE

use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted
class PostController extends Controller
{
    /**
     * @IsGranted("ROLE_ADMIN")
     */
    public function myAdminPage()
    { // ... }
}
Run Code Online (Sandbox Code Playgroud)

自从ieabandoned上出现警告以来composer updatePackage sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.我正在尝试寻找替代方案。

对于注释的情况,Route通过将以下内容替换为直接即可
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

use Symfony\Component\Routing\Annotation\Route;

但我找不到替代方案IsGranted。(适用于 Symfony 5 或 Symfony 6)

有什么建议/建议吗?
谢谢。

Tho*_*asL 4

这 :

 use Symfony\Component\Security\Http\Attribute\IsGranted;
Run Code Online (Sandbox Code Playgroud)

https://symfony.com/doc/current/security.html#secure-controllers-and-other-code

  • 尝试使用 6.2 中首次引入的属性在 5.4 中可能不会很好地工作。 (3认同)
  • “但我找不到 IsGranted 的替代方案。(对于 Symfony 5 或 Symfony 6)” 这个问题也与 symfony 6 有关 (2认同)