Symfony2 security @ No comments annotation not working

I am trying to use annotations to protect my controllers:

namespace Vinny\StreamBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;


class HomeController extends Controller
{

    /**
     * @Route("/home", name="home") 
     * @Secure(roles="ROLE_USER")
     */
    public function indexAction()
    {
     ...

      

But I cannot get my controllers to actually be protected. Are there any cases where this is ignored?

+3


source to share


2 answers


On an almost completely unrelated note, the issue with my issue was not related to anything in my configuration or controller, but was a migration mix from a switch from Symfony 2.0 to Symfony 2.1. I was unable to register the JMSDiExtraBundle, which silently mangled JMSSecurityExtraBundle (and others) annotations.

In my AppKernel.php I was missing:



public function registerBundles()
{
    $bundles = array(
    ...
    new JMS\DiExtraBundle\JMSDiExtraBundle($this),
    ...

      

Everything works fine with this, again.

+11


source


You need to try with ROLE_ADMIN

or ROLE_SUPER

and then see if it is protected or not. ROLE_USER

is the deafult role that applies to all users, so u is allowed



@Secure(roles="ROLE_SUPER")

      

0


source







All Articles