如何设计用户、角色和权限架构?

发布于 2025-01-07 05:00:48 字数 707 浏览 3 评论 0原文

这在Web应用程序开发中是很常见的事情。我已经做过很多次了。

但我目前的项目陷入了为此设计架构的困境。

问题是我的应用程序一开始就会有三种类型的用户,例如超级管理员、管理员和普通用户。

我计划将这些用户类型设置为 ROLE_SUPERADMIN、ROLE_ADMIN 和 ROLE_USER 等角色。

该系统可以有多种角色。事实上,超级管理员和管理员可以创建角色并将这些角色分配给用户。

问题是,

超级管理员将拥有 p1、p2 和 p3 权限。 超级管理员可以创建其他超级管理员。 超级管理员可以创建管理员。 超级管理员不会在系统中添加用户。

管理员可以拥有 p5、p6 和 p7 权限。 管理员不能创建其他管理员。 管理员可以创建其他用户。 管理员还可以创建报告查看者等角色。

具有 p1、p2 和 p3 权限的超级管理员应该能够创建具有 p5、p6 和 p7 权限的管理员。我不太明白。

从逻辑上讲,当超级管理员本身没有p5、p6和p7权限时,他们如何创建具有这些权限的管理员?

请帮助我对此进行正确的设计。

以下是我迄今为止的设计。

用户
用户 ID 角色 ID

ROLE
角色 ID 角色

名称 权限
权限 ID 权限名称

ROLE_PERMISSION RoleID PermissionID

谢谢。

This is a very common thing in the web application developmet. I have done it number of times.

But I am stuck in my current project designing the schema for this.

The thing is my application will have three types of users in the begining e.g. SuperAdmin, Admin and the normal user.

I plan to have these user types as the roles like ROLE_SUPERADMIN, ROLE_ADMIN and ROLE_USER.

The system can have many roles. In fact SuperAdmin and Admins an create roles and assign those roles to users.

The problem is,

Super Admins will have permisson p1, p2 and p3.
Super Admins can create other super admins.
Super Admins can create admins.
Super Admins will not add users in the system.

Admins can have permissions p5,p6 and p7.
Admins can not create another admins.
Admins can create other users.
Admins can also create roles like say Report viewers.

Super admin with permission p1, p2 and p3 should be able to create Admins with permissions p5, p6 and p7. Which I am not quite getting.

Logically when Super admmins themselves do not have permission p5, p6 and p7, how can they create admins with these permissions?

Please help me out with the proper design with this.

Below is the design I have so far.

USER
UserID RoleID

ROLE
RoleID RoleName

PERMISSION
PermissionID PermissionName

ROLE_PERMISSION
RoleID PermissionID

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

原来是傀儡 2025-01-14 05:00:48

这是一个负载性的问题,设置成员、角色等并不是一件小事。我建议您查看已经编写的库,看看它们是否适合您的需求。您应该开始谷歌搜索,简称为“访问控制列表”(acl)。

This is a loaded question, setting up members, roles, etc. is no small feat. I suggest you take a look at already written libraries to see if they may suit your needs. What you should start googling for, is 'Access Control Lists' (acl) for short.

浮华 2025-01-14 05:00:48

您应该研究授权框架和标准,例如 XACML - XACML 允许您基于多个属性定义授权,这样您就不会最终陷入角色爆炸。因此,您可以创建规则,例如:

具有 role=manager 和 location=TX 的用户可以对资源执行 action=view...

也有多个供应商解决方案和开源解决方案。查看 Wikipedia 页面和标准主页以获取更多信息:

我也有一个谈论 XACML 的 Youtube 频道:

You should look into authorization frameworks and standards such as XACML - XACML lets you define authorization based on several attributes so that you don't end up in role explosion. So instead of creating a role manager_in_tx_with_gold_status, you can create rules e.g.:

a user with role=manager and location=TX can do action=view on resources....

There are several vendor solutions and open source solutions too. Check out the Wikipedia page and the standard's homepage for more information:

I have a Youtube channel too that talks about XACML:

云裳 2025-01-14 05:00:48

一旦设计了这样一个数据库;

我安装了一些论坛、门户和CMS脚本,并分析了它们如何处理这种情况,然后提取了数据库模式并将其用作参考。

也许这可以帮助

Once designing a database like this;

I installed some forum, portal and CMS scripts and analyzed how they handled the situation, then extracted DB schemas and used them as a reference.

May be this can help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文