From 145e82ce09bd73bfe11afabd70a00f01a88d4be6 Mon Sep 17 00:00:00 2001
From: wangting <wangting@vci-tech.com>
Date: 星期三, 18 十二月 2024 17:37:00 +0800
Subject: [PATCH] 图标管理
---
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java | 98 ++++++++++++++++++++++++++++++++++---------------
1 files changed, 68 insertions(+), 30 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 5be623c..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,12 @@
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;
import com.vci.starter.web.util.WebThreadLocalUtil;
@@ -14,6 +17,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
@@ -30,6 +34,7 @@
* @author weidy
* @date 2019/11/7 2:32 PM
*/
+//@Configuration
public class VciSecurityInterceptor implements HandlerInterceptor {
/**
@@ -46,8 +51,11 @@
/**
* 浼氳瘽锛屾潈闄愶紝token鐨勬帴鍙�
*/
- @Autowired(required = false)
- private VciSessionForLoginI sessionForLoginI;
+ @Autowired
+ private VciSessionForLoginI vciSessionForLoginI;
+
+ @Autowired
+ private RedisService redisService;
/**
* 鎵ц鎷︽埅
@@ -69,39 +77,40 @@
if(StringUtils.isBlank(userToken)){
userToken = request.getParameter(TokenKeyConstant.USER_TOKEN_KEY);
}
- if(!(handler instanceof HandlerMethod)){
+ if(!(handler instanceof HandlerMethod)){
return true;
}
- List<String> unCheckUrls = new ArrayList<>();
- if(springMVCConfig !=null && springMVCConfig.getUnCheckUrls() !=null){
- unCheckUrls = springMVCConfig.getUnCheckUrls();
- }
- SessionInfo sessionInfo = null;
- if(StringUtils.isNotBlank(userToken)){
- try{
- sessionInfo = sessionForLoginI.getSessionInfoByToken(userToken);
- }catch (Throwable e){
- logger.error("鑾峰彇token鍑洪敊",e);
- //sendErrorMsg(response,"鑾峰彇token鐨勪俊鎭嚭閿欙紝" + userToken + "," + LangBaseUtil.getErrorMsg(e),1);
- //return false;
- }
- if(sessionInfo!=null){
- WebThreadLocalUtil.getCurrentUserSessionInfoInThread().set(sessionInfo);
- }
- }
+
+ boolean unCheckLogin = false;
if(handler instanceof HandlerMethod) {
HandlerMethod hm = (HandlerMethod)handler;
Method method = hm.getMethod();
//璁剧疆浜嗕笉鏍¢獙鐨勪細鐩存帴杩斿洖true
if (method.isAnnotationPresent(VciUnCheckRight.class)) {
- return true;
+ unCheckLogin = true;
}
if (method.getDeclaringClass().isAnnotationPresent(VciUnCheckRight.class)) {
- return true;
+ unCheckLogin = true;
}
}
if(url.endsWith(".md")){
+ unCheckLogin = true;
+ }
+ if(unCheckLogin){
+ //铏界劧涓嶆牎楠屾潈闄愶紝浣嗘槸濡傛灉token涓嶄负绌猴紝闇�瑕佹洿鏂板綋鍓嶇敤鎴�
+ SessionInfo sessionInfo = getSessionInfo(userToken);
+
+ if(sessionInfo != null){
+ //鍒濆鍖栧钩鍙扮殑token
+ vciSessionForLoginI.initInvocationInfo(sessionInfo);
+ }
+
return true;
+ }
+ //鑾峰彇閰嶇疆鏂囦欢涓紝涓嶆牎楠屾潈闄愮殑璺緞
+ List<String> unCheckUrls = new ArrayList<>();
+ if(springMVCConfig !=null && springMVCConfig.getUnCheckUrls() !=null){
+ unCheckUrls = springMVCConfig.getUnCheckUrls();
}
if(StringUtils.isBlank(userToken) && !unCheckUrls.contains(url)){
//璇存槑鏄病鏈夌敤鎴蜂俊鎭殑锛岃�屼笖涔熷繀椤昏鏍¢獙鏄惁鐧诲綍鐨勬儏鍐�
@@ -111,18 +120,24 @@
}
sendErrorMsg(response,"娌℃湁鐧诲綍绯荤粺锛岃鍏堢櫥褰�",1);
return false;
- //琚玊涓嬬嚎鐢眞ebsocket鐩存帴鎻愰啋
+ //琚涪涓嬬嚎鐢眞ebsocket鐩存帴鎻愰啋
}else{
+ SessionInfo sessionInfo = getSessionInfo(userToken);
if(sessionInfo == null){
- //涔熸槸璇存槑涓嶅瓨鍦紝琚玊涓嬬嚎鏃朵篃鑾峰彇涓嶅埌session鐨勪俊鎭簡
+ //涔熸槸璇存槑涓嶅瓨鍦紝琚涪涓嬬嚎鏃朵篃鑾峰彇涓嶅埌session鐨勪俊鎭簡
if(logger.isErrorEnabled()) {
- logger.error("token鍊奸潪娉曪紝鎴栬�呯敤鎴峰凡缁忚韪笅绾�," + userToken);
+ logger.error("token鍊奸潪娉曪紝鎴栬繃鏈燂紝鎴栬�呯敤鎴峰凡缁忚韪笅绾�," + userToken);
}
- sendErrorMsg(response,"token鍊奸潪娉曪紝鎴栬�呯敤鎴峰凡缁忚韪笅绾�," + userToken,1);
+ //鍒犻櫎缂撳瓨涓粺璁$殑鐢ㄦ埛淇℃伅
+ if(redisService == null){
+ redisService = ApplicationContextProvider.getBean(RedisService.class);
+ }
+ redisService.decreOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
+ sendErrorMsg(response,"token鍊奸潪娉曪紝鎴栬繃鏈燂紝鎴栬�呯敤鎴峰凡缁忚韪笅绾�," + userToken,1);
return false;
}else{
if(!unCheckUrls.contains(url)){
- if(sessionForLoginI == null){
+ if(vciSessionForLoginI == null){
//璇存槑娌″姙娉曟牎楠�
String msg = "璇锋眰璺緞"+ url +"娌℃潈闄愯闂�";
if(logger.isErrorEnabled()) {
@@ -131,9 +146,12 @@
sendErrorMsg(response,msg,2);
return false;
}else{
+ //鍒濆鍖栧钩鍙扮殑token
+ vciSessionForLoginI.initInvocationInfo(sessionInfo);
+
String systemPrivateToken = request.getHeader(TokenKeyConstant.SYSTEM_PRIVATE_KEY);
try {
- if (sessionForLoginI.checkRequestRights(request, systemPrivateToken, sessionInfo, handler)) {
+ if (vciSessionForLoginI.checkRequestRights(request, systemPrivateToken, sessionInfo, handler)) {
updateRequestTime(url,userToken);
}else{
return false;
@@ -153,6 +171,26 @@
}
}
return true;
+ }
+
+ private SessionInfo getSessionInfo(String userToken){
+ SessionInfo sessionInfo = null;
+ if(StringUtils.isNotBlank(userToken)){
+ try{
+ if(vciSessionForLoginI == null){
+ vciSessionForLoginI = ApplicationContextProvider.getBean(VciSessionForLoginI.class);
+ }
+
+ sessionInfo = vciSessionForLoginI.getSessionInfoByToken(userToken);
+ }catch (Throwable e){
+ logger.error("鑾峰彇token鍑洪敊",e);
+ }
+ if(sessionInfo!=null){
+ WebThreadLocalUtil.setCurrentUserSessionInfoInThread(sessionInfo);
+ WebThreadLocalUtil.setTokenInThread(TokenKeyConstant.TOKEN_KEY_PREFIX_IN_REDIS+sessionInfo.getToken());
+ }
+ }
+ return sessionInfo;
}
/**
@@ -191,8 +229,8 @@
while(url1.startsWith("/")){
url1 = url1.substring(1);
}
- if(sessionForLoginI != null && !unStorageRequestTimeUrls.contains(url1)){
- sessionForLoginI.updateRequestTime(userToken);
+ if(vciSessionForLoginI != null && !unStorageRequestTimeUrls.contains(url1)){
+ vciSessionForLoginI.updateRequestTime(userToken);
}
}
}
--
Gitblit v1.9.3