我正在使用 JMS Security Extra bundle 来保护我的 Controller 中的方法。
但是有什么方法可以使用 @Secure
保护整个 Controller ?
最佳答案
这可以按照 Documentaion 完成
https://github.com/schmittjoh/JMSSecurityExtraBundle/issues/50
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()
{
// ...
}
}
关于php - 是否可以在 Symfony 2 中保护整个 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11999210/