“未授权”放在哪里访问控制逻辑,似乎不适合ACL?
我想知道“非授权”访问控制逻辑,例如。只能在顶级待办事项上添加子待办事项。它似乎不适合 ACL,它似乎更适合身份验证/授权访问控制逻辑?
我是否将所有内容都放入我的 ACL 中?我必须以某种方式显示不同的错误消息,例如。 “您无法执行此操作”而不是“您没有足够的权限来执行此操作”...我该怎么做?
I am wondering for "Non-Authorization" Access Control Logic eg. One can only add children todos on top level todos. It doesn't seem to fit into ACL's where it seem to be more for Authentication/Authorization Access Control Logic?
Do I put all into my ACL? I must somehow show different error messages tho, eg. 'You cannot perform this action' instead of 'You don't have sufficient permissions to perform this action' ... how might I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在访问列表对象之外处理访问逻辑。我为此目的创建了一个 frontController 插件:
在本例中,我显式检查角色和资源是否存在。这是因为我的数据库中只有角色有权访问资源的 ACL 规则。所有其他情况(当用户没有访问权限时)我将其保留在数据库之外。
当您有不同的逻辑时,检查
$acl->isAllowed($role, $resource, $permission);
并保留$acl->hasRole 可能就足够了()
和$acl->has()
输出。错误处理程序
我抛出一个 Zend_Controller_Action_Exception ,错误代码为 403,但是如果您没有捕获特定代码,它看起来就像一个正常的应用程序错误。因此,我在 ErrorHandler frontController 插件中添加了另一个常量
EXCEPTION_NO_PERMISSION
并将其添加到 switch 语句中:然后您可以在 ErrorController 中获取错误类型
EXCEPTION_NO_PERMISSION
。You should handle the access logic outside your access list object. I created a frontController plugin for this purpose:
In this case, I explicitly check the existence of a role and resource. This is because I have only the ACL rules in my database where the role has access to the resource. All other cases (when user does not have the access) I leave it out of the database.
When you have a different logic, it is perhaps enough to check for
$acl->isAllowed($role, $resource, $permission);
and leave the$acl->hasRole()
and$acl->has()
out.Error handler
I throw a Zend_Controller_Action_Exception with error code 403, but if you don't catch the specific code, it will look like a normal application error. Therefore I added in the ErrorHandler frontController plugin another constant
EXCEPTION_NO_PERMISSION
and added this to the switch statement:Then you can fetch the error type
EXCEPTION_NO_PERMISSION
in your ErrorController.最常见的方法是处理控制器插件中的逻辑。这在大多数情况下都有效,
但我建议将逻辑存储在您的模型中。
ACL也是一个模型。
任何模型/表单/类都可以通过提供
getResourceId()
方法来实现Zend_Acl_Resource_Interface
:例如
The most common way is to handle the logic in the controller plugin. This works well in most cases,
but I'd recommend to store the logic in your models.
ACL is a model too.
Any model/form/class may implement
Zend_Acl_Resource_Interface
just by providinggetResourceId()
method:e.g.