From 65bcf58c4e11a09b095bb60a639af8cadd025cba Mon Sep 17 00:00:00 2001
From: chengf <cgf12138@163.com>
Date: 星期三, 22 十月 2025 18:26:52 +0800
Subject: [PATCH] 部门/岗位添加部门代码
---
service-api/src/main/java/com/java110/api/aop/PageProcessAspect.java | 58 +++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/service-api/src/main/java/com/java110/api/aop/PageProcessAspect.java b/service-api/src/main/java/com/java110/api/aop/PageProcessAspect.java
index c9d221c..68f1030 100644
--- a/service-api/src/main/java/com/java110/api/aop/PageProcessAspect.java
+++ b/service-api/src/main/java/com/java110/api/aop/PageProcessAspect.java
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSONObject;
import com.java110.core.context.IPageData;
import com.java110.core.context.PageData;
-import com.java110.core.context.SecureInvocation;
import com.java110.core.log.LoggerFactory;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.exception.FilterException;
@@ -113,7 +112,6 @@
String componentMethod = "";
if (url.contains("callComponent")) { //缁勪欢澶勭悊
String[] urls = url.split("/");
-
if (urls.length == 6) {
componentCode = urls[4];
componentMethod = urls[5];
@@ -134,12 +132,17 @@
String headerName = (String) reqHeaderEnum.nextElement();
headers.put(headerName.toLowerCase(), request.getHeader(headerName));
}
- pd = PageData.newInstance().builder(userId, userName, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId, appId, headers);
+ //pd = PageData.newInstance().builder(userId, userName, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId, appId, headers);
+ headers.put(CommonConstant.COOKIE_AUTH_TOKEN,this.getToken(request));
+ pd = PageData.newInstance().builder(userId, userName, "", reqData, componentCode, componentMethod, url, sessionId, appId, headers);
pd.setMethod(request.getMethod().equals("GET") ? HttpMethod.GET : HttpMethod.POST);
logger.debug("鍒囬潰 鑾峰彇鍒扮殑pd=" + JSONObject.toJSONString(pd));
request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA, pd);
+ //璋冪敤閾�
+ //Java110TraceFactory.createTrace(componentCode + "/" + componentMethod, headers);
}
+
@AfterReturning(returning = "ret", pointcut = "dataProcess()")
public void doAfterReturning(Object ret) throws Throwable {
@@ -156,14 +159,15 @@
public void after(JoinPoint jp) throws IOException {
// 鎺ユ敹鍒拌姹傦紝璁板綍璇锋眰鍐呭
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-
HttpServletRequest request = attributes.getRequest();
+ //璁板綍璋冪敤閾�
+ //Java110TraceFactory.putAnnotations(TraceAnnotationsDto.VALUE_CLIENT_RECEIVE);
+
PageData pd = request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA) != null ? (PageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA) : null;
//淇濆瓨鏃ュ織澶勭悊
if (pd == null) {
return;
}
-
//鍐檆ookies淇℃伅
writeCookieInfo(pd, attributes);
@@ -177,7 +181,7 @@
return o;
} catch (Throwable e) {
logger.error("鎵ц鏂规硶寮傚父", e);
- return new ResponseEntity("鍐呴儴寮傚父" + e.getLocalizedMessage(), HttpStatus.BAD_REQUEST);
+ return new ResponseEntity(e.getLocalizedMessage(), HttpStatus.BAD_REQUEST);
}
}
@@ -190,14 +194,22 @@
*/
private String getToken(HttpServletRequest request) throws FilterException {
String token = "";
- if (request.getCookies() == null || request.getCookies().length == 0) {
+// if (request.getCookies() != null && request.getCookies().length > 0) {
+// for (Cookie cookie : request.getCookies()) {
+// if (CommonConstant.COOKIE_AUTH_TOKEN.equals(cookie.getName())) {
+// token = cookie.getValue();
+// }
+// }
+// }
+ String authorization = request.getHeader("Authorization");
+
+ if( StringUtil.isEmpty(authorization)){
return token;
}
- for (Cookie cookie : request.getCookies()) {
- if (CommonConstant.COOKIE_AUTH_TOKEN.equals(cookie.getName()) ) {
- token = cookie.getValue();
- }
+ if(authorization.length()> 7) {
+ token = authorization.substring("Bearer ".length());
}
+
return token;
}
@@ -210,15 +222,23 @@
* @throws IOException
*/
private void writeCookieInfo(IPageData pd, ServletRequestAttributes attributes) throws IOException {
- // 杩欓噷鐩墠鍙啓鍒扮粍浠剁骇鍒紝濡傛灉闇�瑕� 鍐欐垚鏂规硶绾у埆
- if (!StringUtil.isNullOrNone(pd.getToken()) && "login".equals(pd.getComponentCode())) {
- HttpServletResponse response = attributes.getResponse();
- Cookie cookie = new Cookie(CommonConstant.COOKIE_AUTH_TOKEN, pd.getToken());
- cookie.setHttpOnly(true);
- cookie.setPath("/");
- response.addCookie(cookie);
- response.flushBuffer();
+ // 杩欓噷鐩墠鍙啓鍒扮粍浠剁骇鍒紝濡傛灉闇�瑕� 鍐欐垚鏂规硶绾у埆 && "login".equals(pd.getComponentCode())
+ //todo 鏈寘鍚玹oken 涓嶅仛澶勭悊
+ if (StringUtil.isNullOrNone(pd.getToken())) {
+ return;
}
+ HttpServletResponse response = attributes.getResponse();
+
+ //璁瞭oken鍐欏叆鍒癱ookies 涓�
+ Cookie cookie = new Cookie(CommonConstant.COOKIE_AUTH_TOKEN, pd.getToken());
+ cookie.setHttpOnly(true);
+ cookie.setPath("/");
+
+ response.addCookie(cookie);
+ //response.addHeader("Set-Cookie","SameSite=None");
+
+ response.flushBuffer();
+
}
}
--
Gitblit v1.8.0