作为 JSF/JPA Web 应用程序项目的一部分,我需要实现一个完整的用户授权模块。我正在使用 Apache Shiro 进行身份验证,如果它符合要求,也可以将其用于授权。但是,现在我正在设计数据库模式模型并提出了下表。我不确定这是否是最好的方法并且需要一些反馈。
要求
根据用户的角色和组成员身份授权用户。角色可以分配给组或个人用户。数据分散在多个表中,但在这里我将仅举一个存储项目详细信息的表的示例。
授权表列表
Table:APP_USER : This table will store the user details along with hashed password
Columns: ID/Username/Password
Table:APP_ROLES : This table stores the roles definitions
Columns:ID/Rolename/Desc
Table: APP_PRIVILEGES : This table stores the actual privileges that are assigned to roles
Columns: ID/Privilege Name/Privilege Type/Role ID
Table: APP_GROUPS: This table stores the group definitions
Columns: ID/GroupName/
Table: APP_USER_GROUPS_MAPPING: This table stores mapping of users to groups and has references to APP_USERS & APP_Groups tables
Columns: USER_ID/Group ID
Table: APP_GROUP_ROLES_MAPPING: This table stores the mapping of groups to roles and has references to APP_ROLES and APP_GROUPS
Columns: Group_ID/Role_ID
Table: APP_USER_ROLE_MAPPING: This table stores the mapping of users to roles in case the role is directly assigned to users and has references to APP_USERS and APP_ROLES tables
Columns: USER_ID/ROLE_ID
Table: APP_PROJECTS_DETAILS: This is one of the many tables that store the data. This specific table holds project details
Columns: ID/PROJECT_NAME/DESC etc
Table: APP_GROUP_PROJECTS_MAPPING: This table stores the permission mapping of which groups has access to which projects.
授权示例:用户尝试删除项目 Test1
- 从 APP_GROUP_PROJECTS_MAPPING 检索项目 Test1 的项目/组映射
- 从 APP_USER_GROUPS_MAPPING 检索用户组
- 检查是否有任何用户组有权访问项目 Test1
- 假设用户有权限,通过分别查询 APP_USER_ROLE_MAPPING 和 APP_GROUP_ROLES_MAPPING 来检查用户是否直接或通过组有 DELETE_PROJECT 权限
- 删除项目Test1
我个人觉得这有点复杂,但不确定如何改进