Commit 5b1e6c0d91f842c4d757ade3955f65b3ae8a9a9a
Merge remote-tracking branch 'origin/feature/visual' into feature/visual
Showing
4 changed files
with
47 additions
and
7 deletions
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,13 +37,34 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { | ||
| 37 | 37 | ||
| 38 | private final OAuth2TokenApi oauth2TokenApi; | 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 | @Override | 54 | @Override |
| 41 | @SuppressWarnings("NullableProblems") | 55 | @SuppressWarnings("NullableProblems") |
| 42 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) | 56 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) |
| 43 | throws ServletException, IOException { | 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 | if (StrUtil.isNotEmpty(token)) { | 67 | if (StrUtil.isNotEmpty(token)) { |
| 46 | - Integer userType = WebFrameworkUtils.getLoginUserType(request); | ||
| 47 | try { | 68 | try { |
| 48 | // 1.1 基于 token 构建登录用户 | 69 | // 1.1 基于 token 构建登录用户 |
| 49 | LoginUser loginUser = buildLoginUserByToken(token, userType); | 70 | LoginUser loginUser = buildLoginUserByToken(token, userType); |
| @@ -88,11 +109,11 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { | @@ -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 | * @param userType 用户类型 | 117 | * @param userType 用户类型 |
| 97 | * @return 模拟的 LoginUser | 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,6 +25,20 @@ public class SecurityFrameworkUtils { | ||
| 25 | private SecurityFrameworkUtils() {} | 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 | * 从请求中,获得认证 Token | 42 | * 从请求中,获得认证 Token |
| 29 | * | 43 | * |
| 30 | * @param request 请求 | 44 | * @param request 请求 |
| @@ -32,6 +46,9 @@ public class SecurityFrameworkUtils { | @@ -32,6 +46,9 @@ public class SecurityFrameworkUtils { | ||
| 32 | * @return 认证 Token | 46 | * @return 认证 Token |
| 33 | */ | 47 | */ |
| 34 | public static String obtainAuthorization(HttpServletRequest request, String header) { | 48 | public static String obtainAuthorization(HttpServletRequest request, String header) { |
| 49 | + if (request.getRequestURI().startsWith("/jmreport/")) { | ||
| 50 | + return getToken(request); | ||
| 51 | + } | ||
| 35 | String authorization = request.getHeader(header); | 52 | String authorization = request.getHeader(header); |
| 36 | if (!StringUtils.hasText(authorization)) { | 53 | if (!StringUtils.hasText(authorization)) { |
| 37 | return null; | 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,6 +3,7 @@ package cn.iocoder.yudao.module.visualization.framework.security.config; | ||
| 3 | import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; | 3 | import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; |
| 4 | import org.springframework.context.annotation.Bean; | 4 | import org.springframework.context.annotation.Bean; |
| 5 | import org.springframework.context.annotation.Configuration; | 5 | import org.springframework.context.annotation.Configuration; |
| 6 | +import org.springframework.http.HttpMethod; | ||
| 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; | 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 7 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | 8 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; |
| 8 | 9 | ||
| @@ -17,7 +18,7 @@ public class SecurityConfiguration { | @@ -17,7 +18,7 @@ public class SecurityConfiguration { | ||
| 17 | return new AuthorizeRequestsCustomizer() { | 18 | return new AuthorizeRequestsCustomizer() { |
| 18 | @Override | 19 | @Override |
| 19 | public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { | 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,12 +6,13 @@ | ||
| 6 | </template> | 6 | </template> |
| 7 | <script> | 7 | <script> |
| 8 | import iFrame from "@/components/iFrame/index"; | 8 | import iFrame from "@/components/iFrame/index"; |
| 9 | +import {getAccessToken} from "@/utils/auth"; | ||
| 9 | export default { | 10 | export default { |
| 10 | name: "JimuReport", | 11 | name: "JimuReport", |
| 11 | components: { iFrame }, | 12 | components: { iFrame }, |
| 12 | data() { | 13 | data() { |
| 13 | return { | 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 | }; |