From 73b1649b75dece37d078fe63fb925dcedbf12995 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Sat, 7 Jan 2023 12:39:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=AF=E6=9C=A8=E6=8A=A5=E8=A1=A8=20A?= =?UTF-8?q?PI=20=E6=95=B0=E6=8D=AE=E9=9B=86=E8=A7=A3=E6=9E=90=E6=97=B6=20t?= =?UTF-8?q?oken=20=E6=9C=AA=E6=AD=A3=E7=A1=AE=E8=A7=A3=E6=9E=90=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/JmReportConfiguration.java | 5 +++-- .../service/JmReportTokenServiceImpl.java | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/config/JmReportConfiguration.java b/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/config/JmReportConfiguration.java index 59510b5ff..c679d1112 100644 --- a/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/config/JmReportConfiguration.java +++ b/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/config/JmReportConfiguration.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.visualization.framework.jmreport.config; +import cn.iocoder.yudao.framework.security.config.SecurityProperties; import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; import cn.iocoder.yudao.module.visualization.framework.jmreport.core.service.JmReportTokenServiceImpl; import org.jeecg.modules.jmreport.api.JmReportTokenServiceI; @@ -18,8 +19,8 @@ public class JmReportConfiguration { @Bean @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") - public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi) { - return new JmReportTokenServiceImpl(oAuth2TokenApi); + public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi, SecurityProperties securityProperties) { + return new JmReportTokenServiceImpl(oAuth2TokenApi, securityProperties); } } diff --git a/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/core/service/JmReportTokenServiceImpl.java b/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/core/service/JmReportTokenServiceImpl.java index fa387a6e9..22c4a19c8 100644 --- a/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/core/service/JmReportTokenServiceImpl.java +++ b/yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/core/service/JmReportTokenServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; +import cn.iocoder.yudao.framework.security.config.SecurityProperties; import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; @@ -25,31 +26,35 @@ import java.util.Objects; @RequiredArgsConstructor public class JmReportTokenServiceImpl implements JmReportTokenServiceI { - private static final String JM_TOKEN_HEADER = "X-Access-Token"; /** - * 系统内置请求头 + * 积木 token head 头 */ - private static final String TOKEN_HEADER = "Authorization"; + private static final String JM_TOKEN_HEADER = "X-Access-Token"; /** * auth 相关格式 */ - private static final String AUTHORIZATION_FORMAT = "Bearer %s"; + private static final String AUTHORIZATION_FORMAT = SecurityFrameworkUtils.AUTHORIZATION_BEARER + " %s"; private final OAuth2TokenApi oauth2TokenApi; + private final SecurityProperties securityProperties; + /** - * 修改请求的 head + * 自定义 API 数据集appian自定义 Header,解决 Token 传递。 + * 参考 api数据集token机制详解 文档 * * @return 新 head */ @Override public HttpHeaders customApiHeader() { - HttpHeaders header = new HttpHeaders(); + // 读取积木标标系统的 token HttpServletRequest request = ServletUtils.getRequest(); String token = request.getHeader(JM_TOKEN_HEADER); - header.add(TOKEN_HEADER, String.format(AUTHORIZATION_FORMAT, token)); - return header; + // 设置到 yudao 系统的 token + HttpHeaders headers = new HttpHeaders(); + headers.add(securityProperties.getTokenHeader(), String.format(AUTHORIZATION_FORMAT, token)); + return headers; } /**