角色控制用户权限(一)

权限设计是软件开发中的一个重要;知识点下面是我研究登陆权限的一点心得以供参考 ;后面会持续更新

 

一;分析

     管理系统是我们最常见的,学校的教务系统,金蝶的K/3系统,都涉及到不同权限的人登陆可以操作的数据会有所不同; 不同权限是怎么在数据库中够成设计到一下一些概念;

 

     用户;就是软件使用者

 

     角色/组;软件使用者的身份

 

     权限;用户对软件的使用权限

 

  

二;数据库的设计

 

     1), 基于角色和权限的设计;



 

 

创建下面的四个表;

    用户表; 

                 用户名

                 角色的名称

 

    角色表

         权限

 

    权限表

         权限地址的索引

 

    权限地址表;

 

         权限地址

 

   

2),表的创建

   用户表 ;

  

create table AN_USERS
(
  userid     NUMBER(7) not null,
  usermail   VARCHAR2(30) not null,
  username   VARCHAR2(30) not null,
  userpwd    VARCHAR2(30) default '888888',
  createdate DATE not null,
  usertype   VARCHAR2(20) default 'users',
  userip     VARCHAR2(30) default '127.0.0.1'
)
alter table AN_USERS
  add constraint AN_USERS_PK primary key (USERMAIL)

 

 

角色表;

   

create table AN_ACTION
(
  actionid NUMBER(7) not null,
  usertype VARCHAR2(30) not null,
  msgname  VARCHAR2(30) not null
)

 

 

权限表;

 

create table AN_MSG
(
  msgid   NUMBER(30) not null,
  msgname VARCHAR2(30) not null,
  menuid  NUMBER(30) not null
)

 

 

权限地址表;存储具体的地址

 

create table AN_MENU
(
  menuid    NUMBER(30) not null,
  menu_href VARCHAR2(30) not null
)

 

 

 

分析创建的表之间的关系;

   1,判断用户是否存在 ,在登陆时查询username  返回null表示不存在该用户

    2,如果查询到该用户,

              用户表的usertype字段和角色表的usertype相同,角色表的msgname与权限表的msgname相同,

权限表的menuid与权限地址menuid相同;

 

  语句为;查询用户00002的权限

select menu_href from an_menu where  menuid in (select menuid from an_msg where msgname in    (select msgname from an_action  where usertype in (select usertype from an_users where u     sername='00002')))

   

 

向四张表中插入数据;

   select t.*, t.rowid from AN_menu t

insert into AN_MENU values(an_menu_id.nextval,'材料申请表');

insert into AN_MENU values(an_menu_id.nextval,'材料领取');

insert into AN_MENU values(an_menu_id.nextval,'材料申请记录');

insert into AN_MENU values(an_menu_id.nextval,'权限分配');

insert into AN_MENU values(an_menu_id.nextval,'普通员工');

insert into AN_MENU values(an_menu_id.nextval,'员工总人数');

insert into AN_MENU values(an_menu_id.nextval,'个人资料');

insert into AN_MENU values(an_menu_id.nextval,'员工的出勤表');

 

select t.*, t.rowid from AN_msg t where msgname='供应链管理'

insert into an_msg values(an_msg_id.nextval,'供应链管理',1);

insert into an_msg values(an_msg_id.nextval,'供应链管理',3);

insert into an_msg values(an_msg_id.nextval,'供应链管理',4);

insert into an_msg values(an_msg_id.nextval,'供应链管理',5);

insert into an_msg values(an_msg_id.nextval,'供应链管理',6);

insert into an_msg values(an_msg_id.nextval,'供应链管理',7);

insert into an_msg values(an_msg_id.nextval,'供应链管理',9);

insert into an_msg values(an_msg_id.nextval,'普通供应链管理',2);

insert into an_msg values(an_msg_id.nextval,'普通供应链管理',8);

 

select t.*, t.rowid from AN_ACTION t

insert into AN_ACTION values(an_action_id.nextval,'users','供应链管理');

insert into AN_ACTION values(an_action_id.nextval,'admin','普通供应链管理');

commit;

 

select t.*, t.rowid from AN_USERS t

insert into AN_USERS values(an_user_id.nextval,'15616121427','00001','888888',sysdate,'admin','127.0.0.1');

insert into AN_USERS values(an_user_id.nextval,'110','00002','888888',sysdate,'users','127.0.0.1');

 

 

执行查询语句

查询00002普通权限

 

   select menu_href from an_menu where menuid in (select menuid from an_msg where msgname in (select msgname from an_action where usertype in (select usertype from an_users where u sername='00002')))

 



 

查询00001管理员权限

 

   select menu_href from an_menu where menuid in (select menuid from an_msg where msgname in (select msgname from an_action where usertype in (select usertype from an_users where u sername='00001')))



 
 

 

 

   

1:集成最新,最流行,,最成熟悉的技术框架 springMVC4.1.4,spring4.1.4,mybaits3.2.8,MySQL5.6 2:前端界面采用当前最流行的响应式布局设计 bootstrap3,html5,CSS3,JQueryAjax 特点: 1:基于mybaits插件完成对于基本的增,删,改,查的功能,不需要写任何SQL语句,代码一键调用即可.具有很好的灵活性,方便性,快速性.这样就大大减少代码开发时间,提高开发效率,为企业或个人有效率地节约人力资源的成本! 2:对JAVA的封装,多态,继承特性做了充分的运用,其中也用到了JAVA的一个重要机制--反射机制! 3:对于简单业务的单表增,删,改,查只需要一个entity,不需要写任何的controller,service,mapper等代码,也不需要任何的sql语句,让程序员更专注于前端 4:具有安全,可靠能快速,方便,高效地进行开发 5:系统具有可扩展性,可控性,通用性强的基础 6:基础的业务性不强的列表界面采取直接配置方式,不需要写任何代码,直接生成界面,具有快捷,快速,方便地查看实时功能效果 7:集成监控功能,随时监控系统内存,CPU,磁盘的最新变化 8:新增告警邮件触发功能,让用户随时了解服务器状况 目标: 1:提升开发效率,规范开发标准 2:提高质量,降低复杂度 3:打造一个开发简单.效率快..性能好.. 易上手的框架 兼容性: 1:设备:兼容IPAD,手机,电脑,笔记本等等 2:界面:兼容IE8+,firefox,google等等 3:数据库:兼容MySQL,oracel,sqlserver2008 通用性: 让项目只注重业务,为企业或个人有效率地节约人力资源的成本! 1:系统具有最基本的用户,角色,资源,权限管理,日志管理等通用性功能,企业或个人可直接在此基础上进行开发,扩展,添加各自的需求和业务功能!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值