权限设计是软件开发中的一个重要;知识点下面是我研究登陆权限的一点心得以供参考 ;后面会持续更新
?
一;分析
? ? ?管理系统是我们最常见的,学校的教务系统,金蝶的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‘)))
?
?
?
?
? ?
原文:http://baihe747.iteye.com/blog/2174101