fix: 积木报表 API 数据集解析时 token 未正确解析的问题

This commit is contained in:
gaibu 2023-01-07 12:39:46 +08:00
parent eadb564a75
commit 73b1649b75
2 changed files with 16 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.visualization.framework.jmreport.config; 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.system.api.oauth2.OAuth2TokenApi;
import cn.iocoder.yudao.module.visualization.framework.jmreport.core.service.JmReportTokenServiceImpl; import cn.iocoder.yudao.module.visualization.framework.jmreport.core.service.JmReportTokenServiceImpl;
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI; import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
@ -18,8 +19,8 @@ public class JmReportConfiguration {
@Bean @Bean
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi) { public JmReportTokenServiceI jmReportTokenService(OAuth2TokenApi oAuth2TokenApi, SecurityProperties securityProperties) {
return new JmReportTokenServiceImpl(oAuth2TokenApi); return new JmReportTokenServiceImpl(oAuth2TokenApi, securityProperties);
} }
} }

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; 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.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
@ -25,31 +26,35 @@ import java.util.Objects;
@RequiredArgsConstructor @RequiredArgsConstructor
public class JmReportTokenServiceImpl implements JmReportTokenServiceI { 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 相关格式 * 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 OAuth2TokenApi oauth2TokenApi;
private final SecurityProperties securityProperties;
/** /**
* 修改请求的 head * 自定义 API 数据集appian自定义 Header解决 Token 传递
* 参考 <a href="http://report.jeecg.com/2222224">api数据集token机制详解</a> 文档
* *
* @return head * @return head
*/ */
@Override @Override
public HttpHeaders customApiHeader() { public HttpHeaders customApiHeader() {
HttpHeaders header = new HttpHeaders(); // 读取积木标标系统的 token
HttpServletRequest request = ServletUtils.getRequest(); HttpServletRequest request = ServletUtils.getRequest();
String token = request.getHeader(JM_TOKEN_HEADER); String token = request.getHeader(JM_TOKEN_HEADER);
header.add(TOKEN_HEADER, String.format(AUTHORIZATION_FORMAT, token)); // 设置到 yudao 系统的 token
return header; HttpHeaders headers = new HttpHeaders();
headers.add(securityProperties.getTokenHeader(), String.format(AUTHORIZATION_FORMAT, token));
return headers;
} }
/** /**