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
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This can be done as per 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()
{
// ...
}
}
回答2:
This annotation can only be applied to methods.
You could do it like this though (it's a regex):
jms_security_extra:
method_access_control:
'AcmeDemoBundle:AdminController:.*Action': 'hasRole("ROLE_ADMIN")'
Read the documentation: http://jmsyst.com/bundles/JMSSecurityExtraBundle/master/method_security_authorization