Commit 5b1e6c0d91f842c4d757ade3955f65b3ae8a9a9a

Authored by jiangqiang
2 parents 5da611d8 227a1257

Merge remote-tracking branch 'origin/feature/visual' into feature/visual

yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/filter/TokenAuthenticationFilter.java
... ... @@ -37,13 +37,34 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
37 37  
38 38 private final OAuth2TokenApi oauth2TokenApi;
39 39  
  40 + /**
  41 + * 积木报表内部请求获取token
  42 + *
  43 + * @param request
  44 + * @return
  45 + */
  46 + private static String getToken(HttpServletRequest request) {
  47 + String token = request.getParameter("token");
  48 + if (token == null) {
  49 + token = request.getHeader("X-Access-Token");
  50 + }
  51 + return token;
  52 + }
  53 +
40 54 @Override
41 55 @SuppressWarnings("NullableProblems")
42 56 protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
43 57 throws ServletException, IOException {
44   - String token = SecurityFrameworkUtils.obtainAuthorization(request, securityProperties.getTokenHeader());
  58 + String token;
  59 + Integer userType;
  60 + if (request.getRequestURI().startsWith("/jmreport/")) {
  61 + token = getToken(request);
  62 + userType = 2;
  63 + } else {
  64 + token = SecurityFrameworkUtils.obtainAuthorization(request, securityProperties.getTokenHeader());
  65 + userType = WebFrameworkUtils.getLoginUserType(request);
  66 + }
45 67 if (StrUtil.isNotEmpty(token)) {
46   - Integer userType = WebFrameworkUtils.getLoginUserType(request);
47 68 try {
48 69 // 1.1 基于 token 构建登录用户
49 70 LoginUser loginUser = buildLoginUserByToken(token, userType);
... ... @@ -88,11 +109,11 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
88 109  
89 110 /**
90 111 * 模拟登录用户,方便日常开发调试
91   - *
  112 + * <p>
92 113 * 注意,在线上环境下,一定要关闭该功能!!!
93 114 *
94   - * @param request 请求
95   - * @param token 模拟的 token,格式为 {@link SecurityProperties#getMockSecret()} + 用户编号
  115 + * @param request 请求
  116 + * @param token 模拟的 token,格式为 {@link SecurityProperties#getMockSecret()} + 用户编号
96 117 * @param userType 用户类型
97 118 * @return 模拟的 LoginUser
98 119 */
... ...
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/util/SecurityFrameworkUtils.java
... ... @@ -25,6 +25,20 @@ public class SecurityFrameworkUtils {
25 25 private SecurityFrameworkUtils() {}
26 26  
27 27 /**
  28 + * 积木报表内部请求获取token
  29 + *
  30 + * @param request
  31 + * @return
  32 + */
  33 + private static String getToken(HttpServletRequest request) {
  34 + String token = request.getParameter("token");
  35 + if (token == null) {
  36 + token = request.getHeader("X-Access-Token");
  37 + }
  38 + return token;
  39 + }
  40 +
  41 + /**
28 42 * 从请求中,获得认证 Token
29 43 *
30 44 * @param request 请求
... ... @@ -32,6 +46,9 @@ public class SecurityFrameworkUtils {
32 46 * @return 认证 Token
33 47 */
34 48 public static String obtainAuthorization(HttpServletRequest request, String header) {
  49 + if (request.getRequestURI().startsWith("/jmreport/")) {
  50 + return getToken(request);
  51 + }
35 52 String authorization = request.getHeader(header);
36 53 if (!StringUtils.hasText(authorization)) {
37 54 return null;
... ...
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/security/config/SecurityConfiguration.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.visualization.framework.security.config;
3 3 import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
4 4 import org.springframework.context.annotation.Bean;
5 5 import org.springframework.context.annotation.Configuration;
  6 +import org.springframework.http.HttpMethod;
6 7 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7 8 import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
8 9  
... ... @@ -17,7 +18,7 @@ public class SecurityConfiguration {
17 18 return new AuthorizeRequestsCustomizer() {
18 19 @Override
19 20 public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
20   - registry.antMatchers("/jmreport/**").anonymous();
  21 + registry.antMatchers(HttpMethod.GET, "/jmreport/**").permitAll();
21 22 }
22 23 };
23 24 }
... ...
yudao-ui-admin/src/views/visualization/jm/index.vue
... ... @@ -6,12 +6,13 @@
6 6 </template>
7 7 <script>
8 8 import iFrame from "@/components/iFrame/index";
  9 +import {getAccessToken} from "@/utils/auth";
9 10 export default {
10 11 name: "JimuReport",
11 12 components: { iFrame },
12 13 data() {
13 14 return {
14   - url: process.env.VUE_APP_BASE_API + "/jmreport/list"
  15 + url: process.env.VUE_APP_BASE_API + "/jmreport/list?token=" + getAccessToken(),
15 16 };
16 17 },
17 18 };
... ...