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

This commit is contained in:
gaibu 2023-01-06 18:23:39 +08:00
parent 24f0e4dd1f
commit 717dd1ab7c
2 changed files with 25 additions and 3 deletions

View File

@ -20,6 +20,8 @@ public class SecurityProperties {
@NotEmpty(message = "Token Header 不能为空") @NotEmpty(message = "Token Header 不能为空")
private String tokenHeader = "Authorization"; private String tokenHeader = "Authorization";
private String jmTokenHeader = "X-Access-Token";
/** /**
* mock 模式的开关 * mock 模式的开关
*/ */

View File

@ -21,6 +21,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.Optional;
/** /**
* Token 过滤器验证 token 的有效性 * Token 过滤器验证 token 的有效性
@ -62,6 +63,25 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
return; return;
} }
} }
// 积木请求头
String jmTokenHeader = request.getHeader(securityProperties.getJmTokenHeader());
if (StrUtil.isNotEmpty(jmTokenHeader)) {
try {
OAuth2AccessTokenCheckRespDTO accessToken = oauth2TokenApi.checkAccessToken(jmTokenHeader);
Optional<LoginUser> optUser = Optional.ofNullable(accessToken)
.map(
t -> new LoginUser().setId(t.getUserId())
.setUserType(t.getUserType())
.setTenantId(t.getTenantId())
.setScopes(t.getScopes())
);
if (optUser.isPresent()) {
SecurityFrameworkUtils.setLoginUser(optUser.get(), request);
}
} catch (ServiceException ignored) {
// do nothing如果报错说明认证失败忽略即可
}
}
// 继续过滤链 // 继续过滤链
chain.doFilter(request, response); chain.doFilter(request, response);
@ -88,7 +108,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
/** /**
* 模拟登录用户方便日常开发调试 * 模拟登录用户方便日常开发调试
* * <p>
* 注意在线上环境下一定要关闭该功能 * 注意在线上环境下一定要关闭该功能
* *
* @param request 请求 * @param request 请求