14
14
15
15
package apijson .demo ;
16
16
17
- import java .util .ArrayList ;
18
- import java .util .Arrays ;
19
- import java .util .Collection ;
20
- import java .util .List ;
17
+ import java .util .*;
21
18
22
19
import javax .servlet .http .HttpSession ;
23
20
24
21
import apijson .orm .script .JavaScriptExecutor ;
22
+ import com .alibaba .fastjson .JSON ;
25
23
import com .alibaba .fastjson .JSONArray ;
26
24
import com .alibaba .fastjson .JSONObject ;
27
25
@@ -49,29 +47,30 @@ public class DemoFunctionParser extends APIJSONFunctionParser {
49
47
public DemoFunctionParser () {
50
48
this (null , null , 0 , null , null );
51
49
}
50
+
52
51
public DemoFunctionParser (RequestMethod method , String tag , int version , JSONObject request , HttpSession session ) {
53
52
super (method , tag , version , request , session );
54
53
}
55
-
54
+
56
55
public Visitor <Long > getCurrentUser (@ NotNull JSONObject curObj ) {
57
56
return DemoVerifier .getVisitor (getSession ());
58
57
}
59
-
58
+
60
59
public Long getCurrentUserId (@ NotNull JSONObject curObj ) {
61
60
return DemoVerifier .getVisitorId (getSession ());
62
61
}
63
-
62
+
64
63
public List <Long > getCurrentUserIdAsList (@ NotNull JSONObject curObj ) {
65
64
List <Long > list = new ArrayList <>(1 );
66
65
list .add (DemoVerifier .getVisitorId (getSession ()));
67
66
return list ;
68
67
}
69
-
68
+
70
69
public List <Long > getCurrentContactIdList (@ NotNull JSONObject curObj ) {
71
70
Visitor <Long > user = getCurrentUser (curObj );
72
71
return user == null ? null : user .getContactIdList ();
73
72
}
74
-
73
+
75
74
76
75
/**
77
76
* @param curObj
@@ -80,15 +79,15 @@ public List<Long> getCurrentContactIdList(@NotNull JSONObject curObj) {
80
79
* @throws Exception
81
80
*/
82
81
public void verifyIdList (@ NotNull JSONObject curObj , @ NotNull String idList ) throws Exception {
83
- Object obj = curObj . get (idList );
82
+ Object obj = getArgVal (idList );
84
83
if (obj == null ) {
85
84
return ;
86
85
}
87
-
86
+
88
87
if (obj instanceof Collection == false ) {
89
88
throw new IllegalArgumentException (idList + " 不符合 Array 数组类型! 结构必须是 [] !" );
90
89
}
91
-
90
+
92
91
Collection <?> collection = (Collection <?>) obj ;
93
92
if (collection != null ) {
94
93
int i = -1 ;
@@ -101,6 +100,12 @@ public void verifyIdList(@NotNull JSONObject curObj, @NotNull String idList) thr
101
100
}
102
101
}
103
102
103
+ @ Override
104
+ public boolean isContain (JSONObject curObj , String array , String value ) {
105
+ List <String > list = apijson .JSON .parseArray (JSON .toJSONString (getArgVal (array )), String .class );
106
+ Object val = getArgVal (value );
107
+ return list != null && list .contains (val == null ? null : String .valueOf (val ));
108
+ }
104
109
105
110
/**
106
111
* @param curObj
@@ -109,15 +114,15 @@ public void verifyIdList(@NotNull JSONObject curObj, @NotNull String idList) thr
109
114
* @throws Exception
110
115
*/
111
116
public void verifyURLList (@ NotNull JSONObject curObj , @ NotNull String urlList ) throws Exception {
112
- Object obj = curObj . get (urlList );
117
+ Object obj = getArgVal (urlList );
113
118
if (obj == null ) {
114
119
return ;
115
120
}
116
-
121
+
117
122
if (obj instanceof Collection == false ) {
118
123
throw new IllegalArgumentException (urlList + " 不符合 Array 数组类型! 结构必须是 [] !" );
119
124
}
120
-
125
+
121
126
Collection <?> collection = (Collection <?>) obj ;
122
127
if (collection != null ) {
123
128
int i = -1 ;
@@ -138,8 +143,8 @@ public void verifyURLList(@NotNull JSONObject curObj, @NotNull String urlList) t
138
143
* @throws Exception
139
144
*/
140
145
public int deleteCommentOfMoment (@ NotNull JSONObject curObj , @ NotNull String momentId ) throws Exception {
141
- long mid = curObj . getLongValue (momentId );
142
- if (mid <= 0 || curObj .getIntValue (JSONResponse .KEY_COUNT ) <= 0 ) {
146
+ Long mid = getArgVal (momentId );
147
+ if (mid == null || mid <= 0 || curObj .getIntValue (JSONResponse .KEY_COUNT ) <= 0 ) {
143
148
return 0 ;
144
149
}
145
150
@@ -165,8 +170,8 @@ public int deleteCommentOfMoment(@NotNull JSONObject curObj, @NotNull String mom
165
170
* @return
166
171
*/
167
172
public int deleteChildComment (@ NotNull JSONObject curObj , @ NotNull String toId ) throws Exception {
168
- long tid = curObj . getLongValue (toId );
169
- if (tid <= 0 || curObj .getIntValue (JSONResponse .KEY_COUNT ) <= 0 ) {
173
+ Long tid = getArgVal (toId );
174
+ if (tid == null || tid <= 0 || curObj .getIntValue (JSONResponse .KEY_COUNT ) <= 0 ) {
170
175
return 0 ;
171
176
}
172
177
@@ -243,9 +248,9 @@ public JSONArray getIdList(@NotNull JSONObject curObj) {
243
248
* @throws Exception
244
249
*/
245
250
public Object verifyAccess (@ NotNull JSONObject curObj ) throws Exception {
246
- long userId = curObj . getLongValue (JSONRequest .KEY_USER_ID );
247
- String role = curObj . getString (JSONRequest .KEY_ROLE );
248
- if (AbstractVerifier .OWNER .equals (role ) && userId != ( Long ) DemoVerifier .getVisitorId (getSession ())) {
251
+ String role = getArgVal (JSONRequest .KEY_ROLE );
252
+ Long userId = getArgVal (JSONRequest .KEY_USER_ID );
253
+ if (AbstractVerifier .OWNER .equals (role ) && ! Objects . equals ( userId , DemoVerifier .getVisitorId (getSession () ))) {
249
254
throw new IllegalAccessException ("登录用户与角色OWNER不匹配!" );
250
255
}
251
256
return null ;
0 commit comments