Skip to content

Commit 096c902

Browse files
committed
Server:优化代码
1 parent 9c907ae commit 096c902

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/server/DemoVerifier.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import javax.servlet.http.HttpSession;
1818
import javax.validation.constraints.NotNull;
1919

20+
import com.alibaba.fastjson.JSONObject;
21+
2022
import apijson.demo.server.model.Comment;
2123
import apijson.demo.server.model.Login;
2224
import apijson.demo.server.model.Moment;
@@ -32,16 +34,10 @@
3234
/**权限验证器
3335
* @author Lemon
3436
*/
35-
public class DemoVerifier extends AbstractVerifier {
37+
public class DemoVerifier extends AbstractVerifier<Long> {
3638
private static final String TAG = "DemoVerifier";
3739

3840

39-
public static final String KEY_PASSWORD = "password";
40-
public static final String KEY_LOGIN_PASSWORD = "loginPassword";
41-
public static final String KEY_PAY_PASSWORD = "payPassword";
42-
public static final String KEY_OLD_PASSWORD = "oldPassword";
43-
44-
4541
// <TableName, <METHOD, allowRoles>>
4642
// <User, <GET, [OWNER, ADMIN]>>
4743
static { //注册权限
@@ -100,8 +96,8 @@ public static long getVisitorId(HttpSession session) {
10096
}
10197
Long id = (Long) session.getAttribute(Controller.USER_ID);
10298
if (id == null) {
103-
Visitor v = getVisitor(session);
104-
id = v == null ? 0 : value((Long) v.getId());
99+
Visitor<Long> v = getVisitor(session);
100+
id = v == null ? 0 : value(v.getId());
105101
session.setAttribute(Controller.USER_ID, id);
106102
}
107103
return value(id);
@@ -110,13 +106,22 @@ public static long getVisitorId(HttpSession session) {
110106
* @param session
111107
* @return
112108
*/
113-
public static Visitor getVisitor(HttpSession session) {
114-
return session == null ? null : (Visitor) session.getAttribute(Controller.USER_);
109+
@SuppressWarnings("unchecked")
110+
public static Visitor<Long> getVisitor(HttpSession session) {
111+
return session == null ? null : (Visitor<Long>) session.getAttribute(Controller.USER_);
115112
}
116113

117114
public static long value(Long v) {
118115
return v == null ? 0 : v;
119116
}
120117

118+
/**删除请求里的权限信息
119+
* @param requestObject
120+
* @return
121+
*/
122+
@Deprecated
123+
public JSONObject removeAccessInfo(JSONObject requestObject) {
124+
return requestObject;
125+
}
121126

122127
}

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractVerifier.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,4 @@ public void verifyRepeat(String table, String key, Object value, long exceptId)
360360
}
361361

362362

363-
364-
/**删除请求里的权限信息
365-
* @param requestObject
366-
* @return
367-
*/
368-
public JSONObject removeAccessInfo(JSONObject requestObject) {
369-
return requestObject;
370-
}
371-
372-
373363
}

0 commit comments

Comments
 (0)