From 21487eadf6c52d8fd470e6c0bd2d8eb066ea5d94 Mon Sep 17 00:00:00 2001 From: zengxiaobo Date: Mon, 27 May 2024 18:23:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/context/AxContextInterceptor.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/web-support-lib/src/main/java/cn/axzo/foundation/web/support/context/AxContextInterceptor.java b/web-support-lib/src/main/java/cn/axzo/foundation/web/support/context/AxContextInterceptor.java index b5356fc..36c84de 100644 --- a/web-support-lib/src/main/java/cn/axzo/foundation/web/support/context/AxContextInterceptor.java +++ b/web-support-lib/src/main/java/cn/axzo/foundation/web/support/context/AxContextInterceptor.java @@ -49,19 +49,8 @@ public class AxContextInterceptor implements HandlerInterceptor { String authorization = request.getHeader("Authorization"); if (!Strings.isNullOrEmpty(authorization) && appRuntime.getEnv() == AppEnvEnum.local) { - AxContext authContext = tryGetContextAuthorization(authorization, request); - if (authContext.getAxUser() != null) { - context.setAxUser(authContext.getAxUser()); - } - if (authContext.getOuId() != null) { - context.setOuId(authContext.getOuId()); - } - if (authContext.getWorkspaceId() != null) { - context.setWorkspaceId(authContext.getWorkspaceId()); - } - if (authContext.getTerminal() != null) { - context.setTerminal(authContext.getTerminal()); - } + AxContext localContext = tryGetContextAuthorization(authorization, request); + merge(context, localContext); } AxContext.set(context); return true; @@ -73,6 +62,24 @@ public class AxContextInterceptor implements HandlerInterceptor { AxContext.clear(); } + private void merge(AxContext headerContext, AxContext localContext) { + if (localContext == null) { + return; + } + if (localContext.getAxUser() != null) { + headerContext.setAxUser(localContext.getAxUser()); + } + if (localContext.getOuId() != null) { + headerContext.setOuId(localContext.getOuId()); + } + if (localContext.getWorkspaceId() != null) { + headerContext.setWorkspaceId(localContext.getWorkspaceId()); + } + if (localContext.getTerminal() != null) { + headerContext.setTerminal(localContext.getTerminal()); + } + } + /** * 支持传入明文的authentication 或者通过puge接口支持 * 明文格式: authentication: Raw {ouid:xxx, axUser:{personId:xxx}}