如何检测角色的特定拒绝?
Zend_Acl 默认情况下不允许每个角色对每个权限的每个资源,直到或除非 他们是特别允许的。 在我的系统中,用户可以拥有许多角色,并且权限被分配给这些角色。 我只是让所有用户角色迭代所有用户角色,并检查 isAllowed() 以获得每个角色的给定资源和权限。
例如,如果当前资源是“foo”并且权限是“bar”,
public function checkAllow($roles, $resouse, $privilege)
{
foreach ($roles as $role) {
if ($acl->isAllowed($role, 'foo', 'bar') === true)
return true;
}
return false;
}
现在我想对这些角色实现排序顺序,即分配的第一个角色将具有更多的优先权,然后是第二个角色,依此类推。
问题来了,我如何检测对某些角色的特定拒绝,例如
$this->deny('member','foo','bar');
在迭代所有角色时,我如何知道给定的角色被特定“拒绝”? 因此,此时我可以跳出 foreach 循环并返回 false
。
Zend_Acl by default disallow every role to every resource on every privilege untill or unless
they are specifically allowed.
In my system a user can have many roles and permission are assinged to these roles.
I simply get all user roles iterate over all of them and check isAllowed() for given resourse and privilege for every role.
for e.g if current resourse is 'foo' and privilege is 'bar'
public function checkAllow($roles, $resouse, $privilege)
{
foreach ($roles as $role) {
if ($acl->isAllowed($role, 'foo', 'bar') === true)
return true;
}
return false;
}
Now I want to implement sort order on these roles i.e first role assinged will have more preference then second and so forth.
Problem comes how can I detect specific deny to some roles like
$this->deny('member','foo','bar');
While iterating over all roles how can I know the given role was specificly "denyied"?
So at that point I can break out of foreach loop and return false
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,假设我理解这个问题,您正在寻找这样的东西吗?
如果没有,请更好地解释一下这个问题,以便我可以更好地提供帮助。
伪代码
Ok, so assuming I undertand the question, is something like this what you are looking for?
if not, please explain the question a little better so i can assist better.
psuedo-code
好吧,我自己通过进入 Zend_Acl 代码找到了解决方案,结果是 Zend_Acl 缺少 isDenied() 方法,它有 isAllowed() 但没有 isDenied()
这是我在类中扩展 Zend_Acl 的 isDenied() 方法的实现
Ok I found the solution myself by going into Zend_Acl code well its come out to be Zend_Acl is missing isDenied() Method , it has isAllowed() but not isDenied()
Heres my implementation of isDenied() method in class which extends Zend_Acl