Initial knowledge of role authority design
This article will introduce the author's authorization module ( flea-frame-auth ) under the flea-frame framework , which is based on RBAC .
What is RBAC?
RBAC (Role-Based Access Control), role-based access control. The basic idea is to add the concept of a role between users and permissions. Each role is associated with single or multiple permissions. You only need to assign the appropriate role to the user, and the user has all the permissions under the associated role.
Compared with directly assigning permissions to users, it brings complexity and redundancy of users and permission data; RBAC only needs to assign corresponding roles to users, and the system overhead caused by changes in the permissions of roles is compared with that of users. Much smaller.
The RBAC model can be divided into four types : RBAC0 , RBAC1 , RBAC2 , and RBAC3 . Among them, RBAC0 is the simplest role permission model (users, roles and permissions), and RBAC1 , RBAC2 , RBAC3 are all based on RBAC0 . For more understanding of RBAC , see the following extension link:
expand:
What is included in flea-frame-auth?
flea-frame-auth contains four sub-modules:
- User submodule
- Role submodule
- Permission submodule
- Function sub-module
1. Overview of related tables
Table Name | Chinese description |
---|---|
flea_account | Account |
flea_account_attr | Account extended attributes |
flea_real_name_info | Real name information |
flea_login_log_YYYYMM | Login log |
flea_user | user |
flea_user_attr | User extended attributes |
flea_user_rel | User association (role, role group) |
flea_user_group | user group |
flea_user_group_rel | User group association (role, role group) |
flea_role | Character |
flea_role_rel | Role association (role, permission, permission group) |
flea_role_group | Role group (not involved in authorization) |
flea_role_group_rel | Role group association (role) |
flea_privilege | Authority |
flea_privilege_rel | Permission association (menu, operation, element) |
flea_privilege_group | Rights Groups |
flea_privilege_group_rel | Permission group association (permission) |
flea_menu | menu |
flea_operation | operating |
flea_element | Element (page) |
flea_function_attr | Function extension attributes |
2. Related table SQL
The above-mentioned related SQL tables, the author will not list them one by one here. You can check fleaauth.sql on GitHub . The script content is based on MySQL and can be used as a reference.
3. User sub-module introduction
Table Name | Chinese description |
---|---|
flea_account | Account |
flea_account_attr | Account extended attributes |
flea_real_name_info | Real name information |
flea_login_log_YYYYMM | Login log |
flea_user | user |
flea_user_attr | User extended attributes |
flea_user_rel | User association (role, role group) |
flea_user_group | user group |
flea_user_group_rel | User group association (role, role group) |
(1) Account
Here are subdivided into system accounts and operating accounts :
The system account , the account information registered in the authorization module of each application system, is mainly used for the authorization verification of the interaction between the systems; the
operating account , the account information registered by the user of each application system.
(2) Account extended attributes
授权模块提供的账户自定义的属性,用于满足不同应用系统差异化的数据要求;
比如,这里可以自定义账户的类型,用于区分不同账户。
(3) 用户
与账户相对应,这里可细分 系统用户 和 操作用户 :
系统用户,各应用系统在授权模块所注册的用户信息;
操作用户,各应用系统使用者注册的用户信息。
(4) 用户扩展属性
授权模块提供的用户自定义的属性,用于满足不同应用系统差异化的数据要求。
(5) 实名信息
授权模块提供的表,用于记录用户实名认证的信息。
(6) 登录日志
授权模块提供的表,用于记录操作用户登录和登出系统的日志信息。
(7) 用户关联
授权模块提供的表,目前可关联 角色,角色组。
用户关联角色 ,记录了实际授予给用户的角色信息;
用户关联角色组,记录了实际授予给用户的角色组中角色信息。
(8) 用户组
授权模块提供的表,可以理解为同类型的用户集合;用户拥有的权限,包含自身授权和其归属的用户组授权。
(9) 用户组关联
授权模块提供的表,目前可关联 角色,角色组。
用户组关联角色 ,记录了实际授予给用户组的角色信息;
用户组关联角色组,记录了实际授予给用户组的角色组中角色信息。
4. 角色子模块介绍
表名 | 中文描述 |
---|---|
flea_role | 角色 |
flea_role_rel | 角色关联(角色, 权限, 权限组) |
flea_role_group | 角色组(不参与授权) |
flea_role_group_rel | 角色组关联(角色) |
(1) 角色
授权模块提供的表,可理解为具备一定权限的一类用户。
(2) 角色关联
授权模块提供的表,目前可关联 角色、权限、权限组。
角色关联角色,引入了如下概念:
- 角色继承,关联角色(子角色)可继承被关联角色(父角色)的所有权限;
- 角色互斥,关联角色和被关联角色存在权限上的相互制约,在进行用户授权时,两者不能同时授予同一用户;
- 角色基数约束,系统中可以拥有这个角色的用户数目限制;
角色关联权限,记录了实际给角色绑定的权限信息。
角色关联权限组,记录了实际给角色绑定的权限组中的权限信息。
(3) 角色组
授权模块提供的表,可理解为具备一定权限的一类用户的集合;它本身不参与授权,其下所拥有的权限由其角色成员决定。
(4) 角色组关联
授权模块提供的表,目前可关联 角色。
角色组关联角色,引入了如下概念:
- 组内互斥,角色组中的角色存在权限上的相互制约,在进行用户授权时,只能选择组内的一个角色授予用户或用户组;
5. 权限子模块介绍
表名 | 中文描述 |
---|---|
flea_privilege | 权限 |
flea_privilege_rel | 权限关联(菜单, 操作, 元素) |
flea_privilege_group | 权限组 |
flea_privilege_group_rel | 权限组关联 (权限) |
(1) 权限
授权模块提供的表,可理解为系统中用户可操作资源的范围和程度。
(2) 权限关联
授权模块提供的表,目前定义三种功能的关联,分别为 菜单、操作 和 元素。
(3) 权限组
授权模块提供的表,可以理解为同类型的权限的集合;权限和权限组之间是多对一的关系,权限表中 group_id 记录权限组编号,默认值为-1;权限组关联的功能,即为其下所有权限关联的功能,不单独为权限组关联功能。
(4) 权限组关联
授权模块提供的表,目前可关联 权限。
权限组关联权限,引入了如下概念:
- 组内互斥,权限组中的权限存在可操作资源的范围和程度上的相互制约,在进行角色授权时,只能选择组内的一个权限授予角色。
6. 功能子模块介绍
表名 | 中文描述 |
---|---|
flea_menu | 菜单 |
flea_operation | 操作 |
flea_element | 元素 (页面) |
flea_function_attr | 功能扩展属性 |
目前功能子模块包含 菜单、操作 和 元素,这些功能都和权限相关联【可参考 授权模块下的 权限关联表 flea_privilege_rel 】,如下:
(1) 菜单
授权模块提供的表,可解释为一系列业务逻辑的总和,为完成某种特定功能,而定义的一类功能单元。
(2) 操作
授权模块提供的表,可理解为业务逻辑上较为单一的功能单元,如角色新增,权限新增等。
(3) 元素
授权模块提供的表,目前有页面元素定义,如页面按钮等。
(4) 功能扩展属性
授权模块提供的表,为上述功能单元配置扩展属性。
如果以后需要新增某种功能的权限控制,只需要如下操作:
- 在功能子模块中新增相关功能表;
- 在权限子模块的 权限关联表 中新定义一种 关联类型 【rel_type】,并绑定上相关授权数据。