用户权限设计(一)-数据库设计
来源:互联网 发布:linux 命令 竖线 编辑:程序博客网 时间:2024/05/19 23:53
在WEB开发中,难免要解决权限管理的问题,在这里结合项目和之前对权限的理解,记录下权限系统构建的过程。
主要运用的技术:Spring MVC + Mybatis+Bootstrap + Apache Shiro + MySQL
权限系统设计思想:权限主要是指明哪些用户可以对系统的哪些功能有什么样的权限,而一个系统的功能从程序开发的角度来说就是对数据的CURD(增、删、改、查)。我们进一步把用户就行分组处理,因为可能不同的用户都是拥有相同的权限的,这样我们只要把这些用户归属于用户组,再对用户组进行授权,这样就有效的控制了用户。从权限的作用来看,我们需要的实体有:用户,权限,角色。一般来说一个用户可能属于多个角色,就像那些当官的挂着一堆职称一样,一个角色能包含多个用户;类似的角色和权限具有类似的关系。从描述中我们再细化下,给出以下E-R图(LZ自己画的,可能不符合E-R设计标准,主要方便看):
用户权限设计 E-R 图
上面的图是LZ 用PowerDesigner画出来的,感兴趣的可以搜一下。我在这里用户权重这个概念,角色不直接拥有权限,让权重直接对权限,这样对权限进行了细分,可以让同一个角色在基础权限上在进行划分。
PowerDesigner生成MySQL 脚本如下:
/*==============================================================*//* DBMS name: MySQL 5.0 *//* Created on: 2017/4/13 19:22:14 *//*==============================================================*/drop table if exists sys_permissions;drop table if exists sys_role;drop table if exists sys_role_per;drop table if exists sys_user;drop table if exists sys_user_role;drop table if exists sys_weight;drop table if exists sys_weight_per;/*==============================================================*//* Table: sys_permissions 系统权限表 *//*==============================================================*/create table sys_permissions( ID bigint not null, PER_NAME varchar(50) not null, PER_DESC varchar(100) not null, PER_LEVEL int, PER_PARENT_ID bigint, PER_URL varchar(100), PER_AUTHORIZATION varchar(50) not null, PER_RANKING int, PER_STATUS tinyint not null, ICON_URL varchar(100), CREATIME datetime, UPDATETIME datetime, primary key (ID)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;alter table sys_permissions comment '权限表';/*==============================================================*//* Table: sys_role 系统角色表 *//*==============================================================*/create table sys_role( ID bigint not null COMMENT 'ID', NAME varchar(100) COMMENT '角色名称', CODE varchar(50) COMMENT '编号', DESCRIPTION varchar(200) COMMENT '角色描述', WEIGHT bigint COMMENT '权重表中权重号', primary key (ID))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;/*==============================================================*//* Table: sys_role_per 角色权限表 *//*==============================================================*/create table sys_role_per( ROLE_ID bigint COMMENT '角色表ID', PER_ID bigint COMMENT '权限表ID', ID bigint not null COMMENT 'ID', primary key (ID))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;/*==============================================================*//* Table: sys_user 用户表 *//*==============================================================*/create table sys_user( ID bigint not null COMMENT 'ID', USER_ID varchar(120) COMMENT '用户ID', PWD varchar(50) COMMENT '密码', ICON varchar(300) COMMENT '图标', NICK_NAME varchar(120) COMMENT '昵称', SEX varchar(2) COMMENT '性别', CREATE_TIME datetime COMMENT '创建时间', UPDATE_TIME datetime COMMENT '更新时间' primary key (ID))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;alter table sys_user comment '用户信息表';/*==============================================================*//* Table: sys_user_role 用户角色表 *//*==============================================================*/create table sys_user_role( ID bigint not null COMMENT 'ID' , USER_ID bigint not null COMMENT '用户表ID', ROLE_ID bigint not null COMMENT '角色ID', primary key (ID))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;/*==============================================================*//* Table: sys_weight 权重表 *//*==============================================================*/create table sys_weight( ID bigint not null COMMENT 'ID' , WEIGHT_NAME varchar(50) not null COMMENT '权重名称', WEIGHT_DES varchar(200) COMMENT '权重描述', primary key (ID))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;/*==============================================================*//* Table: sys_weight_per 权重权限表 *//*==============================================================*/create table sys_weight_per( ID bigint not null COMMENT 'ID', WEIGHT_ID bigint not null COMMENT '权重ID', PER_ID bigint not null COMMENT '权限ID', primary key (ID))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;alter table sys_role add constraint FK_ROLE_WEIGHT foreign key (WEIGHT) references sys_weight (ID) on delete restrict on update restrict;alter table sys_role_per add constraint FK_ROLE_ID foreign key (ROLE_ID) references sys_role (ID) on delete restrict on update restrict;alter table sys_role_per add constraint FK_PER_ID foreign key (PER_ID) references sys_permissions (ID) on delete restrict on update restrict;alter table sys_user_role add constraint FK_USER_ROLE_USER_ID foreign key (USER_ID) references sys_user (ID) on delete restrict on update restrict;alter table sys_user_role add constraint FK_USER_ROLE_ROLE_ID foreign key (ROLE_ID) references sys_role (ID) on delete restrict on update restrict;alter table sys_weight_per add constraint FK_WEIGHT_PER_PER_ID foreign key (PER_ID) references sys_permissions (ID) on delete restrict on update restrict;alter table sys_weight_per add constraint FK_WEIGHT_PER_WEIGHT_ID foreign key (WEIGHT_ID) references sys_weight (ID) on delete restrict on update restrict;
接下来就是把脚本在数据库跑下,这样基石(数据库表)就算搭建好了。
0 0
- 用户权限设计(一)-数据库设计
- 用户权限的数据库设计
- 用户权限数据库设计
- 用户权限数据库设计
- 数据库设计-用户权限
- 用户权限管理数据库设计
- 用户权限数据库设计解决方案
- 用户权限设计(一)
- 关于用户权限的数据库设计
- RBAC用户权限管理数据库设计
- RBAC用户权限管理数据库设计
- 后台管理用户权限数据库设计
- RBAC用户权限管理数据库设计
- RBAC用户权限管理数据库设计
- RBAC用户权限管理数据库设计
- RBAC用户权限管理数据库设计
- RBAC用户权限管理数据库设计
- RBAC用户权限管理数据库设计
- 数据标准化/归一化方法(Data Normalization Method )
- 方法
- Java实现Md5加密
- 并发编程--公平锁和非公平锁
- 提供一个linux串口程序
- 用户权限设计(一)-数据库设计
- Opencv学习---霍夫变换
- 套接字模式
- 卸载win10 自带应用
- 栈
- 前台获取后台返回的图片并显示
- 宜信大数据创新中心2017实习生面试(三轮)
- Linux下访问网络文件系统
- Paxos算法原理与推导