Symfony:对某些类型的用户取消后端模块的安全。如何?

发布于 2024-11-10 04:26:42 字数 553 浏览 1 评论 0原文

开门见山——我有一个 Symfony 1.3 / Propel 1.4 项目。我有一个通过其自己的 security.yml 中的 is_secure: true 来保护的模块。我希望这个模块不仅可供超级管理员访问——我正在使用 sfGuardPlugin symfony 插件。该模块位于后端应用程序中。

我想让具有任意 type 属性值的用户可以访问该模块。该网站的普通用户在那里有 NULL ,其余所有都有某种值。当我将安全指令更改为 is_secure: false (只是为了测试它)时,我会转到 /admin 并使用具有某种 类型的用户登录,我被正确重定向到 /admin/purchases (唯一不安全的后端模块),但出现安全错误消息 - “您没有访问权限显示此页面”或类似的内容。

由于我不太熟悉 sfGuardPlugin (以及 Symfony 的总体安全性),因此我需要一些关于如何执行此操作的帮助。

Straight to the point -- I have a Symfony 1.3 / Propel 1.4 project. I have a module which is secured via is_secure: true in its own security.yml. I want this module to be accessible not only for super admins -- I am using the sfGuardPlugin symfony plugin. The module is located in the backend app.

I would like to make the module accessible to users who have any value of their type property. Regular users of the site have NULL in there, all of the rest have a value of some kind. When I change the security directive to is_secure: false (just to test it), I then go to /admin and do login with a user who has some type, I get properly redirected to /admin/purchases (the only non-secured backend module) but with security error message -- "You do not have access to show this page" or something along the lines.

Since I am not quite so familiar with sfGuardPlugin (and Symfony's security in general), I would like some help as to how do I do this, please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独﹏钓一江月 2024-11-17 04:26:42

请参阅文档了解行动安全。

使用 sfGuardPlugin 中的组权限自动为您选择的用户提供广告凭据(请参阅额外文档 sfGuardPlugin 以了解插件如何将用户组和权限转换为凭据)

See documentation about action security.

Use group permissions from sfGuardPlugin to automatically ad credentials for users of your choice (see extra documentation for sfGuardPlugin in order to understand how the plugin converts user groups and permissions into credentials)

朦胧时间 2024-11-17 04:26:42

如果您不想中继 security.yml 凭据,您还可以在操作中处理此问题:

public function executeIndex($request){
  if(!$this->getUser()->hasGroup('desired-group')){
    $this->getUser->setFlash('message', 'You do not have access to show this page');
    return $this->redirect('admin/purchases');
  }

  // more logic here
}

如果这适用于模块的更多操作,则您可以在 DRY 的情况下使用 preExecute() 方法(不要重复自己) ……)

If you don't want to relay on the security.yml credentials, you could also handle this inside an action:

public function executeIndex($request){
  if(!$this->getUser()->hasGroup('desired-group')){
    $this->getUser->setFlash('message', 'You do not have access to show this page');
    return $this->redirect('admin/purchases');
  }

  // more logic here
}

If this works for more actions of your module, yould could use the preExecute() methode in case of DRY (dont repeat yourself…)

小红帽 2024-11-17 04:26:42

只要您拥有每个用户的正确凭据。在您的后端模块中
security.yml 文件中,您可以执行以下操作:

all:
  credentials: [[admin, developer]]

或者您可以执行单独的操作:

requestView:
  credentials: [[supporter, admin, developer]]

As long as you've got the right credentials for each user. In your backend modules
security.yml file you can do this:

all:
  credentials: [[admin, developer]]

Or you can do individual actions:

requestView:
  credentials: [[supporter, admin, developer]]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文