是否可以在Symfony 2中保护整个Controller? [英] Is it possible to secure whole Controller in Symfony 2?
本文介绍了是否可以在Symfony 2中保护整个Controller?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用JMSSecurityExtra捆绑包来保护我的contoller中的方法.
但是我有什么办法可以用@Secure
保护整个控制器吗?
I am using JMSSecurityExtra bundle for securing methods in my contoller.
But is there any way that i can secure the whole controller with @Secure
?
推荐答案
这可以按照 Documentaion 完成
https://github.com/schmittjoh/JMSSecurityExtraBundle/issues/50
提示:如果您希望使用相同的方法保护控制器的所有动作 规则,您也可以在类本身上指定@PreAuthorize.警告 但是,此规则仅适用于在中声明的方法 班级.
Tip: If you like to secure all actions of the controller with the same rule, you may also specify @PreAuthorize on the class itself. Caution though, this rule is only applied to the methods which are declared in the class.
use JMS\SecurityExtraBundle\Annotation\PreAuthorize;
/** @PreAuthorize("hasRole('A') or (hasRole('B') and hasRole('C'))") */
class MyService
{
public function secureMethod()
{
// ...
}
}
这篇关于是否可以在Symfony 2中保护整个Controller?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文