博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
操作权限,数据权限的解决方案
阅读量:6934 次
发布时间:2019-06-27

本文共 5012 字,大约阅读时间需要 16 分钟。

ERP系统常见的问题:操作权限、数据权限的解决方案

 1、页面:通过权限控制某个页面是否显示

 2、按钮:通过权限控制某个页面上的按钮是否显示

 3、方法:通过权限控制某个方法是否能够访问

 4、数据行:通过权限控制某个用户只能看到几行数据

后台设置权限

 1、操作权限:添加计划、修改计划、搜索计划权限

 2、数据权限:本人、本部门、所有

实现设置

 1、页面:通过请求查询用户有哪些权限-有哪些模块

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function 
loadMenu(){
    
$.ajax({
        
url : 
""
,
        
type : 
"post"
,
        
dataType : 
"jsonp"
,
        
jsonp: 
"jsonpCallback"
,
        
success : 
function
(result) {
             
            
var 
lefthtml=
"<li><a href=''><i class='fa fa-tachometer fa-fw'></i> <span class='menu-text'>首页</span></a>  </li>"
;
            
var 
category=
""
;
            
var 
i=0;
            
$(result.leftModule).each(
function
(){ 
                
if
(
this
.categoryName!=category){
                    
if
(i!=0){
                        
lefthtml=lefthtml+
"</ul></li>"
;
                    
}
                    
lefthtml=lefthtml+  
"<li class='has-sub'>"
;
                    
lefthtml=lefthtml+  
"<a href='javascript:;' class=''>"
;
                    
if
(
this
.categoryName==
"客源管理"
){
                        
lefthtml=lefthtml+  
"<i class='fa fa-user fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
                    
}
else 
if
(
this
.categoryName==
"房源管理"
){
                        
lefthtml=lefthtml+  
"<i class='fa fa-home fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
                    
}
else 
if
(
this
.categoryName==
"我的首页"
){
                        
lefthtml=lefthtml+  
"<i class='fa fa-bookmark-o fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
                    
}
else 
if
(
this
.categoryName==
"签约管理"
){
                        
lefthtml=lefthtml+  
"<i class='fa fa-edit fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
                    
}
else 
if
(
this
.categoryName==
"文档公告管理"
){
                        
lefthtml=lefthtml+  
"<i class='fa fa-folder-open fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
                    
}
else 
if
(
this
.categoryName==
"跟进管理"
){
                        
lefthtml=lefthtml+  
"<i class='fa fa-hand-o-right fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
                    
}
else
{
                        
lefthtml=lefthtml+  
"<i class='fa fa-bookmark-o fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
                    
}
                    
lefthtml=lefthtml+  
"<span class='arrow'></span>"
;
                    
lefthtml=lefthtml+  
"</a>"
;
                    
lefthtml=lefthtml+  
"<ul class='sub'>"
;
                    
lefthtml=lefthtml+  
"<li><a class='' href='"
+
this
.link+
"'><span class='sub-menu-text'>"
+
this
.moduleName+
"</span></a></li>"
;   
                    
category=
this
.categoryName;
                
}
else
{
                    
lefthtml=lefthtml+  
"<li><a class='' href='"
+
this
.link+
"'><span class='sub-menu-text'>"
+
this
.moduleName+
"</span></a></li>"
;   
                
}
                
if
(i==result.leftModule.length-1){
                    
lefthtml=lefthtml+
"</ul></li>"
;
                
}
                
i++;
                
});
            
$(
"#leftMenu"
).html(lefthtml);
        
},
        
error : 
function
(err) {
        
}
    
});

   2、按钮 跟进登录人查询该用户有哪些权限码,在每个按钮的设置auth-code="shs_pair"属性

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function 
valideAction(){
    
$.ajax({
        
url :
""
,
        
type:
"post"
,
        
data: {actionCookies:$.cookie(
'actionCookie'
)},
        
dataType: 
"jsonp"
,
        
jsonp:
"jsonpCallback"
,
        
success :
function
(result){
            
var 
authCodeArray= 
new 
Array();
            
$(result).each(
function
(){ 
                
authCodeArray.push(
this
.actionCode);
       
});
            
$(
"[auth-code]"
).each(
function
(){
                
var 
auth_code=$(
this
).attr(
"auth-code"
);
                
if
($.inArray(auth_code, authCodeArray)==-1){
                     
$(
this
).remove();
                
}
             
});
        
}
    
});
     
     
}

 3、方法 通过权限拦截器

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public 
String intercept(ActionInvocation invocation) 
throws 
Exception {
        
ActionContext actionContext = invocation.getInvocationContext();
        
HttpServletRequest request = (HttpServletRequest) actionContext
                
.get(StrutsStatics.HTTP_REQUEST);
        
HttpServletResponse response = (HttpServletResponse) actionContext
                
.get(StrutsStatics.HTTP_RESPONSE);
        
ActionProxy actionProxy = invocation.getProxy();
        
String methodName = actionProxy.getMethod();
        
if 
(StringUtils.isBlank(methodName)) {
            
methodName = 
"execute"
;
        
}
        
Class aClass = actionProxy.getAction().getClass();
        
Method method = aClass.getMethod(methodName);
        
PermissionsCode annotation = method
                
.getAnnotation(PermissionsCode.
class
);
        
String pin = (String) ActionContext.getContext().get(SystemDict.ERP_PIN);
       
/* String actionCookie= cookieUtil.getCookieValue(cookieKeyName);
        
String actionJson= SecurityUtil.decrypt(actionCookie,cookieEncrypt.get("desPrefix"));*/
        
LOG.info("登录人pin----------------"+pin);
        
if (pin!=null&&!pin.equals(adminPin)) {
            
/*List<Map<String,Object>> listPermissions=null;
            
if(actionJson!=null){
                
listPermissions= JsonUtil.fromJson(actionJson,List.class,Map.class);
            
}*/
            
List<ActionResult> actionlist=actionRpc.getActionList(pin);
            
if 
(annotation != 
null 
&& StringUtils.isNotBlank(annotation.code())) {
                
String code = annotation.code();
                
if
(actionlist!=
null 
&& actionlist.size()!=
0
){
                    
for
(ActionResult action : actionlist){
                        
if
(code.equals(action.getActionCode())){
                            
//如果正确则继续执行
                            
this
.setScopeContext(action.getScope());
                            
return 
invocation.invoke();
                        
}
                    
}
                
}
            
else 
{
                
//如果没有权限码则跳过
                
return 
invocation.invoke();
            
}
        
else 
{
            
//如果是admin跳过权限码
            
return 
invocation.invoke();
        
}
        
//跳转错误页面
        
this
.redirect(request, response);
        
return 
null
;
    
}

4、数据行:首先用户有这个权限,同时获取出该权限的权限范围(本人、本部门、所有)

 根据用户的权限范围查询数据行

本文转自 xinsir999 51CTO博客,原文链接:http://blog.51cto.com/xinsir/1869480,如需转载请自行联系原作者
你可能感兴趣的文章
2016-11-15试题解题报告
查看>>
【前端】JSON.stringfy 和 JSON.parse(待续)
查看>>
C++基础——类继承
查看>>
教程-MessageBox 使用方法
查看>>
Recover Binary Search Tree
查看>>
08-图7 公路村村通
查看>>
Java基础学习总结(26)——JNDI入门简介
查看>>
django 动态更新属性值
查看>>
如何挑选适合的前端框架(去哪儿网前端架构师司徒正美)
查看>>
C# 中Excel导出,可以自由设置导出的excel格式
查看>>
mac14.5 mojave安装错误
查看>>
opensuse11.4 apache2 403 错误.
查看>>
【计算几何】【凸包】bzoj1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
查看>>
docker
查看>>
HotSpot虚拟机对象的创建过程
查看>>
分布式系统简单理解
查看>>
lf 前后端分离 (4) 价格策略
查看>>
C++ cctype定义的函数 - 学习笔记(7)
查看>>
C语言:关于socket的基础知识点
查看>>
python基础知识理解
查看>>