@@ -136,7 +136,7 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>,
136
136
ROLE_MAP .put (UNKNOWN , new Entry <String , Object >());
137
137
ROLE_MAP .put (LOGIN , new Entry <String , Object >("userId>" , 0 ));
138
138
ROLE_MAP .put (CONTACT , new Entry <String , Object >("userId{}" , "contactIdList" ));
139
- ROLE_MAP .put (CIRCLE , new Entry <String , Object >("userId-()" , "verifyCircle()" )); // "userId{}", "circleIdList")); // 还是 {"userId":"currentUserId", "userId{}": "contactIdList", "@combine": "userId,userId{}" } ?
139
+ ROLE_MAP .put (CIRCLE , new Entry <String , Object >("userId-()" , "verifyCircle()" )); // "userId{}", "circleIdList")); // 还是 {"userId":"currentUserId", "userId{}": "contactIdList", "@combine": "userId,userId{}" } ?
140
140
ROLE_MAP .put (OWNER , new Entry <String , Object >("userId" , "userId" ));
141
141
ROLE_MAP .put (ADMIN , new Entry <String , Object >("userId-()" , "verifyAdmin()" ));
142
142
@@ -183,8 +183,17 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>,
183
183
REQUEST_MAP = new HashMap <>(ACCESS_MAP .size ()*7 ); // 单个与批量增删改
184
184
185
185
COMPILE_MAP = new HashMap <String , Pattern >();
186
+
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
+
186
194
}
187
195
196
+
188
197
/**获取权限Map,每种操作都只允许对应的角色
189
198
* @param access
190
199
* @return
@@ -272,7 +281,7 @@ public boolean verifyAccess(SQLConfig config) throws Exception {
272
281
if (role == null ) {
273
282
role = UNKNOWN ;
274
283
}
275
- else {
284
+ else {
276
285
if (ROLE_MAP .containsKey (role ) == false ) {
277
286
Set <String > NAMES = ROLE_MAP .keySet ();
278
287
throw new IllegalArgumentException ("角色 " + role + " 不存在!" +
@@ -302,8 +311,8 @@ public void verifyRole(SQLConfig config, String table, RequestMethod method, Str
302
311
* @param method
303
312
* @param role
304
313
* @return
305
- * @throws Exception
306
- * @see {@link apijson.JSONObject#KEY_ROLE}
314
+ * @throws Exception
315
+ * @see {@link apijson.JSONObject#KEY_ROLE}
307
316
*/
308
317
public void verifyAllowRole (SQLConfig config , String table , RequestMethod method , String role ) throws Exception {
309
318
Log .d (TAG , "verifyAllowRole table = " + table + "; method = " + method + "; role = " + role );
@@ -333,8 +342,8 @@ public void verifyAllowRole(SQLConfig config, String table, RequestMethod method
333
342
* @param method
334
343
* @param role
335
344
* @return
336
- * @throws Exception
337
- * @see {@link apijson.JSONObject#KEY_ROLE}
345
+ * @throws Exception
346
+ * @see {@link apijson.JSONObject#KEY_ROLE}
338
347
*/
339
348
public void verifyUseRole (SQLConfig config , String table , RequestMethod method , String role ) throws Exception {
340
349
Log .d (TAG , "verifyUseRole table = " + table + "; method = " + method + "; role = " + role );
@@ -367,7 +376,7 @@ public void verifyUseRole(SQLConfig config, String table, RequestMethod method,
367
376
368
377
//key!{}:[] 或 其它没有明确id的条件 等 可以和key{}:list组合。类型错误就报错
369
378
requestId = config .getWhere (visitorIdKey , true );//JSON里数值不能保证是Long,可能是Integer
370
- @ SuppressWarnings ("unchecked" )
379
+ @ SuppressWarnings ("unchecked" )
371
380
Collection <Object > requestIdArray = (Collection <Object >) config .getWhere (visitorIdKey + "{}" , true );//不能是 &{}, |{} 不要传,直接{}
372
381
if (requestId != null ) {
373
382
if (requestIdArray == null ) {
@@ -378,7 +387,7 @@ public void verifyUseRole(SQLConfig config, String table, RequestMethod method,
378
387
379
388
if (requestIdArray == null ) {//可能是@得到 || requestIdArray.isEmpty()) {//请求未声明key:id或key{}:[...]条件,自动补全
380
389
config .putWhere (visitorIdKey +"{}" , JSON .parseArray (list ), true ); //key{}:[]有效,SQLConfig里throw NotExistException
381
- }
390
+ }
382
391
else {//请求已声明key:id或key{}:[]条件,直接验证
383
392
for (Object id : requestIdArray ) {
384
393
if (id == null ) {
@@ -463,7 +472,7 @@ public void verifyLogin() throws Exception {
463
472
if (((Number ) visitorId ).longValue () <= 0 ) {
464
473
throw new NotLoggedInException ("未登录或登录过期,请登录后再操作!" );
465
474
}
466
- }
475
+ }
467
476
else if (visitorId instanceof String ) {
468
477
if (StringUtil .isEmpty (visitorId , true )) {
469
478
throw new NotLoggedInException ("未登录或登录过期,请登录后再操作!" );
@@ -925,7 +934,7 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m
925
934
// 判断必要字段是否都有<<<<<<<<<<<<<<<<<<<
926
935
String [] musts = StringUtil .split (must );
927
936
Set <String > mustSet = new HashSet <String >();
928
-
937
+
929
938
if (musts != null && musts .length > 0 ) {
930
939
for (String s : musts ) {
931
940
if (real .get (s ) == null && real .get (s +"@" ) == null ) { // 可能传null进来,这里还会通过 real.containsKey(s) == false) {
0 commit comments