我有4个不同的访问级别:管理员,合作伙伴,员工和客户。管理员、合作伙伴和员工拥有对客户端的管理访问权限。基本上,我所做的是创建了一个Rails应用程序,客户可以将文档上传到他们的供应商(合作伙伴)。除了客户端级访问之外,一切都运行得很好。我有两个代码: partercode和client code。合作伙伴只能查看文件的partercode字段等于合作伙伴的合作伙伴代码的文件。这个很好用。但是,客户端只能看到partnercode匹配和clientcode匹配的文件。下面是我的客户部分。工作的是,客户端只被允许查看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发布于 2011-04-28 21:09:08
我找到了答案。具有讽刺意味的是,答案就在这个问题的标签中;嵌套的。
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检查合作伙伴代码。
发布于 2012-06-02 03:13:31
我不认为嵌套if_attribute语句实际上是这样工作的。默认情况下,Declarative_authorization使用or语句连接这些if_attribute语句,但是如果我理解正确的话,您希望使用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/Reader/AuthorizationRulesReader.html#M000184
发布于 2012-12-17 19:19:42
:join_by是有效的,但我的问题是,有时您需要同时使用AND和OR。您可以在一行中指定多个if条件作为不同的参数。这些数据将使用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
endhttps://stackoverflow.com/questions/5810445
复制相似问题