使用 sfGuard 保护 Symfony 中的整个控制器?
我正在查看 sfGuard 和 Symfony 有关安全性的文档。但我找不到任何有关保护整个控制器的地方。只有称为“安全”的操作。
我尝试使用 preExecute
方法调用 forward404Unless($this->getUser()->hasGroup('admin'))
但它没有不工作。
是否可以使用 security.yml 和 sfGuard 来保护我在控制器中的操作?或者在 symfony 中有这样做的实践吗?编辑每个控制器都会很麻烦,我必须创建将来可能会改变的自定义安全性。
谢谢。
I was looking at the Documents for sfGuard and Symfony about the security. But I cannot find anywhere about secure a whole Controller. There is only called action Secure.
I tried to use the preExecute
method to make a call to forward404Unless($this->getUser()->hasGroup('admin'))
but it doesn't work.
Is it possible to use the security.yml and sfGuard to secure my actions in a controller? Or is there practice of doing this in symfony? It will be a hassle to edit every single controller I have had to create custom security that might change in the future.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
symfony 使用级联配置模式,这些模式允许您以更可重用和实用的方式配置所有项目/应用程序/模块/操作。与安全性发生同样的事情,您可以使用 security.yml 来定义访问限制。
如果您在应用程序文件夹中创建 security.yml (即 $sf_root/app_name/config/security.yml)并指定如下内容:
默认情况下,它将使您的所有应用程序安全(用户必须登录) ,允许您在适当的时候进行覆盖。假设文件模块有一个需要管理员凭据的“下载”操作,但拥有“通用”和“管理员”凭据的用户可以使用所有其他操作,因此您必须在 $sf_root/ 创建一个 security.yml apps/app_name/modules/file/config/ 并定义:
有关安全性和高级凭据的更多信息,请查看 symfony 页面 操作安全
Well symfony use a cascading configuration schema, those allowing you to configure all your project/app/module/action in a more reusable and practical way. With security happens the same thing, you can use the security.yml to define access restrictions.
If you create a security.yml in the app folder (that would be $sf_root/app_name/config/security.yml) and specify something like this:
It will make all your app secure by default (users will have to be logged in), allowing you to overwrite when appropiate. Lets say the file module has an action "download" that needs admnistrator credentials, but all the other actions could be used by user having "common" and "administrator" credentials, so you will have to create a security.yml at $sf_root/apps/app_name/modules/file/config/ and define:
For more info on security and advanced credentials, please check out symfony page on Action Security
您可以像这样使用
security.yml
:不过,我不确定它是否可以与组一起使用。
You can use
security.yml
like this:I'm not sure about it working with a group, though.