使用Symfony2的JMSSecurityExtraBundle,我尝试创建自己的表达式方法,并使用PreAuthor注释将其绑定到控制器中。
我不知道为什么,但该方法从未被触发,并且在尝试评估预授权注释时,安全包以"令牌没有所需的角色"结尾。似乎正在尝试验证角色而不是解析预授权表达式。
关于我正在尝试做什么的示例:
<?php
namespace Acme'HelperBundle'Security;
use Symfony'Component'DependencyInjection'ContainerInterface;
use JMS'DiExtraBundle'Annotation as DI;
/** @DI'Service */
class RequestAccessEvaluator
{
private $container;
/**
* @DI'InjectParams({
* "container" = @DI'Inject("service_container"),
* })
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/** @DI'SecurityFunction("isAllowed") */
public function isAllowed()
{
return true;
}
}
我的控制器:
/**
*
* @PreAuthorize("isAllowed()")
* @Route("/bla/{id}")
* @Method({"POST"})
* @return json
*/
public function postBlaAction(Request $request, $id)
{
我终于解决了我的问题...实际上我错过了那个配置。
只需将其放入我的config.yml中并将选项"表达式"设置为true即可。