为ACL设计数据库
对于我正在从事的项目,我需要为用户、几种不同类型的项目以及类似acl的权限系统设计一个数据库。
基本上,这就是我想做的(更复杂,但这足以证明我的意思):
- user: (id, name, password)
- Article: (id, title, body)
- image: (id, title, file_name)
- 权限:(item_type,item_id,user_id,读,写,管理)
(itemType和itemId一起是一个复合外键,引用文章或图像,具体取决于item_type)
有些人会说使用权限表不是一个好主意,通过向文章和图像添加读取、写入和管理列也可以实现同样的目的,但请记住,可能有多个用户对同一项目拥有不同的权限。放弃它不是一个选择。
在我看来,这会很好用。但是当谈到实现时,我找不到一个 php orm 来给我一些自由来做到这一点。这让我相信我可能做错了什么。
所以,我的问题是: 实现 ACL 并为此设计数据库的正确方法是什么? 企业级应用程序是如何完成的? 有没有非db ACL的解决方案?
For the project I'm working on, I need to design a database for users, items of several different types, and acl-like permission system.
Basically, this is what I wanted to do (much more complex, but this is enough to demonstrate what I mean):
- user: (id, name, password)
- article: (id, title, body)
- image: (id, title, file_name)
- permission: (item_type, item_id, user_id, read, write, manage)
(itemType and itemId are together a composite foreign key, referencing article or image, depending on item_type)
Some would say using a permission table is not a good idea, and that same can be achieved by adding read, write and manage columns to article and image, but keep in mind that there might be multiple users with different rights to same items. It's not an option to give that up.
In my opinion, this would work fine. But when it comes to implementation, I couldn't find a single php orm to give me some freedom to do this. This lead me to believe I might be doing something wrong.
So, my questions are:
What is the correct way to implement an ACL and design database for that?
How is it done for enterprise level applications?
Are there any non-db ACL solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要拥有一张
多对多
表即可将用户绑定到权限以及可能解决您的瓶颈的对象。它将具有 - user_id 和permission_id 以及object_id 将引用3 个不同的表。
意思是这样的:
希望它能有所帮助
You just have to have one
many-to-many
table which will bind users to permissions and probably objects that will solve your choking point.It will have - user_id and permission_id and object_id will be referencing 3 different tables.
Means will be something like:
hope it helps abit