Procházet zdrojové kódy

权限检测变更。

root před 5 roky
rodič
revize
55f0b029ea

binární
1.dmp


+ 4 - 0
src/main/java/com/kingkong/bljs/api/RestController.java

@@ -1,6 +1,7 @@
1 1
 package com.kingkong.bljs.api;
2 2
 
3 3
 
4
+import com.kingkong.bljs.common.PrivChecker;
4 5
 import com.kingkong.bljs.service.ModelService;
5 6
 import com.kingkong.bljs.service.RestService;
6 7
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@ public class RestController extends BaseController {
24 25
      * @param code
25 26
      * @return
26 27
      */
28
+    @PrivChecker(type = 6,code = "#code", name = "0")
27 29
     @GetMapping("{code}")
28 30
     public Object get(@PathVariable String code, @RequestParam("body") String body) throws Exception{
29 31
         return restService.getData(code,body);
@@ -37,12 +39,14 @@ public class RestController extends BaseController {
37 39
      * @return
38 40
      * @throws Exception
39 41
      */
42
+    @PrivChecker(type = 6,code = "#code", name = "1")
40 43
     @PostMapping("{code}")
41 44
     public Object post(@PathVariable String code,@RequestBody String body) throws Exception{
42 45
         return restService.post(code,body);
43 46
     }
44 47
 
45 48
     @DeleteMapping("{code}/{params}")
49
+    @PrivChecker(type = 6,code = "#code", name = "2")
46 50
     public Object delete(@PathVariable String code,@PathVariable String params) throws Exception{
47 51
         return restService.delete(code,params);
48 52
     }

+ 2 - 2
src/main/java/com/kingkong/bljs/common/PrivAspect.java

@@ -47,8 +47,8 @@ public class PrivAspect {
47 47
             params.put('#' + parameterNames[i], args[i]);
48 48
         }
49 49
 
50
-        String name = params.getString(checker.name(),"");
51
-        String code = params.getString(checker.code(),"");
50
+        String name = params.getString(checker.name(),checker.name());
51
+        String code = params.getString(checker.code(),checker.code());
52 52
 
53 53
         if(name.equals(""))
54 54
             throw new Exception("权限配置错误!");

+ 7 - 7
src/main/java/com/kingkong/bljs/service/CommonService.java

@@ -32,7 +32,7 @@ public class CommonService {
32 32
         return new TableColumnCollection(this.queryService.getTableColumns(name));
33 33
     }
34 34
 
35
-    @PrivChecker(type = 1,name = "#name", action = "insert")
35
+    //@PrivChecker(type = 1,name = "#name", action = "insert")
36 36
     public long insert(String name,Map data) throws Exception{
37 37
         JSONObject object = new JSONObject();
38 38
         for(Object key: data.keySet()){
@@ -49,7 +49,7 @@ public class CommonService {
49 49
         return this.queryService.insert(name,object);
50 50
     }
51 51
 
52
-    @PrivChecker(type = 1 ,name = "#name", action = "update")
52
+    //@PrivChecker(type = 1 ,name = "#name", action = "update")
53 53
     public int update(String name,Map data,Map condition){
54 54
         TableColumnCollection columns  = this.getTableColumns(name);
55 55
         if(columns.containColumn("updated_at"))
@@ -58,7 +58,7 @@ public class CommonService {
58 58
         return this.queryService.update(name,data,condition);
59 59
     }
60 60
 
61
-    @PrivChecker(type = 1, name = "#name" ,action = "delete")
61
+    //@PrivChecker(type = 1, name = "#name" ,action = "delete")
62 62
     public boolean delete(String name,Map condition){
63 63
         return this.queryService.delete(name,JObject.parser(condition));
64 64
     }
@@ -67,7 +67,7 @@ public class CommonService {
67 67
         return this.queryService.deleteRaw(name,condition);
68 68
     }
69 69
 
70
-    @PrivChecker(type = 1, name = "#name" ,action = "select")
70
+    //@PrivChecker(type = 1, name = "#name" ,action = "select")
71 71
     public Map find(String name,Map condition){
72 72
         return this.queryService.first(name,condition);
73 73
     }
@@ -84,12 +84,12 @@ public class CommonService {
84 84
         return find(name,where);
85 85
     }
86 86
 
87
-    @PrivChecker(type = 1 , name = "#name" , action = "select")
87
+    //@PrivChecker(type = 1 , name = "#name" , action = "select")
88 88
     public List<Map> select(String name, Map condition){
89 89
         return this.queryService.selectTable(name,condition);
90 90
     }
91 91
 
92
-    @PrivChecker(type = 4, name = "#procName")
92
+    //@PrivChecker(type = 4, name = "#procName")
93 93
     public void executeProc(String procName,List<Object> params){
94 94
         queryService.executeProc(procName,params);
95 95
     }
@@ -104,7 +104,7 @@ public class CommonService {
104 104
      * @param name 序列名称
105 105
      * @return
106 106
      */
107
-    @PrivChecker(type = 5,name = "#name", action = "select")
107
+    //@PrivChecker(type = 5,name = "#name", action = "select")
108 108
     public long getSequence(String name){
109 109
         String strSQL = "select {0}.nextval id from dual";
110 110
         List<Map> result = this.queryService.select(strSQL,name);

+ 3 - 3
src/main/java/com/kingkong/bljs/service/ModuleService.java

@@ -111,7 +111,7 @@ public class ModuleService {
111 111
      * @param mcode 模块避难
112 112
      * @return
113 113
      */
114
-    @PrivChecker(name = "#name",code = "#mid")
114
+    //@PrivChecker(name = "#name",code = "#mid")
115 115
     public Map getData(String mid,String name, JObject querier) throws Exception{
116 116
         //String strSQL = this.getSource(mid,name);
117 117
         Map item = this.getSource(mid,name);
@@ -252,12 +252,12 @@ public class ModuleService {
252 252
         return result;
253 253
     }
254 254
 
255
-    @PrivChecker(type = 1,name = "#name")
255
+    //@PrivChecker(type = 1,name = "#name")
256 256
     public List<Map> getList(String name,Map condition){
257 257
         return commonService.select(name,condition);
258 258
     }
259 259
 
260
-    @PrivChecker(type = 1,name = "#name")
260
+    //@PrivChecker(type = 1,name = "#name")
261 261
     public Map find(String name,Map condition){
262 262
         return commonService.find(name,condition);
263 263
     }

+ 21 - 18
src/main/java/com/kingkong/bljs/service/PrivService.java

@@ -50,26 +50,29 @@ public class PrivService {
50 50
 
51 51
 
52 52
         for(Map item : privs){
53
-            if(1 == type){ //表权限
54
-                if(item.get("name").toString().equals(name) && item.get("action").toString().equals(action))
55
-                    return true;
53
+            if(1 == type){ //表权限,淘汰不用
54
+//                if(item.get("name").toString().equals(name) && item.get("action").toString().equals(action))
55
+//                    return true;
56 56
             }
57
-            else if(0 == type){ //数据源
58
-                if( item.get("m_id").toString().equals(code) && item.get("name").toString().equals(name)
59
-                        && item.get("action").toString().equals(action))
60
-                    return true;
61
-            } else if(2 == type){// url资源
62
-                if(item.get("name").toString().equals(name)){
57
+            else if(0 == type){ //数据源,淘汰不用
58
+//                if( item.get("m_id").toString().equals(code) && item.get("name").toString().equals(name)
59
+//                        && item.get("action").toString().equals(action))
60
+//                    return true;
61
+            } else if(2 == type){// url资源,淘汰不用
62
+//                if(item.get("name").toString().equals(name)){
63
+//                    return true;
64
+//                }
65
+            } else if(4 == type){ //存储过程,淘汰不用
66
+//                if( item.get("name").toString().toUpperCase().equals(name.toUpperCase())){
67
+//                    return  true;
68
+//                }
69
+            } else if (5 == type){//序列,淘汰不用
70
+//                if( item.get("name").toString().toUpperCase().equals(name.toUpperCase())){
71
+//                    return  true;
72
+//                }
73
+            } else if( 6 == type ){
74
+                if(item.get("code").toString().equals(code) && item.get("method").toString().equals(name))
63 75
                     return true;
64
-                }
65
-            } else if(4 == type){ //存储过程
66
-                if( item.get("name").toString().toUpperCase().equals(name.toUpperCase())){
67
-                    return  true;
68
-                }
69
-            } else if (5 == type){//序列
70
-                if( item.get("name").toString().toUpperCase().equals(name.toUpperCase())){
71
-                    return  true;
72
-                }
73 76
             }
74 77
 
75 78
         }

+ 3 - 0
src/main/java/com/kingkong/bljs/service/RestService.java

@@ -57,6 +57,9 @@ public class RestService {
57 57
 
58 58
     private Object sqlAction(UserApi api,String request) {
59 59
         String strSQL = api.getContent();
60
+
61
+        strSQL = moduleService.parserEnvVariable(strSQL);
62
+
60 63
         return queryService.quickQuery(strSQL,request);
61 64
     }
62 65
 

+ 117 - 31
src/main/java/com/kingkong/bljs/service/UserService.java

@@ -106,7 +106,7 @@ public class UserService {
106 106
                 "WHERE t.app_id = z.app_id and t.r_id = z.id and z.status =1 \n" +
107 107
                 "	and t.app_id ={0} and t.u_id ={1}";
108 108
 
109
-        List<Map> roles = queryService.select(strSQL,appid,user.get("id"));
109
+        List<Map> roles = queryService.select(strSQL,appid,user.get("id").toString());
110 110
         user.put("roles",roles);
111 111
 
112 112
         //菜单
@@ -121,17 +121,18 @@ public class UserService {
121 121
 
122 122
 
123 123
         // 后台判断权限
124
-        strSQL = "SELECT a.*,b.id m_id\n" +
125
-                "FROM k_role_priv t,k_module_priv z,k_module_priv_detail a,k_module b\n" +
126
-                "WHERE t.r_id in({0}) and  t.m_code = z.m_code and t.p_code = z.code\n" +
127
-                "	and a.code = z.code  and b.code = z.m_code ";
124
+//        strSQL =  "select a.name\n" +
125
+//                "from k_role_priv t,k_module_priv z,k_module_priv_detail a\n" +
126
+//                "where t.r_id in({0})\n" +
127
+//                "      and t.p_code = z.code and a.code = z.code\n" +
128
+//                "      and a.type = 3";
129
+//
130
+//        List<Map> list = queryService.select(strSQL,strRoles);
131
+//
132
+//        List<Map> privs = new ArrayList<>();
133
+        UserPriv userPriv = new UserPriv(strRoles);
128 134
 
129
-
130
-        List<Map> list = queryService.select(strSQL,strRoles);
131
-
132
-        List<Map> privs = listPriv(list);
133
-
134
-        user.put("privs",privs);
135
+        user.put("privs",userPriv.getPrivs());
135 136
 
136 137
 
137 138
         // 用于在前端判断权限
@@ -145,18 +146,18 @@ public class UserService {
145 146
     }
146 147
 
147 148
 
148
-    private List<Map> listPriv(List<Map> list){
149
-        List<Map> result = new ArrayList<Map>();
150
-        for(int i = 0;i < list.size(); i ++){
151
-            Map item = list.get(i);
152
-            result.add(item);
153
-            if(item.get("type").toString().equals("3")){
154
-                result.addAll(getModuleDefaultPriv(item.get("name").toString()));
155
-
156
-            }
157
-        }
158
-        return result;
159
-    }
149
+//    private List<Map> listPriv(List<Map> list){
150
+//        List<Map> result = new ArrayList<Map>();
151
+//        for(int i = 0;i < list.size(); i ++){
152
+//            Map item = list.get(i);
153
+//            result.add(item);
154
+//            if(item.get("type").toString().equals("3")){
155
+//                result.addAll(getModuleDefaultPriv(item.get("name").toString()));
156
+//
157
+//            }
158
+//        }
159
+//        return result;
160
+//    }
160 161
 
161 162
 
162 163
     /**
@@ -164,14 +165,14 @@ public class UserService {
164 165
      * @param moduleName
165 166
      * @return
166 167
      */
167
-    private List<Map> getModuleDefaultPriv(String moduleName){
168
-        String strSQL = "SELECT z.*,b.id m_id\n" +
169
-                "FROM k_module_priv t,k_module_priv_detail z,k_module b\n" +
170
-                "WHERE t.m_code= '{0}' AND t.code = t.m_code\n" +
171
-                "	and z.code = t.code and b.code = t.m_code";
172
-        List<Map> list = queryService.select(strSQL,moduleName);
173
-        return listPriv(list);
174
-    }
168
+//    private List<Map> getModuleDefaultPriv(String moduleName){
169
+//        String strSQL = "SELECT z.*,b.id m_id\n" +
170
+//                "FROM k_module_priv t,k_module_priv_detail z,k_module b\n" +
171
+//                "WHERE t.m_code= '{0}' AND t.code = t.m_code\n" +
172
+//                "	and z.code = t.code and b.code = t.m_code";
173
+//        List<Map> list = queryService.select(strSQL,moduleName);
174
+//        return listPriv(list);
175
+//    }
175 176
 
176 177
 
177 178
     /**
@@ -200,4 +201,89 @@ public class UserService {
200 201
 
201 202
     }
202 203
 
204
+
205
+    class UserPriv {
206
+        private String roleIds;
207
+
208
+        //已经加载的模块
209
+        private List<String> moduleCache = new ArrayList<>() ;
210
+
211
+        private List<Map> privs = new ArrayList<>();
212
+
213
+        public  UserPriv(String roleIds ){
214
+            this.roleIds = roleIds;
215
+        }
216
+
217
+        public List<Map> getPrivs(){
218
+            String strSQL = "select a.*\n" +
219
+                            "from k_role_priv t,k_module_priv z,k_module_priv_detail a\n" +
220
+                            "where t.r_id in({0})\n" +
221
+                            "      and t.p_code = z.code and a.code = z.code\n" +
222
+                            "      and a.type = 3";
223
+
224
+            List<Map> list = queryService.select(strSQL,roleIds);
225
+            load(list);
226
+            return privs;
227
+        }
228
+
229
+        //加载模块默认权限
230
+        private void loadModule(String module) {
231
+            if(moduleCache.contains(module))
232
+                return;
233
+
234
+            moduleCache.add(module);
235
+
236
+            String strSQL = "select  z.*\n" +
237
+                            "from k_module_priv t,k_module_priv_detail z\n" +
238
+                            "where t.m_code='{0}' and t.code = z.code\n" +
239
+                            "      and t.code = t.m_code";
240
+            List<Map> list = queryService.select(strSQL,module);
241
+            load(list);
242
+        }
243
+
244
+        private void load(List<Map> list){
245
+            for(Map map : list) {
246
+                String type = map.get("type").toString();
247
+                String name = map.get("name").toString();
248
+
249
+                if(type.equals("3")){ //模块信息
250
+                    loadModule(name);
251
+                }
252
+                else if(type.equals("6")) { // appi
253
+                    loadApi(name);
254
+                }
255
+                else if(type.equals("7")) { // api group
256
+                    loadApiGroup(name);
257
+                }
258
+            }
259
+        }
260
+
261
+        /**
262
+         * 加载api分组
263
+         * @param groupId
264
+         */
265
+        private void loadApiGroup(String groupId) {
266
+            String strSQL = "select code,name from k_api where  g_id={0}";
267
+            List<Map> list = queryService.select(strSQL,groupId);
268
+            privs = ListUtil.merge(privs,list);
269
+
270
+            // 下级分类
271
+            strSQL = "select id from k_api_group where  p_id={0}";
272
+            list = queryService.select(strSQL,groupId);
273
+            for(Map map : list) {
274
+                loadApiGroup(map.get("id").toString());
275
+            }
276
+        }
277
+
278
+
279
+        //加载API
280
+        private void loadApi(String apiId) {
281
+            String strSQL = "select code,method from k_api where id={0}";
282
+            List<Map> list = queryService.select(strSQL,apiId);
283
+
284
+            privs = ListUtil.merge(privs,list);
285
+        }
286
+
287
+    }
288
+
203 289
 }

+ 8 - 0
src/main/java/com/kingkong/bljs/util/ListUtil.java

@@ -76,4 +76,12 @@ public class ListUtil {
76 76
         return null;
77 77
     }
78 78
 
79
+
80
+    public static List<Map> merge(List<Map> list,List<Map> list2) {
81
+        for(Map item: list2) {
82
+            list.add(item);
83
+        }
84
+        return list;
85
+    }
86
+
79 87
 }