需要一些建议对我自己的基于角色的访问控制(RBAC)自己的、对我、访问控制、角色

2023-09-06 22:38:05 作者:京城易公子

我有一个pretty的简单的个人资料页面,用户可以上传图片和视频。我已经实现了我自己的角色系统,我没有使用.NET(我想学习和建造自己的)。我有10000用户的最多,约50-100用户同时使用。

I have a pretty simple profile page where users can upload images and videos. I have implemented my own role system and I'm not using .NET (I wanted to learn and builded my own). I'll have 10´000 users at the most and about 50-100 users simultaneously using it.

我在处理我的RBAC数据库三个表:

I have three tables in the DB that handles my RBAC:

角色:管理,用户管理,客户的 权限: SendEmail,填写AdvancedSearch,RemoveUser 的...等。

Roles: Admin, User, Manager, Guest Permissions: SendEmail, AdvancedSearch, RemoveUser... etc.

授权:在此表中映射了角色的权限。我运行检查每一个许可,才能进行的操作时间。如果权限< - >作用是在表我回到和行动真正被授权

Authorized: In this table I map a role to a permission. I run a check every time a permission is required for an action. If the permission<->role is in the table I return true and the action is authorized.

所以,这里对这个方案中的几个问题。

So, here's a few questions on this scenario.

这是一种重量轻的检查方法 授权?通过quering数据库上 每一个页面加载和操作的用户 令。 我应该记住这一个XML文件 更快的结果? 有没有更好的结构,这 排序RBAC的? Is this a light weight way to check authorization? By quering the DB on every page load and action the user makes. Should I keep this in an XML-file for faster result? Is there a better structure for this sort of RBAC?

在此先感谢!

推荐答案

有关50-100用户,我会在应用程序的每活跃用户只需缓存的东西。这就避免了从数据库的任何小的开销取,除非它过期。所以,只是有一些小物件,你可以便宜缓存,但其中包含所有你需要运行的应用程序的核心功能的用户信息。

For 50-100 users, I would just cache something per-active-user in the app. This avoids any small overhead from a db fetch, except for when it expires. So just have some small object that you can cache cheaply, but which includes all the user information you need to run the app's core functions.

疗法什么能阻止你使用这个实现一个的IPrincipal 使用内置的 [的PrincipalPermission(...)] 的东西,但做自己的作品了。

Ther's nothing stopping you using this to implement an IPrincipal to use the inbuilt [PrincipalPermission(...)] stuff, but doing it yourself works too.