权限管理系统概要设计

权限控制存在于大多数系统当中,因为大多数系统都需要:

  • 出于安全性考虑,防止系统受到恶意操作。比如,恶意绕过不完善的权限系统进入系统查询敏感数据
  • 设立用户可见范围,避免用户过度操作。比如,避免用户随意删除/修改不应当他处理的数据

 

一个公司一般来说开发、维护多个系统,而权限控制又常见于各系统中,为避免重复劳动,可以将权限控制提取出一个系统,再通过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;
View Code

 

由于权限系统是多个系统共同使用的,所以需要加上所属系统的属性:

 

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;
View Code

 

具备角色继承的设计,待续。。。

 

posted @ 2015-03-30 23:12  nick_huang  阅读(2116)  评论(0编辑  收藏  举报