Skip to content

Commit 1d63078

Browse files
committed
权限:解决删改不支持 String 类型主键
1 parent 83c00c1 commit 1d63078

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,39 +376,48 @@ public void verifyUseRole(SQLConfig config, String table, RequestMethod method,
376376
break;
377377
case CONTACT:
378378
case CIRCLE:
379-
//TODO 做一个缓存contactMap<visitorId, contactArray>,提高[]:{}查询性能, removeAccessInfo时map.remove(visitorId)
380-
//不能在Visitor内null -> [] ! 否则会导致某些查询加上不需要的条件!
379+
// TODO 做一个缓存contactMap<visitorId, contactArray>,提高[]:{}查询性能, removeAccessInfo时map.remove(visitorId)
380+
// 不能在 Visitor内null -> [] ! 否则会导致某些查询加上不需要的条件!
381381
List<Object> list = visitor.getContactIdList() == null
382382
? new ArrayList<Object>() : new ArrayList<Object>(visitor.getContactIdList());
383383
if (CIRCLE.equals(role)) {
384384
list.add(visitorId);
385385
}
386386

387-
//key!{}:[] 或 其它没有明确id的条件 等 可以和key{}:list组合。类型错误就报错
388-
requestId = config.getWhere(visitorIdKey, true);//JSON里数值不能保证是Long,可能是Integer
387+
// key!{}:[] 或 其它没有明确id的条件 等 可以和 key{}:[] 组合。类型错误就报错
388+
requestId = config.getWhere(visitorIdKey, true); // JSON 里数值不能保证是 Long,可能是 Integer
389389
@SuppressWarnings("unchecked")
390-
Collection<Object> requestIdArray = (Collection<Object>) config.getWhere(visitorIdKey + "{}", true);//不能是 &{}, |{} 不要传,直接{}
390+
Collection<Object> requestIdArray = (Collection<Object>) config.getWhere(visitorIdKey + "{}", true); // 不能是 &{}, |{} 不要传,直接 {}
391391
if (requestId != null) {
392392
if (requestIdArray == null) {
393393
requestIdArray = new JSONArray();
394394
}
395395
requestIdArray.add(requestId);
396396
}
397397

398-
if (requestIdArray == null) {//可能是@得到 || requestIdArray.isEmpty()) {//请求未声明key:id或key{}:[...]条件,自动补全
399-
config.putWhere(visitorIdKey+"{}", JSON.parseArray(list), true); //key{}:[]有效,SQLConfig里throw NotExistException
398+
if (requestIdArray == null) { // 可能是 @ 得到 || requestIdArray.isEmpty()) { // 请求未声明 key:id 或 key{}:[...] 条件,自动补全
399+
config.putWhere(visitorIdKey+"{}", JSON.parseArray(list), true); // key{}:[] 有效,SQLConfig 里 throw NotExistException
400400
}
401-
else {//请求已声明key:id或key{}:[]条件,直接验证
401+
else { // 请求已声明 key:id 或 key{}:[] 条件,直接验证
402402
for (Object id : requestIdArray) {
403403
if (id == null) {
404404
continue;
405405
}
406-
if (id instanceof Number == false) {//不能准确地判断Long,可能是Integer
407-
throw new UnsupportedDataTypeException(table + ".id类型错误,id类型必须是Long!");
406+
407+
if (id instanceof Number) { // 不能准确地判断 Long,可能是 Integer
408+
if (((Number) id).longValue() <= 0 || list.contains(Long.valueOf("" + id)) == false) { // Integer等转为 Long 才能正确判断,强转崩溃
409+
throw new IllegalAccessException(visitorIdKey + " = " + id + " 的 " + table
410+
+ " 不允许 " + role + " 用户的 " + method.name() + " 请求!");
411+
}
412+
}
413+
else if (id instanceof String) {
414+
if (StringUtil.isEmpty(id) || list.contains(id) == false) {
415+
throw new IllegalAccessException(visitorIdKey + " = " + id + " 的 " + table
416+
+ " 不允许 " + role + " 用户的 " + method.name() + " 请求!");
417+
}
408418
}
409-
if (list.contains(Long.valueOf("" + id)) == false) {//Integer等转为Long才能正确判断。强转崩溃
410-
throw new IllegalAccessException(visitorIdKey + " = " + id + " 的 " + table
411-
+ " 不允许 " + role + " 用户的 " + method.name() + " 请求!");
419+
else {
420+
throw new UnsupportedDataTypeException(table + ".id 类型错误,类型必须是 Long/String!");
412421
}
413422
}
414423
}

0 commit comments

Comments
 (0)