我有4个不同级别的访问权限;管理员,合作伙伴,雇员和客户。管理员,合作伙伴和员工对客户有管理访问权限。基本上,我所做的是创建一个Rails应用程序,客户可以将文档上传到其供应商(合作伙伴)。除了客户级访问外,一切都很好。我有两个代码; PARTERCODE和客户端代码。合作伙伴只能看到文件的partercode字段等于合作伙伴的伙伴代码的文件。这很好。但是,客户端只能看到伙伴代码匹配的文件和客户端代码匹配的文件。以下是我的客户部分。有效的是,客户只允许客户端查看ParterCode文件,但是它使他们看到了其他属于合作伙伴的客户。 (通过在URL中输入数字)。我怀疑这是一个问题,但这是我绝对希望关闭的安全漏洞。

  role :client do
    has_permission_on [:users], :to => [:client, :edit, :update] do
      if_attribute :username => is { user.username }
    end
     has_permission_on [:documents], :to => [:client, :new, :create]
     has_permission_on [:documents], :to => [:client, :index, :show, :edit, :update, :destroy, :documents] do
       if_attribute :partnercode => is { user.partnercode }, :clientcode => is { user.clientcode }
     end
  end
有帮助吗?

解决方案 2

我找到了答案。具有讽刺意味的是,答案是这个问题的标签。嵌套。

  role :client do
    has_permission_on [:users], :to => [:client, :edit, :update] do
      if_attribute :username => is { user.username }
    end
     has_permission_on [:documents], :to => [:client, :new, :create]
     has_permission_on [:documents], :to => [:client, :index, :show, :edit, :update, :destroy, :documents] do
       if_attribute :clientcode => is { user.clientcode } do
        if_attribute :partnercode => is { user.partnercode }
       end
     end
  end

一旦我验证客户端代码是正确的,然后创建另一个do ..结束检查伙伴代码。

其他提示

我不认为筑巢 if_attribute 陈述实际上是这样的。默认情况下,声明_authorization加入这些 if_attribute 陈述 or 声明,但是如果我理解正确,您希望他们加入 and. 。改变的方法是设置 :join_by 属性为 :and.

role :client do
  has_permission_on [:documents], :to => [:do_whatever], :join_by => :and do
    if_attribute :partnercode => is { user.partnercode }
    if_attribute :clientcode => is { user.clientcode }
  end
end

资源: http://www.tzi.org/~sbartsch/declarative_authorization/master/classes/authorization/authorization/authorizationrizationrizationRulesreader.html#m000184

:join_by 有效,但我的问题是有时您需要 ANDOR. 。您可以在单行上指定多个条件,作为不同的参数。这些将使用 AND 而每行都用 OR.

role :client do
  has_permission_on [:documents], :to => [:do_whatever], :join_by => :and do
    if_attribute :partnercode => is { user.partnercode }, 
                 :clientcode => is { user.clientcode } # These two are evaluated with AND
    if_attribute :some_attr => is { some_val }
  end
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top