@@ -103,7 +103,7 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>,
103
103
104
104
// 共享 STRUCTURE_MAP 则不能 remove 等做任何变更,否则在并发情况下可能会出错,加锁效率又低,所以这里改为忽略对应的 key
105
105
public static Map <String , Entry <String , Object >> ROLE_MAP ;
106
-
106
+
107
107
public static List <String > OPERATION_KEY_LIST ;
108
108
109
109
// <TableName, <METHOD, allowRoles>>
@@ -129,7 +129,7 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>,
129
129
ROLE_MAP .put (CIRCLE , new Entry <String , Object >("userId-()" , "verifyCircle()" )); // "userId{}", "circleIdList")); // 还是 {"userId":"currentUserId", "userId{}": "contactIdList", "@combine": "userId,userId{}" } ?
130
130
ROLE_MAP .put (OWNER , new Entry <String , Object >("userId" , "userId" ));
131
131
ROLE_MAP .put (ADMIN , new Entry <String , Object >("userId-()" , "verifyAdmin()" ));
132
-
132
+
133
133
OPERATION_KEY_LIST = new ArrayList <>();
134
134
OPERATION_KEY_LIST .add (TYPE .name ());
135
135
OPERATION_KEY_LIST .add (VERIFY .name ());
@@ -204,7 +204,7 @@ public String getIdKey(String database, String schema, String datasource, String
204
204
public String getUserIdKey (String database , String schema , String datasource , String table ) {
205
205
return apijson .JSONObject .KEY_USER_ID ;
206
206
}
207
-
207
+
208
208
@ SuppressWarnings ("unchecked" )
209
209
@ Override
210
210
public T newId (RequestMethod method , String database , String schema , String datasource , String table ) {
@@ -247,7 +247,7 @@ public boolean verifyAccess(SQLConfig config) throws Exception {
247
247
if (table == null ) {
248
248
return true ;
249
249
}
250
-
250
+
251
251
String role = config .getRole ();
252
252
if (role == null ) {
253
253
role = UNKNOWN ;
@@ -265,10 +265,10 @@ public boolean verifyAccess(SQLConfig config) throws Exception {
265
265
266
266
RequestMethod method = config .getMethod ();
267
267
verifyRole (config , table , method , role );
268
-
268
+
269
269
return true ;
270
270
}
271
-
271
+
272
272
@ Override
273
273
public void verifyRole (SQLConfig config , String table , RequestMethod method , String role ) throws Exception {
274
274
verifyAllowRole (config , table , method , role ); //验证允许的角色
@@ -289,15 +289,15 @@ public void verifyAllowRole(SQLConfig config, String table, RequestMethod method
289
289
if (table == null ) {
290
290
table = config == null ? null : config .getTable ();
291
291
}
292
-
292
+
293
293
if (table != null ) {
294
294
if (method == null ) {
295
295
method = config == null ? GET : config .getMethod ();
296
296
}
297
297
if (role == null ) {
298
298
role = config == null ? UNKNOWN : config .getRole ();
299
299
}
300
-
300
+
301
301
Map <RequestMethod , String []> map = ACCESS_MAP .get (table );
302
302
303
303
if (map == null || Arrays .asList (map .get (method )).contains (role ) == false ) {
@@ -329,7 +329,7 @@ public void verifyUseRole(SQLConfig config, String table, RequestMethod method,
329
329
if (role == null ) {
330
330
role = config == null ? UNKNOWN : config .getRole ();
331
331
}
332
-
332
+
333
333
Object requestId ;
334
334
switch (role ) {
335
335
case LOGIN ://verifyRole通过就行
@@ -882,11 +882,15 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m
882
882
883
883
// 判断必要字段是否都有<<<<<<<<<<<<<<<<<<<
884
884
String [] musts = StringUtil .split (must );
885
- List <String > mustList = musts == null ? new ArrayList <String >() : Arrays .asList (musts );
886
- for (String s : mustList ) {
887
- if (real .get (s ) == null ) { // 可能传null进来,这里还会通过 real.containsKey(s) == false) {
888
- throw new IllegalArgumentException (method + "请求," + name
889
- + " 里面不能缺少 " + s + " 等[" + must + "]内的任何字段!" );
885
+ Set <String > mustSet = new HashSet <String >();
886
+
887
+ if (musts != null && musts .length > 0 ) {
888
+ for (String s : musts ) {
889
+ if (real .get (s ) == null ) { // 可能传null进来,这里还会通过 real.containsKey(s) == false) {
890
+ throw new IllegalArgumentException (method + "请求," + name + " 里面不能缺少 " + s + " 等[" + must + "]内的任何字段!" );
891
+ }
892
+
893
+ mustSet .add (s );
890
894
}
891
895
}
892
896
//判断必要字段是否都有>>>>>>>>>>>>>>>>>>>
@@ -947,28 +951,61 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m
947
951
Set <String > rkset = real .keySet (); //解析内容并没有改变rkset
948
952
949
953
//解析不允许的字段<<<<<<<<<<<<<<<<<<<
950
- List <String > refuseList = new ArrayList <String >();
951
- if ("!" .equals (refuse )) {//所有非 must,改成 !must 更好
952
- for (String key : rkset ) {//对@key放行,@role,@column,自定义@position等
953
- if (key != null && key .startsWith ("@" ) == false
954
- && mustList .contains (key ) == false && objKeySet .contains (key ) == false ) {
955
- refuseList .add (key );
954
+ String [] refuses = StringUtil .split (refuse );
955
+ Set <String > refuseSet = new HashSet <String >();
956
+
957
+ if (refuses != null && refuses .length > 0 ) {
958
+ Set <String > notRefuseSet = new HashSet <String >();
959
+
960
+ for (String rfs : refuses ) {
961
+ if (rfs == null ) { // StringUtil.isEmpty(rfs, true) {
962
+ continue ;
963
+ }
964
+
965
+ if (rfs .startsWith ("!" )) {
966
+ rfs = rfs .substring (1 );
967
+
968
+ if (notRefuseSet .contains (rfs )) {
969
+ throw new ConflictException (REFUSE .name () + ":value 中出现了重复的 !" + rfs + " !不允许重复,也不允许一个 key 和取反 !key 同时使用!" );
970
+ }
971
+ if (refuseSet .contains (rfs )) {
972
+ throw new ConflictException (REFUSE .name () + ":value 中同时出现了 " + rfs + " 和 !" + rfs + " !不允许重复,也不允许一个 key 和取反 !key 同时使用!" );
973
+ }
974
+
975
+ if (rfs .equals ("" )) { // 所有非 MUST
976
+ for (String key : rkset ) { // 对@key放行,@role,@column,自定义@position等, @key:{ "Table":{} } 不会解析内部
977
+ if (key == null || key .startsWith ("@" ) || notRefuseSet .contains (key ) || mustSet .contains (key ) || objKeySet .contains (key )) {
978
+ continue ;
979
+ }
980
+
981
+ refuseSet .add (key );
982
+ }
983
+ }
984
+ else { // 排除 !key 后再禁传其它的
985
+ notRefuseSet .add (rfs );
986
+ }
987
+ }
988
+ else {
989
+ if (refuseSet .contains (rfs )) {
990
+ throw new ConflictException (REFUSE .name () + ":value 中出现了重复的 " + rfs + " !不允许重复,也不允许一个 key 和取反 !key 同时使用!" );
991
+ }
992
+ if (notRefuseSet .contains (rfs )) {
993
+ throw new ConflictException (REFUSE .name () + ":value 中同时出现了 " + rfs + " 和 !" + rfs + " !不允许重复,也不允许一个 key 和取反 !key 同时使用!" );
994
+ }
995
+
996
+ refuseSet .add (rfs );
956
997
}
957
- }
958
- } else {
959
- String [] refuses = StringUtil .split (refuse );
960
- if (refuses != null && refuses .length > 0 ) {
961
- refuseList .addAll (Arrays .asList (refuses ));
962
998
}
963
999
}
1000
+
964
1001
//解析不允许的字段>>>>>>>>>>>>>>>>>>>
965
1002
966
1003
967
1004
//判断不允许传的key<<<<<<<<<<<<<<<<<<<<<<<<<
968
1005
for (String rk : rkset ) {
969
- if (refuseList .contains (rk )) { //不允许的字段
1006
+ if (refuseSet .contains (rk )) { //不允许的字段
970
1007
throw new IllegalArgumentException (method + "请求," + name
971
- + " 里面不允许传 " + rk + " 等" + StringUtil .getString (refuseList ) + "内的任何字段!" );
1008
+ + " 里面不允许传 " + rk + " 等" + StringUtil .getString (refuseSet ) + "内的任何字段!" );
972
1009
}
973
1010
974
1011
if (rk == null ) { //无效的key
@@ -1391,7 +1428,7 @@ private static void verifyCondition(@NotNull String funChar, @NotNull JSONObject
1391
1428
} finally {
1392
1429
executor .close ();
1393
1430
}
1394
-
1431
+
1395
1432
if (result != null && JSONResponse .isExist (result .getIntValue (JSONResponse .KEY_COUNT )) == false ) {
1396
1433
throw new IllegalArgumentException (rk + ":value 中value不合法!必须匹配 '" + tk + "': '" + tv + "' !" );
1397
1434
}
0 commit comments