权限管理系统概要设计
权限控制存在于大多数系统当中,因为大多数系统都需要:
- 出于安全性考虑,防止系统受到恶意操作。比如,恶意绕过不完善的权限系统进入系统查询敏感数据
- 设立用户可见范围,避免用户过度操作。比如,避免用户随意删除/修改不应当他处理的数据
一个公司一般来说开发、维护多个系统,而权限控制又常见于各系统中,为避免重复劳动,可以将权限控制提取出一个系统,再通过RPC方式供其他系统调用,如HTTP、Web Service。
一般来说,系统的权限校验点在于,并不限于:
- 登陆。检查用户口令是否正确
- 导航菜单。根据用户/角色的权限加载菜单项,只展现拥有的权限
- 具体页面。只展现拥有的按钮
- 进入具体业务前,检查权限,一般来说,可通过URL进行控制
- 点击菜单项,进入具体功能(菜单级别的权限控制)
- 点击具体功能内的操作按钮,比如【Add】(按钮级别的权限控制)
对于上述这些基础的功能,经典的权限5表就可实现:
MYSQL DDL :

drop table if exists T_FUNCTION; drop table if exists T_ROLE; drop table if exists T_ROLE_FUNCTION; drop table if exists T_USER; drop table if exists T_USER_ROLE; /*==============================================================*/ /* Table: T_FUNCTION */ /*==============================================================*/ create table T_FUNCTION ( ID int(11) not null, NAME varchar(128) comment '名称', CODE varchar(128) comment '功能编码', URL varchar(256) comment '功能链接(请求地址)', TYPE char(1) comment '类型:菜单、按钮', STATUS char(1) comment '状态:有效、无效', primary key (ID) ); /*==============================================================*/ /* Table: T_ROLE */ /*==============================================================*/ create table T_ROLE ( ID int(11) not null, NAME varchar(128) comment '名称', STATUS char(1) comment '状态:有效、无效', primary key (ID) ); /*==============================================================*/ /* Table: T_ROLE_FUNCTION */ /*==============================================================*/ create table T_ROLE_FUNCTION ( ID int(11) not null, ROLE_ID int(11), FUNCTION_ID int(11), primary key (ID) ); /*==============================================================*/ /* Table: T_USER */ /*==============================================================*/ create table T_USER ( ID int(11) not null, NAME varchar(128) comment '名字', LOGIN_ID varchar(128) comment '登录ID', PASSWORD varchar(128) comment '密码', STATUS char(1) comment '状态:有效、无效', primary key (ID) ); /*==============================================================*/ /* Table: T_USER_ROLE */ /*==============================================================*/ create table T_USER_ROLE ( ID int(11) not null, USER_ID int(11), ROLE_ID int(11), primary key (ID) ); alter table T_ROLE_FUNCTION add constraint FK_Reference_3 foreign key (ROLE_ID) references T_ROLE (ID) on delete restrict on update restrict; alter table T_ROLE_FUNCTION add constraint FK_Reference_4 foreign key (FUNCTION_ID) references T_FUNCTION (ID) on delete restrict on update restrict; alter table T_USER_ROLE add constraint FK_Reference_1 foreign key (USER_ID) references T_USER (ID) on delete restrict on update restrict; alter table T_USER_ROLE add constraint FK_Reference_2 foreign key (ROLE_ID) references T_ROLE (ID) on delete restrict on update restrict;
由于权限系统是多个系统共同使用的,所以需要加上所属系统的属性:
MYSQL DDL :

drop table if exists T_FUNCTION; drop table if exists T_ROLE; drop table if exists T_ROLE_FUNCTION; drop table if exists T_SYSTEM; drop table if exists T_USER; drop table if exists T_USER_ROLE; /*==============================================================*/ /* Table: T_FUNCTION */ /*==============================================================*/ create table T_FUNCTION ( ID int(11) not null, NAME varchar(128) comment '名称', CODE varchar(128) comment '功能编码', URL varchar(256) comment '功能链接(请求地址)', TYPE char(1) comment '类型:菜单、按钮', STATUS char(1) comment '状态:有效、无效', SYSTEM_ID int(11) comment '系统编码', primary key (ID) ); /*==============================================================*/ /* Table: T_ROLE */ /*==============================================================*/ create table T_ROLE ( ID int(11) not null, NAME varchar(128) comment '名称', STATUS char(1) comment '状态:有效、无效', SYSTEM_ID int(11) comment '系统编码', primary key (ID) ); /*==============================================================*/ /* Table: T_ROLE_FUNCTION */ /*==============================================================*/ create table T_ROLE_FUNCTION ( ID int(11) not null, ROLE_ID int(11), FUNCTION_ID int(11), primary key (ID) ); /*==============================================================*/ /* Table: T_SYSTEM */ /*==============================================================*/ create table T_SYSTEM ( ID int(11) not null, NAME varchar(128), STATUS char(1), primary key (ID) ); /*==============================================================*/ /* Table: T_USER */ /*==============================================================*/ create table T_USER ( ID int(11) not null, NAME varchar(128) comment '名字', LOGIN_ID varchar(128) comment '登录ID', PASSWORD varchar(128) comment '密码', STATUS char(1) comment '状态:有效、无效', primary key (ID) ); /*==============================================================*/ /* Table: T_USER_ROLE */ /*==============================================================*/ create table T_USER_ROLE ( ID int(11) not null, USER_ID int(11), ROLE_ID int(11), primary key (ID) ); alter table T_FUNCTION add constraint FK_Reference_6 foreign key (SYSTEM_ID) references T_SYSTEM (ID) on delete restrict on update restrict; alter table T_ROLE add constraint FK_Reference_5 foreign key (SYSTEM_ID) references T_SYSTEM (ID) on delete restrict on update restrict; alter table T_ROLE_FUNCTION add constraint FK_Reference_3 foreign key (ROLE_ID) references T_ROLE (ID) on delete restrict on update restrict; alter table T_ROLE_FUNCTION add constraint FK_Reference_4 foreign key (FUNCTION_ID) references T_FUNCTION (ID) on delete restrict on update restrict; alter table T_USER_ROLE add constraint FK_Reference_1 foreign key (USER_ID) references T_USER (ID) on delete restrict on update restrict; alter table T_USER_ROLE add constraint FK_Reference_2 foreign key (ROLE_ID) references T_ROLE (ID) on delete restrict on update restrict;
具备角色继承的设计,待续。。。
作者:Nick Huang 博客:http://www.cnblogs.com/nick-huang/
本博客为学习、笔记之用,以笔记形式记录学习的知识与感悟。学习过程中可能参考各种资料,如觉文中表述过分引用,请务必告知,以便迅速处理。如有错漏,不吝赐教。
如果本文对您有用,点赞或评论哦;如果您喜欢我的文章,请点击关注我哦~
本博客为学习、笔记之用,以笔记形式记录学习的知识与感悟。学习过程中可能参考各种资料,如觉文中表述过分引用,请务必告知,以便迅速处理。如有错漏,不吝赐教。
如果本文对您有用,点赞或评论哦;如果您喜欢我的文章,请点击关注我哦~
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用