首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >declarative_authorization if_attribute中用户的多个条件

declarative_authorization if_attribute中用户的多个条件
EN

Stack Overflow用户
提问于 2011-04-28 04:54:13
回答 3查看 1.1K关注 0票数 1

我有4个不同的访问级别:管理员,合作伙伴,员工和客户。管理员、合作伙伴和员工拥有对客户端的管理访问权限。基本上,我所做的是创建了一个Rails应用程序,客户可以将文档上传到他们的供应商(合作伙伴)。除了客户端级访问之外,一切都运行得很好。我有两个代码: partercode和client code。合作伙伴只能查看文件的partercode字段等于合作伙伴的合作伙伴代码的文件。这个很好用。但是,客户端只能看到partnercode匹配和clientcode匹配的文件。下面是我的客户部分。工作的是,客户端只被允许查看partercode文件,但它将它们设置为查看属于该合作伙伴的其他客户端。(通过在URL中键入数字)。我怀疑这永远不会是一个问题,但这是一个我绝对希望关闭的安全漏洞。

代码语言:javascript
复制
  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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-04-28 21:09:08

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

代码语言:javascript
复制
  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。end检查合作伙伴代码。

票数 0
EN

Stack Overflow用户

发布于 2012-06-02 03:13:31

我不认为嵌套if_attribute语句实际上是这样工作的。默认情况下,Declarative_authorization使用or语句连接这些if_attribute语句,但是如果我理解正确的话,您希望使用and连接它们。改变这一点的方法是将:join_by属性设置为:and

代码语言:javascript
复制
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/Reader/AuthorizationRulesReader.html#M000184

票数 3
EN

Stack Overflow用户

发布于 2012-12-17 19:19:42

:join_by是有效的,但我的问题是,有时您需要同时使用ANDOR。您可以在一行中指定多个if条件作为不同的参数。这些数据将使用AND进行比较,而每一行都使用OR进行评估。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5810445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档