From 18e2c156de069eaee2f989e09fda061841aae605 Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期四, 11 七月 2024 11:35:33 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java | 90 ++++++++++++++++++++++++++++++--------------
1 files changed, 61 insertions(+), 29 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..9679f27 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
@@ -7,6 +7,7 @@
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.util.ApplicationContextProvider;
import com.vci.starter.web.util.LangBaseUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.WebThreadLocalUtil;
@@ -14,10 +15,15 @@
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;
@@ -30,6 +36,7 @@
* @author weidy
* @date 2019/11/7 2:32 PM
*/
+//@Configuration
public class VciSecurityInterceptor implements HandlerInterceptor {
/**
@@ -46,8 +53,8 @@
/**
* 浼氳瘽锛屾潈闄愶紝token鐨勬帴鍙�
*/
- @Autowired(required = false)
- private VciSessionForLoginI sessionForLoginI;
+ @Autowired
+ private VciSessionForLoginI vciSessionForLoginI;
/**
* 鎵ц鎷︽埅
@@ -72,36 +79,37 @@
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 +119,19 @@
}
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);
+ 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 +140,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 +165,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 +223,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