Skip to content

Commit 6d18f58

Browse files
authored
整理代码
1 parent ff40a5d commit 6d18f58

File tree

1 file changed

+95
-102
lines changed

1 file changed

+95
-102
lines changed

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

Lines changed: 95 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>,
7575
/**为 PUT, DELETE 强制要求必须有 id/id{} 条件
7676
*/
7777
public static boolean IS_UPDATE_MUST_HAVE_ID_CONDITION = true;
78-
/**开启校验请求角色权限
79-
*/
80-
public static boolean ENABLE_VERIFY_ROLE = true;
81-
/**开启校验请求传参内容
82-
*/
83-
public static boolean ENABLE_VERIFY_CONTENT = true;
84-
85-
/**未登录,不明身份的用户
78+
/**开启校验请求角色权限
79+
*/
80+
public static boolean ENABLE_VERIFY_ROLE = true;
81+
/**开启校验请求传参内容
82+
*/
83+
public static boolean ENABLE_VERIFY_CONTENT = true;
84+
85+
/**未登录,不明身份的用户
8686
*/
8787
public static final String UNKNOWN = "UNKNOWN";
8888

@@ -163,14 +163,14 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>,
163163

164164
if (Log.DEBUG) {
165165
SYSTEM_ACCESS_MAP.put(Table.class.getSimpleName(), getAccessMap(Table.class.getAnnotation(MethodAccess.class)));
166-
SYSTEM_ACCESS_MAP.put(Column.class.getSimpleName(), getAccessMap(Column.class.getAnnotation(MethodAccess.class)));
166+
SYSTEM_ACCESS_MAP.put(Column.class.getSimpleName(), getAccessMap(Column.class.getAnnotation(MethodAccess.class)));
167167
SYSTEM_ACCESS_MAP.put(PgAttribute.class.getSimpleName(), getAccessMap(PgAttribute.class.getAnnotation(MethodAccess.class)));
168-
SYSTEM_ACCESS_MAP.put(PgClass.class.getSimpleName(), getAccessMap(PgClass.class.getAnnotation(MethodAccess.class)));
169-
SYSTEM_ACCESS_MAP.put(AllTable.class.getSimpleName(), getAccessMap(AllTable.class.getAnnotation(MethodAccess.class)));
170-
SYSTEM_ACCESS_MAP.put(AllTableComment.class.getSimpleName(), getAccessMap(AllTableComment.class.getAnnotation(MethodAccess.class)));
171-
SYSTEM_ACCESS_MAP.put(AllColumn.class.getSimpleName(), getAccessMap(AllColumn.class.getAnnotation(MethodAccess.class)));
172-
SYSTEM_ACCESS_MAP.put(AllColumnComment.class.getSimpleName(), getAccessMap(AllColumnComment.class.getAnnotation(MethodAccess.class)));
173-
SYSTEM_ACCESS_MAP.put(SysTable.class.getSimpleName(), getAccessMap(SysTable.class.getAnnotation(MethodAccess.class)));
168+
SYSTEM_ACCESS_MAP.put(PgClass.class.getSimpleName(), getAccessMap(PgClass.class.getAnnotation(MethodAccess.class)));
169+
SYSTEM_ACCESS_MAP.put(AllTable.class.getSimpleName(), getAccessMap(AllTable.class.getAnnotation(MethodAccess.class)));
170+
SYSTEM_ACCESS_MAP.put(AllTableComment.class.getSimpleName(), getAccessMap(AllTableComment.class.getAnnotation(MethodAccess.class)));
171+
SYSTEM_ACCESS_MAP.put(AllColumn.class.getSimpleName(), getAccessMap(AllColumn.class.getAnnotation(MethodAccess.class)));
172+
SYSTEM_ACCESS_MAP.put(AllColumnComment.class.getSimpleName(), getAccessMap(AllColumnComment.class.getAnnotation(MethodAccess.class)));
173+
SYSTEM_ACCESS_MAP.put(SysTable.class.getSimpleName(), getAccessMap(SysTable.class.getAnnotation(MethodAccess.class)));
174174
SYSTEM_ACCESS_MAP.put(SysColumn.class.getSimpleName(), getAccessMap(SysColumn.class.getAnnotation(MethodAccess.class)));
175175
SYSTEM_ACCESS_MAP.put(ExtendedProperty.class.getSimpleName(), getAccessMap(ExtendedProperty.class.getAnnotation(MethodAccess.class)));
176176

@@ -184,13 +184,6 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>,
184184

185185
COMPILE_MAP = new HashMap<String, Pattern>();
186186

187-
COMPILE_MAP.put("PHONE",Pattern.compile("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$"));
188-
COMPILE_MAP.put("QQ",Pattern.compile("[1-9][0-9]{4,}"));
189-
COMPILE_MAP.put("EMAIL",Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"));
190-
COMPILE_MAP.put("IDCARD",Pattern.compile("(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"));
191-
COMPILE_MAP.put("TEL",Pattern.compile("(^\\(\\d{3,4}-)|\\d{3,4}-\\)?\\d{7,8}$"));
192-
COMPILE_MAP.put("IDCARD",Pattern.compile("(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"));
193-
194187
}
195188

196189

@@ -267,10 +260,10 @@ public AbstractVerifier<T> setVisitor(Visitor<T> visitor) {
267260
*/
268261
@Override
269262
public boolean verifyAccess(SQLConfig config) throws Exception {
270-
if (ENABLE_VERIFY_ROLE == false) {
271-
throw new UnsupportedOperationException("AbstractVerifier.ENABLE_VERIFY_ROLE == false " +
263+
if (ENABLE_VERIFY_ROLE == false) {
264+
throw new UnsupportedOperationException("AbstractVerifier.ENABLE_VERIFY_ROLE == false " +
272265
"时不支持校验角色权限!如需支持则设置 AbstractVerifier.ENABLE_VERIFY_ROLE = true !");
273-
}
266+
}
274267

275268
String table = config == null ? null : config.getTable();
276269
if (table == null) {
@@ -539,17 +532,17 @@ public void verifyRepeat(String table, String key, Object value, long exceptId)
539532

540533

541534
/**从request提取target指定的内容
542-
* @param method
543-
* @param name
544-
* @param target
545-
* @param request
546-
* @param maxUpdateCount
547-
* @param database
548-
* @param schema
549-
* @param creator
550-
* @return
551-
* @throws Exception
552-
*/
535+
* @param method
536+
* @param name
537+
* @param target
538+
* @param request
539+
* @param maxUpdateCount
540+
* @param database
541+
* @param schema
542+
* @param creator
543+
* @return
544+
* @throws Exception
545+
*/
553546
@Override
554547
public JSONObject verifyRequest(@NotNull final RequestMethod method, final String name
555548
, final JSONObject target, final JSONObject request, final int maxUpdateCount
@@ -588,19 +581,19 @@ public static JSONObject verifyRequest(@NotNull final RequestMethod method, fina
588581
}
589582

590583
/**从request提取target指定的内容
591-
* @param method
592-
* @param name
593-
* @param target
594-
* @param request
595-
* @param maxUpdateCount
596-
* @param database
597-
* @param schema
598-
* @param idCallback
599-
* @param creator
600-
* @return
601-
* @param <T>
602-
* @throws Exception
603-
*/
584+
* @param method
585+
* @param name
586+
* @param target
587+
* @param request
588+
* @param maxUpdateCount
589+
* @param database
590+
* @param schema
591+
* @param idCallback
592+
* @param creator
593+
* @return
594+
* @param <T>
595+
* @throws Exception
596+
*/
604597
public static <T extends Object> JSONObject verifyRequest(@NotNull final RequestMethod method
605598
, final String name, final JSONObject target, final JSONObject request
606599
, final int maxUpdateCount, final String database, final String schema
@@ -609,28 +602,28 @@ public static <T extends Object> JSONObject verifyRequest(@NotNull final Request
609602
, null, idCallback, creator);
610603
}
611604
/**从request提取target指定的内容
612-
* @param method
613-
* @param name
614-
* @param target
615-
* @param request
616-
* @param maxUpdateCount
617-
* @param database
618-
* @param schema
619-
* @param datasource
620-
* @param idCallback
621-
* @param creator
622-
* @return
623-
* @param <T>
624-
* @throws Exception
625-
*/
605+
* @param method
606+
* @param name
607+
* @param target
608+
* @param request
609+
* @param maxUpdateCount
610+
* @param database
611+
* @param schema
612+
* @param datasource
613+
* @param idCallback
614+
* @param creator
615+
* @return
616+
* @param <T>
617+
* @throws Exception
618+
*/
626619
public static <T extends Object> JSONObject verifyRequest(@NotNull final RequestMethod method
627620
, final String name, final JSONObject target, final JSONObject request
628621
, final int maxUpdateCount, final String database, final String schema, final String datasource
629622
, final IdCallback<T> idCallback, final SQLCreator creator) throws Exception {
630-
if (ENABLE_VERIFY_CONTENT == false) {
631-
throw new UnsupportedOperationException("AbstractVerifier.ENABLE_VERIFY_CONTENT == false" +
623+
if (ENABLE_VERIFY_CONTENT == false) {
624+
throw new UnsupportedOperationException("AbstractVerifier.ENABLE_VERIFY_CONTENT == false" +
632625
" 时不支持校验请求传参内容!如需支持则设置 AbstractVerifier.ENABLE_VERIFY_CONTENT = true !");
633-
}
626+
}
634627

635628
Log.i(TAG, "verifyRequest method = " + method + "; name = " + name
636629
+ "; target = \n" + JSON.toJSONString(target)
@@ -784,17 +777,17 @@ else if (o instanceof String) {
784777

785778

786779
/**校验并将response转换为指定的内容和结构
787-
* @param method
788-
* @param name
789-
* @param target
790-
* @param response
791-
* @param database
792-
* @param schema
793-
* @param creator
794-
* @param callback
795-
* @return
796-
* @throws Exception
797-
*/
780+
* @param method
781+
* @param name
782+
* @param target
783+
* @param response
784+
* @param database
785+
* @param schema
786+
* @param creator
787+
* @param callback
788+
* @return
789+
* @throws Exception
790+
*/
798791
@Override
799792
public JSONObject verifyResponse(@NotNull final RequestMethod method, final String name
800793
, final JSONObject target, final JSONObject response, final String database, final String schema
@@ -803,33 +796,33 @@ public JSONObject verifyResponse(@NotNull final RequestMethod method, final Stri
803796
}
804797

805798
/**校验并将response转换为指定的内容和结构
806-
* @param method
807-
* @param name
808-
* @param target
809-
* @param response
810-
* @param creator
811-
* @param callback
812-
* @return
813-
* @throws Exception
814-
*/
799+
* @param method
800+
* @param name
801+
* @param target
802+
* @param response
803+
* @param creator
804+
* @param callback
805+
* @return
806+
* @throws Exception
807+
*/
815808
public static JSONObject verifyResponse(@NotNull final RequestMethod method, final String name
816809
, final JSONObject target, final JSONObject response, SQLCreator creator, OnParseCallback callback) throws Exception {
817810
return verifyResponse(method, name, target, response, null, null, null, creator, callback);
818811
}
819812
/**校验并将response转换为指定的内容和结构
820-
* @param method
821-
* @param name
822-
* @param target
823-
* @param response
824-
* @param database
825-
* @param schema
826-
* @param idKeyCallback
827-
* @param creator
828-
* @param callback
829-
* @return
830-
* @param <T>
831-
* @throws Exception
832-
*/
813+
* @param method
814+
* @param name
815+
* @param target
816+
* @param response
817+
* @param database
818+
* @param schema
819+
* @param idKeyCallback
820+
* @param creator
821+
* @param callback
822+
* @return
823+
* @param <T>
824+
* @throws Exception
825+
*/
833826
public static <T extends Object> JSONObject verifyResponse(@NotNull final RequestMethod method, final String name
834827
, final JSONObject target, final JSONObject response, final String database, final String schema
835828
, final IdCallback<T> idKeyCallback, SQLCreator creator, OnParseCallback callback) throws Exception {
@@ -1199,12 +1192,12 @@ private static JSONObject operate(Operation opt, JSONObject targetChild
11991192

12001193
Set<Map.Entry<String, Object>> set = new LinkedHashSet<>(targetChild.entrySet());
12011194
for (Map.Entry<String, Object> e : set) {
1202-
String tk = e == null ? null : e.getKey();
1195+
String tk = e == null ? null : e.getKey();
12031196
if (tk == null || OPERATION_KEY_LIST.contains(tk)) {
12041197
continue;
12051198
}
12061199

1207-
Object tv = e.getValue();
1200+
Object tv = e.getValue();
12081201

12091202
if (opt == TYPE) {
12101203
verifyType(tk, tv, real);
@@ -1576,7 +1569,7 @@ private static void verifyCondition(@NotNull String funChar, @NotNull JSONObject
15761569
config.setTest(true);
15771570
// config.setTable(Test.class.getSimpleName());
15781571
// config.setColumn(rv + logic.getChar() + funChar)
1579-
// 字符串可能 SQL 注入,目前的解决方式是加 TYPE 校验类型或者干脆不用 sqlVerify,而是通过远程函数来校验
1572+
// 字符串可能 SQL 注入,目前的解决方式是加 TYPE 校验类型或者干脆不用 sqlVerify,而是通过远程函数来校验
15801573
config.putWhere(rv + logic.getChar() + funChar, tv, false);
15811574
config.setCount(1);
15821575

0 commit comments

Comments
 (0)