From 5203081b68e3a8dc139d1807b2f8774e4a00a82a Mon Sep 17 00:00:00 2001 From: ludc <ludc@vci-tech.com> Date: 星期四, 16 一月 2025 11:11:59 +0800 Subject: [PATCH] 退出登录接口增加清除session、jwttoken等缓存信息 --- Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java | 21 ++++++++++++++++----- 1 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java index 6f6112f..68ef18a 100644 --- a/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java +++ b/Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java @@ -4,9 +4,11 @@ import com.vci.starter.web.annotation.controller.VciUnCheckRight; import com.vci.starter.web.autoconfigure.SpringMVCConfig; import com.vci.starter.web.constant.TokenKeyConstant; +import com.vci.starter.web.constant.VConstant; import com.vci.starter.web.enumpck.ResultCodeEnum; import com.vci.starter.web.pagemodel.BaseResult; import com.vci.starter.web.pagemodel.SessionInfo; +import com.vci.starter.web.redis.RedisService; import com.vci.starter.web.util.ApplicationContextProvider; import com.vci.starter.web.util.LangBaseUtil; import com.vci.starter.web.util.VciBaseUtil; @@ -15,15 +17,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; -import javax.annotation.Resource; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -56,6 +54,9 @@ @Autowired private VciSessionForLoginI vciSessionForLoginI; + @Autowired + private RedisService redisService; + /** * 鎵ц鎷︽埅 * @param request 璇锋眰瀵硅薄 @@ -76,7 +77,7 @@ if(StringUtils.isBlank(userToken)){ userToken = request.getParameter(TokenKeyConstant.USER_TOKEN_KEY); } - if(!(handler instanceof HandlerMethod)){ + if(!(handler instanceof HandlerMethod)){ return true; } @@ -98,6 +99,11 @@ if(unCheckLogin){ //铏界劧涓嶆牎楠屾潈闄愶紝浣嗘槸濡傛灉token涓嶄负绌猴紝闇�瑕佹洿鏂板綋鍓嶇敤鎴� SessionInfo sessionInfo = getSessionInfo(userToken); + + if(sessionInfo != null){ + //鍒濆鍖栧钩鍙扮殑token + vciSessionForLoginI.initInvocationInfo(sessionInfo); + } return true; } @@ -122,6 +128,11 @@ if(logger.isErrorEnabled()) { logger.error("token鍊奸潪娉曪紝鎴栬繃鏈燂紝鎴栬�呯敤鎴峰凡缁忚韪笅绾�," + userToken); } + //鍒犻櫎缂撳瓨涓粺璁$殑鐢ㄦ埛淇℃伅 + if(redisService == null){ + redisService = ApplicationContextProvider.getBean(RedisService.class); + } + redisService.decreOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY); sendErrorMsg(response,"token鍊奸潪娉曪紝鎴栬繃鏈燂紝鎴栬�呯敤鎴峰凡缁忚韪笅绾�," + userToken,1); return false; }else{ -- Gitblit v1.9.3