日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

典型的简单权限分配系统方法介绍

發(fā)布時間:2023/12/20 windows 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 典型的简单权限分配系统方法介绍 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

??? 一個struts1+spring+hibernate的典型權(quán)限系統(tǒng)的設(shè)計(jì)思路,歸納小結(jié)如下,特別適用于簡單場合的,比如某個單位下,有直屬單位及部門的

情況.數(shù)據(jù)表設(shè)計(jì)如下
user表:
? userid:
? username:
? unitid: //所屬單位的id

? deptid://所屬部門的id

?? status:0表示為普通用戶 1:表示為該單位的最高管理員

?

role角色表
??
? id:編號

??rolename:角色名
? content:角色的具體分配權(quán)限

?? memo:備注
??? unit:所屬的單位id

userright表:(user與role是多對多,因此需要該表)
??? id:
??? userId:
??? roleid:

?

unit表(單位表)
???? unitId:單位編號
??? unitName:單位名
???? fatherId:上級單位ID (如果為0的時候,表示為最上層的單位)
??? allFatherId:保存所有關(guān)聯(lián)的父級單位的id路徑)

?? unitType :表明是單位還是部門,? 0:單位, 1:部門
??

舉個例子說明下:
? ?? unitid?? unitname??? fatherid??? allfatherid?? unittype

??????? 1???????根單位????????????? 0????????????????????????? 0

??????? 2????? 根單位部門1?????? 1????????? ,1???????????????1

??????? 3????? 直屬單位1?????????? 1??????? ,1????????????????0

??????? 4????? 直屬單位1的部門1? 3????? ,1,3???????????? 1

?

AddressGroup? 單位群組表:這個表的作用在于,可以將某幾個單位歸為一個群組,那么比如在發(fā)文的時候,可以一次同時發(fā)送文件給該群組下的
所有的單位
?? groupId?? 群組編號:
?? groupName?? 群組名稱
?? content:包含的單位id,比如某個群組有單位1,3的

?

二 在頁面層中,類似如下:
? ??? <td rowspan=4>發(fā)文管理</td>
????? <td><input name="box" type="checkbox" value="211">發(fā)文登記</td>
????? <td><input name="box" type="checkbox" value="212" >創(chuàng)建</td>
????? <td><input name="box" type="checkbox" value="213" >修改</td>
????? <td width=15%><input name="box" type="checkbox" value="215" >查看</td>

? .......就是很多個上面的形式,

然后用javascript把用戶所選的都記錄下來
?? function check(){
? if (thisForm.roleName.value == ""||trim(thisForm.roleName.value)==""){
??? alert("請?zhí)顚懡巧Q!");
??? thisForm.roleName.focus();
??? return false;
? }
? thisForm.content.value=getRole();
? thisForm.submit();
}
//將角色用逗號連接起來
function getRole(){
? var allCHK = document.body.all.tags('INPUT');
? var lstr = "" ;
? for(i=0;i<allCHK.length;i++){
??? if(allCHK[i].type.toUpperCase()=="CHECKBOX" && allCHK[i].checked==true){
?????? if (lstr==""){
????????? lstr = allCHK[i].value;}
?????? else {lstr= lstr + "," + allCHK[i].value;???? }
???? }
? }
? return lstr ;
}

同樣要埋藏一個hidden域來保存咯
<input type=hidden name=content value="$!role.getContent()">

?

三 action層的保存
??? /**
? * 保存角色信息
? */
?public void saveRole(Role role)throws Exception{
??String where = " from Role where roleName='"+role.getRoleName()+"' and unitId = "+role.getUnit().getUnitId()+" and roleId<>"+role.getRoleId();
??List list = roleDao.find(where);
??if(list.size()>0){
???throw new LogicException("本單位中已經(jīng)存在" + role.getRoleName() + "這個角色");
??}
??roleDao.save(role);
?}

?

四 編輯角色時,把某個角色讀取出來,回顯在頁面上
?? public ActionForward viewRole(
??ActionMapping mapping,
??ActionForm form,
??HttpServletRequest request,
??HttpServletResponse response){
??String roleId = request.getParameter("roleId");
??if(!("".equals(roleId))){
???Role role = roleManager.getRole(roleId);
???request.setAttribute("role",role);
??}
??return mapping.findForward("viewRole");
?}

