From a2d9cfec028c81bdcfe0caee1d46afca254ac2d3 Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Fri, 18 Sep 2026 19:13:45 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=89=8B=E6=9C=BA=E5=8F=B7=E7=99=BB=E5=BD=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98=202=E3=80=81=E8=B0=83=E6=95=B4OA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 5 + .../oa/config/OAFeignClientConfig.java | 30 +---- .../thirdparty/oa/config/OAProperties.java | 2 +- .../oa/interceptor/OARequestInterceptor.java | 122 ++++++++++++++++++ doc/nacos/blade-dev.yaml | 1 + doc/nacos/blade-prod.yaml | 1 + doc/nacos/third-party-api.yaml | 1 + 7 files changed, 138 insertions(+), 24 deletions(-) create mode 100644 blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/interceptor/OARequestInterceptor.java diff --git a/blade-service/blade-system/src/main/resources/application.yml b/blade-service/blade-system/src/main/resources/application.yml index 1d8d630..2d04e41 100644 --- a/blade-service/blade-system/src/main/resources/application.yml +++ b/blade-service/blade-system/src/main/resources/application.yml @@ -32,3 +32,8 @@ iam: authorization: ${IAM_SSO_AUTHORIZATION:Z3d6aF90bXMtOVJJU0RVN1U6YW0yYkcwWnBJZ0RQZmtrSjNaZkZjUDBSaGFuSEtxQng=} profile-authorization: ${IAM_SSO_PROFILE_AUTHORIZATION:YjNlZmU0ODEwMzJiNGJhZTpkYzQ5NDY1NmQ4MzE0NThjODI5MzlmNzA2ZjliNDY3MQ==} page-size: ${IAM_SSO_ACCOUNT_PAGE_SIZE:50} + +# OA人员同步走同一 gwzh 网关,仅需 Authorization(与可用 curl 一致) +thirdParty: + oa: + authorization: ${OA_AUTHORIZATION:${IAM_SSO_AUTHORIZATION:Z3d6aF90bXMtOVJJU0RVN1U6YW0yYkcwWnBJZ0RQZmtrSjNaZkZjUDBSaGFuSEtxQng=}} diff --git a/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAFeignClientConfig.java b/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAFeignClientConfig.java index 8917a2d..ef4306a 100644 --- a/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAFeignClientConfig.java +++ b/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAFeignClientConfig.java @@ -1,42 +1,26 @@ package org.springblade.thirdparty.oa.config; import feign.Request; -import feign.RequestInterceptor; -import jakarta.annotation.Resource; -import org.springblade.core.tool.utils.StringUtil; +import org.springblade.thirdparty.oa.interceptor.OARequestInterceptor; import org.springframework.context.annotation.Bean; import java.util.concurrent.TimeUnit; /** + * OA Feign 客户端配置 + * * @author bfhuange * @since 2024/12/18 */ public class OAFeignClientConfig { - @Resource - OAProperties oaProperties; - @Bean - public RequestInterceptor requestInterceptor() { - return template -> { - // 空实现屏蔽 全局拦截器 BladeFeignRequestInterceptor - template.header("Authorization", normalizeAuthorization(oaProperties.getAuthorization())); - }; - } + @Bean + public OARequestInterceptor requestInterceptor(OAProperties oaProperties) { + return new OARequestInterceptor(oaProperties); + } @Bean public Request.Options options() { return new Request.Options(10, TimeUnit.SECONDS, 120, TimeUnit.SECONDS, true); } - - private String normalizeAuthorization(String authorization) { - if (StringUtil.isBlank(authorization)) { - return authorization; - } - if (StringUtil.startsWithIgnoreCase(authorization, "Basic ") - || StringUtil.startsWithIgnoreCase(authorization, "Bearer ")) { - return authorization; - } - return "Basic " + authorization; - } } diff --git a/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAProperties.java b/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAProperties.java index bfcbae1..264d15b 100644 --- a/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAProperties.java +++ b/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/config/OAProperties.java @@ -17,7 +17,7 @@ public class OAProperties { private String baseUrl; /** - * authorization + * gwzh 网关 Authorization(Basic),与可用 curl 一致 */ private String authorization; } diff --git a/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/interceptor/OARequestInterceptor.java b/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/interceptor/OARequestInterceptor.java new file mode 100644 index 0000000..fa6e580 --- /dev/null +++ b/blade-third-party-api/blade-oa-api/src/main/java/org/springblade/thirdparty/oa/interceptor/OARequestInterceptor.java @@ -0,0 +1,122 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *
+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *
+ * 1. This software is for development use only under a valid license + * from BladeX. + *
+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *
+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *
+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *
+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *
+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.thirdparty.oa.interceptor; + +import feign.RequestInterceptor; +import feign.RequestTemplate; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.thirdparty.oa.config.OAProperties; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Set; + +/** + * OA Feign 请求拦截器。 + *
+ * 对齐可用 curl:仅发送 Authorization + Content-Type,并清掉登录请求透传头,
+ * 避免 nginx 因 Host/Content-Length/Blade-Auth 等返回 400。
+ *
+ * @author Chill
+ */
+@Slf4j
+@RequiredArgsConstructor
+public class OARequestInterceptor implements RequestInterceptor {
+
+ private static final String BASIC_PREFIX = "Basic ";
+ private static final String BEARER_PREFIX = "Bearer ";
+ private static final Set