我正在尝试使用注解来保护我的 Controller :
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()
{
...
但我似乎无法真正保护我的 Controller 。是否有任何情况会被忽略?
最佳答案
在一个几乎完全不相关的说明中,我的问题并非源于我的配置或 Controller 中的任何内容,而是从 Symfony 2.0 到 Symfony 2.1 的转换过程中的迁移混淆。我未能注册 JMSDiExtraBundle,它默默地削弱了 JMSSecurityExtraBundle 的(和其他人的)注释。
在我的 AppKernel.php 中,我丢失了:
public function registerBundles()
{
$bundles = array(
...
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
...
一切正常,再次。
关于php - Symfony2 安全 @Secure 注释不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14665725/