Commit 73b1649b75dece37d078fe63fb925dcedbf12995
1 parent
eadb564a
fix: 积木报表 API 数据集解析时 token 未正确解析的问题
Showing
2 changed files
with
16 additions
and
10 deletions
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/jmreport/config/JmReportConfiguration.java
| 1 | 1 | package cn.iocoder.yudao.module.visualization.framework.jmreport.config; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.security.config.SecurityProperties; | |
| 3 | 4 | import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; |
| 4 | 5 | import cn.iocoder.yudao.module.visualization.framework.jmreport.core.service.JmReportTokenServiceImpl; |
| 5 | 6 | import org.jeecg.modules.jmreport.api.JmReportTokenServiceI; |
| ... | ... | @@ -18,8 +19,8 @@ public class JmReportConfiguration { |
| 18 | 19 | |
| 19 | 20 | @Bean |
| 20 | 21 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") |
| 21 | - public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi) { | |
| 22 | - return new JmReportTokenServiceImpl(oAuth2TokenApi); | |
| 22 | + public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi, SecurityProperties securityProperties) { | |
| 23 | + return new JmReportTokenServiceImpl(oAuth2TokenApi, securityProperties); | |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | } | ... | ... |
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; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 7 | +import cn.iocoder.yudao.framework.security.config.SecurityProperties; | |
| 7 | 8 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 8 | 9 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 9 | 10 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| ... | ... | @@ -25,31 +26,35 @@ import java.util.Objects; |
| 25 | 26 | @RequiredArgsConstructor |
| 26 | 27 | public class JmReportTokenServiceImpl implements JmReportTokenServiceI { |
| 27 | 28 | |
| 28 | - private static final String JM_TOKEN_HEADER = "X-Access-Token"; | |
| 29 | 29 | /** |
| 30 | - * 系统内置请求头 | |
| 30 | + * 积木 token head 头 | |
| 31 | 31 | */ |
| 32 | - private static final String TOKEN_HEADER = "Authorization"; | |
| 32 | + private static final String JM_TOKEN_HEADER = "X-Access-Token"; | |
| 33 | 33 | /** |
| 34 | 34 | * auth 相关格式 |
| 35 | 35 | */ |
| 36 | - private static final String AUTHORIZATION_FORMAT = "Bearer %s"; | |
| 36 | + private static final String AUTHORIZATION_FORMAT = SecurityFrameworkUtils.AUTHORIZATION_BEARER + " %s"; | |
| 37 | 37 | |
| 38 | 38 | private final OAuth2TokenApi oauth2TokenApi; |
| 39 | 39 | |
| 40 | + private final SecurityProperties securityProperties; | |
| 41 | + | |
| 40 | 42 | /** |
| 41 | - * 修改请求的 head | |
| 43 | + * 自定义 API 数据集appian自定义 Header,解决 Token 传递。 | |
| 44 | + * 参考 <a href="http://report.jeecg.com/2222224">api数据集token机制详解</a> 文档 | |
| 42 | 45 | * |
| 43 | 46 | * @return 新 head |
| 44 | 47 | */ |
| 45 | 48 | @Override |
| 46 | 49 | public HttpHeaders customApiHeader() { |
| 47 | - HttpHeaders header = new HttpHeaders(); | |
| 50 | + // 读取积木标标系统的 token | |
| 48 | 51 | HttpServletRequest request = ServletUtils.getRequest(); |
| 49 | 52 | String token = request.getHeader(JM_TOKEN_HEADER); |
| 50 | 53 | |
| 51 | - header.add(TOKEN_HEADER, String.format(AUTHORIZATION_FORMAT, token)); | |
| 52 | - return header; | |
| 54 | + // 设置到 yudao 系统的 token | |
| 55 | + HttpHeaders headers = new HttpHeaders(); | |
| 56 | + headers.add(securityProperties.getTokenHeader(), String.format(AUTHORIZATION_FORMAT, token)); | |
| 57 | + return headers; | |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | 60 | /** | ... | ... |