Commit bbb27df5e92d33428745de6886a28e0dc0884810
Committed by
Gitee
!359 积木报表:API数据集解析时,提示数据为空,报表字段明细会被清空
Merge pull request !359 from 与或非/issues/I62TCM
Showing
2 changed files
with
36 additions
and
2 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
| ... | ... | @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.visualization.framework.jmreport.core.service; |
| 3 | 3 | 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 | +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | |
| 7 | +import cn.iocoder.yudao.framework.security.config.SecurityProperties; | |
| 6 | 8 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 7 | 9 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 8 | 10 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| ... | ... | @@ -11,7 +13,9 @@ import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; |
| 11 | 13 | import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; |
| 12 | 14 | import lombok.RequiredArgsConstructor; |
| 13 | 15 | import org.jeecg.modules.jmreport.api.JmReportTokenServiceI; |
| 16 | +import org.springframework.http.HttpHeaders; | |
| 14 | 17 | |
| 18 | +import javax.servlet.http.HttpServletRequest; | |
| 15 | 19 | import java.util.Objects; |
| 16 | 20 | |
| 17 | 21 | /** |
| ... | ... | @@ -22,8 +26,37 @@ import java.util.Objects; |
| 22 | 26 | @RequiredArgsConstructor |
| 23 | 27 | public class JmReportTokenServiceImpl implements JmReportTokenServiceI { |
| 24 | 28 | |
| 29 | + /** | |
| 30 | + * 积木 token head 头 | |
| 31 | + */ | |
| 32 | + private static final String JM_TOKEN_HEADER = "X-Access-Token"; | |
| 33 | + /** | |
| 34 | + * auth 相关格式 | |
| 35 | + */ | |
| 36 | + private static final String AUTHORIZATION_FORMAT = SecurityFrameworkUtils.AUTHORIZATION_BEARER + " %s"; | |
| 37 | + | |
| 25 | 38 | private final OAuth2TokenApi oauth2TokenApi; |
| 26 | 39 | |
| 40 | + private final SecurityProperties securityProperties; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 自定义 API 数据集appian自定义 Header,解决 Token 传递。 | |
| 44 | + * 参考 <a href="http://report.jeecg.com/2222224">api数据集token机制详解</a> 文档 | |
| 45 | + * | |
| 46 | + * @return 新 head | |
| 47 | + */ | |
| 48 | + @Override | |
| 49 | + public HttpHeaders customApiHeader() { | |
| 50 | + // 读取积木标标系统的 token | |
| 51 | + HttpServletRequest request = ServletUtils.getRequest(); | |
| 52 | + String token = request.getHeader(JM_TOKEN_HEADER); | |
| 53 | + | |
| 54 | + // 设置到 yudao 系统的 token | |
| 55 | + HttpHeaders headers = new HttpHeaders(); | |
| 56 | + headers.add(securityProperties.getTokenHeader(), String.format(AUTHORIZATION_FORMAT, token)); | |
| 57 | + return headers; | |
| 58 | + } | |
| 59 | + | |
| 27 | 60 | /** |
| 28 | 61 | * 校验 Token 是否有效,即验证通过 |
| 29 | 62 | * | ... | ... |