??

?? 在JSP頁面中,可以讀出來 ,可以在body的onload函數(shù)中,讀init();

<input type=hidden name="content" value="$!role.getContent()">
?? function init(){
?var allCHK = document.body.all.tags('INPUT');
?var content = thisForm.content.value;
?if(content != ""){
?? var strIds = content.split(",");
?? for(k=0;k<strIds.length;k++){
????? for(i=0;i<allCHK.length;i++){
??????? if(allCHK[i].type.toUpperCase()=="CHECKBOX"? &&? allCHK[i].name=="box"? && allCHK[i].value==strIds[k]) {
?????????? allCHK[i].checked=true ;
??????? }
????? }
?? }


?}
}

?

五? 權(quán)限的判斷
??? 一般在一個菜單里面,可以在導(dǎo)航菜單中予以體現(xiàn)
? 下面是velocity的一個例子
??? #set ($RECVDOC_LIST = 111)
#set ($RECVDOC_SIGN = 112)
#set ($RECVDOC_TUIHUI = 113)
#set ($RECVDOC_READ = 114)
#set ($RECVDOC_LOOKFOR = 115)?

?? 就是設(shè)定某些功能的權(quán)限編碼

?然后是service層的,取出某個用戶的權(quán)限:
?? ?public? Vector getPermissionIDsByUserId(int userId) throws Exception{
??? int i;
??? Vector v=new Vector();
??? String sql=" from Role where roleid in (select roleId from UsersRight where userId="+userId+")";
??? List list = roleDao.find(sql);
??? Iterator iter = list.iterator();
??? while(iter.hasNext()){
??? ?Role role = (Role)iter.next();
??????? String strIds[] = StringUtils.split(role.getContent(),",");
??????? for(i = 0; i < strIds.length; i++){
?????????? v.add(strIds[i]);
??????? }
??? }
??? return v;
? }
}

?

public boolean? hasPermission(int permissionId) throws Exception{
????? String permissionIdStr=Integer.toString(permissionId);
????? boolean retValue = false;
????? if(permission == null) {
??? ??
??? ?? //返回該用戶的權(quán)限
??????? permission = rmg.getPermissionIDsByUserId(u.getUserId().intValue());
????? }
????? if(permissionIdStr.length()==3){? retValue=permission.contains(permissionIdStr);}

?

????? if(permissionIdStr.length()==1)
????? {
????????? int i;
????????? for(i=0;i<permission.size();i++)
????????? {
????????????? if (((String)permission.elementAt(i)).startsWith(permissionIdStr))
????????????? {
???????????????? retValue=true;
???????????????? i=permission.size();
????????????? }
????????? }
????? }
????? return retValue;
??? }
???

?菜單攔的判斷
??

?var p;
? #if($userinfo.hasPermission(1))
??? p = new createPanel('recvdoc','收文管理');
??? #if($userinfo.hasPermission($RECVDOC_SIGN_LIST) || $userinfo.hasPermission($RECVDOC_SIGN_PRINT) || $userinfo.hasPermission($RECVDOC_SIGN_READ) || $userinfo.hasPermission($RECVDOC_SIGN_LOOKFOR))
????? p.addButton('$request.getContextPath()/menu/images/recvdoc.gif','待簽收文件','changePage("10");');
??? #end

?

?? 比如上面的收文管理模塊中,有很多個子功能,這里首先傳入到userinfo.hasPermission(1))去判斷,

這時會執(zhí)行if(permissionIdStr.length()==1)
????? {
的判斷,

?? 假如該用戶有收文管理下的某個子功能的權(quán)限,比如111,則通過該驗(yàn)證(注意?? i=permission.size();跳出FOR了,返回true值,因此該
用戶可以看到"收文管理"這個大的菜單,至于該用戶能具體看到下面的哪些子功能,則通過
??? if(permissionIdStr.length()==3){? retValue=permission.contains(permissionIdStr);} 去判斷了.

?

?

?

?

?

?

?

總結(jié)

以上是生活随笔為你收集整理的典型的简单权限分配系统方法介绍的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。