(on a Symfony 5.4 PHP 7.4 project)
So far I am using IsGranted
to restrict access in controllers per role.
i.e.
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted
class PostController extends Controller
{
/**
* @IsGranted("ROLE_ADMIN")
*/
public function myAdminPage()
{ // ... }
}
Since the abandoned
warning on composer update
i.e:
Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.
I'm trying to find an alternative.
for the case of the Route
annotation things are straight forward by replacing:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
with
use Symfony\Component\Routing\Annotation\Route;
But I cannot find an alternative for IsGranted
. (for Symfony 5 or Symfony 6)
Any suggestions/advices?
Thanks.
CodePudding user response:
In Symfony 5.4, you should use the Security
component instead.
use Symfony\Component\Security\Core\Security;
class PostController extends Controller
{
/**
* @Security("is_granted('ROLE_ADMIN')")
*/
public function myAdminPage()
{
// ...
}
}
CodePudding user response:
This :
use Symfony\Component\Security\Http\Attribute\IsGranted;
https://symfony.com/doc/current/security.html#securing-controllers-and-other-code