From 42a2772d1aa7493bcc4fac3e24ee8eda4eebc23d Mon Sep 17 00:00:00 2001 From: xubinbin <1323875150@qq.com> Date: 星期二, 12 十二月 2023 17:09:04 +0800 Subject: [PATCH] bugfix:请求头带token, SecurityUtils 获取用户id 一直为0 #1195 --- src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java index 6cc3b41..a7416a8 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java @@ -2,11 +2,10 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; -import org.apache.catalina.connector.ClientAbortException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; -import org.junit.jupiter.api.Order; +import org.springframework.core.annotation.Order; import org.mitre.dsmiley.httpproxy.ProxyServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,6 +18,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.ConnectException; @@ -63,6 +63,18 @@ } } return queryStr; + } + + + @Override + protected HttpResponse doExecute(HttpServletRequest servletRequest, HttpServletResponse servletResponse, + HttpRequest proxyRequest) throws IOException { + HttpResponse response = super.doExecute(servletRequest, servletResponse, proxyRequest); + response.removeHeaders("Access-Control-Allow-Origin"); + response.setHeader("Access-Control-Allow-Credentials","true"); + response.removeHeaders("Access-Control-Allow-Credentials"); + + return response; } /** @@ -182,6 +194,18 @@ return queryStr; } + + @Override + protected HttpResponse doExecute(HttpServletRequest servletRequest, HttpServletResponse servletResponse, + HttpRequest proxyRequest) throws IOException { + HttpResponse response = super.doExecute(servletRequest, servletResponse, proxyRequest); + String origin = servletRequest.getHeader("origin"); + response.setHeader("Access-Control-Allow-Origin",origin); + response.setHeader("Access-Control-Allow-Credentials","true"); + + return response; + } + /** * 寮傚父澶勭悊 */ @@ -194,11 +218,11 @@ } catch (IOException ioException) { if (ioException instanceof ConnectException) { logger.error("褰曞儚鏈嶅姟 杩炴帴澶辫触"); - }else if (ioException instanceof ClientAbortException) { - /** - * TODO 浣跨敤杩欎釜浠g悊搴撳疄鐜颁唬鐞嗗湪閬囧埌浠g悊瑙嗛鏂囦欢鏃讹紝濡傛灉鏄�206缁撴灉锛屼細閬囧埌鎶ラ敊铔嬪競鐩墠鍔熻兘姝e父锛� - * TODO 鏆傛椂鍘婚櫎寮傚父澶勭悊銆傚悗缁娇鐢ㄥ叾浠栦唬鐞嗘鏋朵慨鏀规祴璇� - */ +// }else if (ioException instanceof ClientAbortException) { +// /** +// * TODO 浣跨敤杩欎釜浠g悊搴撳疄鐜颁唬鐞嗗湪閬囧埌浠g悊瑙嗛鏂囦欢鏃讹紝濡傛灉鏄�206缁撴灉锛屼細閬囧埌鎶ラ敊铔嬪競鐩墠鍔熻兘姝e父锛� +// * TODO 鏆傛椂鍘婚櫎寮傚父澶勭悊銆傚悗缁娇鐢ㄥ叾浠栦唬鐞嗘鏋朵慨鏀规祴璇� +// */ }else { logger.error("褰曞儚鏈嶅姟 浠g悊澶辫触锛� ", e); -- Gitblit v1.8.0