修改在获得用户session方法里面因为使用threadLocal,可能会出现串数据的问题,统一使用getCurrentUserFromRedis和...

修改在获得用户session方法里面因为使用threadLocal,可能会出现串数据的问题,统一使用getCurrentUserFromRedis和 getXSessionFromRedis方法规避风险
parent a574abac
...@@ -15,6 +15,7 @@ import static cn.quantgroup.xyqb.session.XyqbSessionContextHolder.getXSessionFro ...@@ -15,6 +15,7 @@ import static cn.quantgroup.xyqb.session.XyqbSessionContextHolder.getXSessionFro
*/ */
public interface IBaseController { public interface IBaseController {
@Deprecated
default User getCurrentUser() { default User getCurrentUser() {
SessionStruct session = getXSession(); SessionStruct session = getXSession();
if (session == null) { if (session == null) {
...@@ -23,10 +24,19 @@ public interface IBaseController { ...@@ -23,10 +24,19 @@ public interface IBaseController {
return getXSession().getValues().getUser(); return getXSession().getValues().getUser();
} }
@Deprecated
default SessionStruct getSessionStruct() { default SessionStruct getSessionStruct() {
return getXSession(); return getXSession();
} }
default User getCurrentUserFromRedis() {
SessionStruct session = getXSessionFromRedis();
if (session == null) {
return null;
}
return session.getValues().getUser();
}
default SessionStruct getCurrentSessionFromRedis(){ default SessionStruct getCurrentSessionFromRedis(){
return getXSessionFromRedis(); return getXSessionFromRedis();
} }
......
...@@ -47,7 +47,7 @@ public class PlatformAPIController implements IBaseController { ...@@ -47,7 +47,7 @@ public class PlatformAPIController implements IBaseController {
@RequestMapping("/page/next") @RequestMapping("/page/next")
public JsonResult nextPage(String key, String target, @RequestParam(required = false, defaultValue = "") String currentPage) { public JsonResult nextPage(String key, String target, @RequestParam(required = false, defaultValue = "") String currentPage) {
User user = getCurrentUser(); User user = getCurrentUserFromRedis();
if (null == user) { if (null == user) {
return JsonResult.buildErrorStateResult("未找到用户", null); return JsonResult.buildErrorStateResult("未找到用户", null);
} }
......
...@@ -88,7 +88,7 @@ public class UserController implements IBaseController { ...@@ -88,7 +88,7 @@ public class UserController implements IBaseController {
@RequestMapping("/test") @RequestMapping("/test")
public JsonResult test() { public JsonResult test() {
return JsonResult.buildSuccessResult("", getCurrentUser()); return JsonResult.buildSuccessResult("", getCurrentUserFromRedis());
} }
@RequestMapping("/login/fast") @RequestMapping("/login/fast")
...@@ -368,7 +368,7 @@ public class UserController implements IBaseController { ...@@ -368,7 +368,7 @@ public class UserController implements IBaseController {
@RequestMapping("/syncUserInfo") @RequestMapping("/syncUserInfo")
public JsonResult syncUserInfo() { public JsonResult syncUserInfo() {
User user = getCurrentUser(); User user = getCurrentUserFromRedis();
if (null == user) { if (null == user) {
return JsonResult.buildErrorStateResult(null, null); return JsonResult.buildErrorStateResult(null, null);
} }
...@@ -450,7 +450,7 @@ public class UserController implements IBaseController { ...@@ -450,7 +450,7 @@ public class UserController implements IBaseController {
@RequestMapping("/associate_wechat") @RequestMapping("/associate_wechat")
public JsonResult associateWithWechat(String openId) { public JsonResult associateWithWechat(String openId) {
User user = getCurrentUser(); User user = getCurrentUserFromRedis();
Long userId = user.getId(); Long userId = user.getId();
WechatUserInfo userInfo = wechatService.findWechatUserInfoFromDb(openId); WechatUserInfo userInfo = wechatService.findWechatUserInfoFromDb(openId);
LOGGER.info("微信关联openId,user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo); LOGGER.info("微信关联openId,user:[{}],openId:[{}],wechatUserInfo:[{}]",user,openId,userInfo);
......
...@@ -42,7 +42,7 @@ public class UserDetailController implements IBaseController { ...@@ -42,7 +42,7 @@ public class UserDetailController implements IBaseController {
if (!info.isValid()) { if (!info.isValid()) {
return JsonResult.buildErrorStateResult("身份证号码错误", null); return JsonResult.buildErrorStateResult("身份证号码错误", null);
} }
User user = getCurrentUser(); User user = getCurrentUserFromRedis();
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult("系统错误", null); return JsonResult.buildErrorStateResult("系统错误", null);
} }
......
...@@ -49,7 +49,7 @@ public class RequestFilter implements Filter { ...@@ -49,7 +49,7 @@ public class RequestFilter implements Filter {
SessionStruct sessionStruct; SessionStruct sessionStruct;
if (!isMatch(requestPath)) { if (!isMatch(requestPath)) {
//获取session信息,如果没有获取到session信息则返回错误信息 //获取session信息,如果没有获取到session信息则返回错误信息
sessionStruct = XyqbSessionContextHolder.getXSession(); sessionStruct = XyqbSessionContextHolder.getXSessionFromRedis();
if (sessionStruct == null) { if (sessionStruct == null) {
response.setStatus(401); response.setStatus(401);
response.setHeader("Content-Type", "application/json;charset=utf-8"); response.setHeader("Content-Type", "application/json;charset=utf-8");
...@@ -61,7 +61,7 @@ public class RequestFilter implements Filter { ...@@ -61,7 +61,7 @@ public class RequestFilter implements Filter {
try { try {
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
} finally { } finally {
sessionStruct = XyqbSessionContextHolder.getXSession(); sessionStruct = XyqbSessionContextHolder.getXSessionFromRedis();
if (sessionStruct != null) { if (sessionStruct != null) {
try { try {
sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues()); sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment