Repository navigation
Expand file tree
/
Copy pathVerifier.java
More file actions
executable file
·139 lines (110 loc) · 3.2 KB
/
Copy pathVerifier.java
File metadata and controls
executable file
·139 lines (110 loc) · 3.2 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
This source code is licensed under the Apache License Version 2.0.*/
package apijson.orm;
import java.util.List;
import java.util.Map;
import apijson.*;
/**校验器(权限、请求参数、返回结果等)
* @author Lemon
*/
public interface Verifier<T, M extends Map<String, Object>, L extends List<Object>> { // extends JSONParser<M, L> {
/**验证权限是否通过
* @param config
* @return
* @throws Exception
*/
boolean verifyAccess(SQLConfig<T, M, L> config) throws Exception;
/**校验请求使用的角色,角色不好判断,让访问者发过来角色名,OWNER,CONTACT,ADMIN等
* @param config
* @param table
* @param method
* @param role
* @return
* @throws Exception
* @see {@link apijson.JSONObject#KEY_ROLE}
*/
void verifyRole(SQLConfig<T, M, L> config, String table, RequestMethod method, String role) throws Exception;
/**登录校验
* @throws Exception
*/
void verifyLogin() throws Exception;
/**管理员角色校验
* @throws Exception
*/
void verifyAdmin() throws Exception;
/**验证是否重复
* @param table
* @param key
* @param value
* @throws Exception
*/
void verifyRepeat(String table, String key, Object value) throws Exception;
/**验证是否重复
* @param table
* @param key
* @param value
* @param exceptId 不包含id
* @throws Exception
*/
void verifyRepeat(String table, String key, Object value, long exceptId) throws Exception;
/**验证请求参数的数据和结构
* @param method
* @param name
* @param target
* @param request
* @param maxUpdateCount
* @param globalDatabase
* @param globalSchema
* @param creator
* @return
* @throws Exception
*/
M verifyRequest(RequestMethod method, String name, M target, M request,
int maxUpdateCount, String globalDatabase, String globalSchema, SQLCreator<T, M, L> creator) throws Exception;
/**验证返回结果的数据和结构
* @param method
* @param name
* @param target
* @param response
* @param database
* @param schema
* @param creator
* @param callback
* @return
* @throws Exception
*/
M verifyResponse(
RequestMethod method, String name, M target, M response,
String database, String schema, SQLCreator<T, M, L> creator, OnParseCallback<T, M, L> callback
) throws Exception;
@NotNull
Parser<T, M, L> createParser();
@NotNull
Visitor<T> getVisitor();
Verifier<T, M, L> setVisitor(@NotNull Visitor<T> visitor);
String getVisitorIdKey(SQLConfig<T, M, L> config);
default M createJSONObject() {
return (M) new JSONObject();
}
default L createJSONArray() {
return (L) new JSONArray();
}
default String toJSONString(Object obj) {
return JSON.toJSONString(obj);
}
default Object parseJSON(Object json) {
return JSON.parseJSON(json);
}
default M parseObject(Object json) {
return (M) parseObject(json, JSONObject.class);
}
default <T> T parseObject(Object json, Class<T> clazz) {
return JSON.parseObject(json, clazz);
}
default L parseArray(Object json) {
return (L) parseObject(json, JSONArray.class);
}
default <T> List<T> parseArray(Object json, Class<T> clazz) {
return JSON.parseArray(json, clazz);
}
}