How to define several roles to the same controller using use Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Security ;?

0
use AppBundle\Tests\Controller\HojaRutaControllerTest;

//use Proxies\__CG__\AppBundle\Entity\Chofer;
//use Proxies\__CG__\AppBundle\Entity\Omnibus;
//use Proxies\__CG__\AppBundle\Entity\Ruta;
//use Proxies\__CG__\AppBundle\Entity\HojaRuta;
use Doctrine\ORM\Query\ResultSetMapping;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use AppBundle\Entity\Recaudacion;
use AppBundle\Form\RecaudacionType;

/**
 *
 * Función para llamar a la plantilla de administración
 * @Security("has_role('ROLE_ADMIN')")
 *
 *
 */
class RecaudacionController extends Controller
{
    
asked by Abdiel David 22.06.2017 в 21:16
source

1 answer

0

@Security supports expressions, so you can express it in the following way:

<?php
use AppBundle\Tests\Controller\HojaRutaControllerTest;

use Doctrine\ORM\Query\ResultSetMapping;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use AppBundle\Entity\Recaudacion;
use AppBundle\Form\RecaudacionType;

/**
 *
 * Función para llamar a la plantilla de administración
 * @Security("has_role('ROLE_ADMIN') or has_role('OTRO_ROL')")
 *
 *
 */
class RecaudacionController extends Controller
{

Another way to do this is to generate a specific ROL for this action, for example ROLE_RECOUNT, and that all the roles that you need to have access to this function inherit from it. Then you just have to check that specific role instead of checking one or more roles. This option is very practical so that in the future the requirements change and other roles need to access this (or any other) functionality. Just add the specific role to the other roles that interest you.

    
answered by 26.06.2017 в 10:26