Commit d00a88a75ddb8638c86b34fbd5daec578ad521ea
1 parent
5b1e6c0d
修改积木报表相关访问配置
Showing
7 changed files
with
58 additions
and
70 deletions
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/filter/TokenAuthenticationFilter.java
| ... | ... | @@ -37,34 +37,13 @@ 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 | - | |
| 54 | 40 | @Override |
| 55 | 41 | @SuppressWarnings("NullableProblems") |
| 56 | 42 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) |
| 57 | 43 | throws ServletException, IOException { |
| 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 | - } | |
| 44 | + String token = SecurityFrameworkUtils.obtainAuthorization(request, securityProperties.getTokenHeader()); | |
| 67 | 45 | if (StrUtil.isNotEmpty(token)) { |
| 46 | + Integer userType = WebFrameworkUtils.getLoginUserType(request); | |
| 68 | 47 | try { |
| 69 | 48 | // 1.1 基于 token 构建登录用户 |
| 70 | 49 | LoginUser loginUser = buildLoginUserByToken(token, userType); |
| ... | ... | @@ -109,11 +88,11 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { |
| 109 | 88 | |
| 110 | 89 | /** |
| 111 | 90 | * 模拟登录用户,方便日常开发调试 |
| 112 | - * <p> | |
| 91 | + * | |
| 113 | 92 | * 注意,在线上环境下,一定要关闭该功能!!! |
| 114 | 93 | * |
| 115 | - * @param request 请求 | |
| 116 | - * @param token 模拟的 token,格式为 {@link SecurityProperties#getMockSecret()} + 用户编号 | |
| 94 | + * @param request 请求 | |
| 95 | + * @param token 模拟的 token,格式为 {@link SecurityProperties#getMockSecret()} + 用户编号 | |
| 117 | 96 | * @param userType 用户类型 |
| 118 | 97 | * @return 模拟的 LoginUser |
| 119 | 98 | */ | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/util/SecurityFrameworkUtils.java
| ... | ... | @@ -25,20 +25,6 @@ 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 | - /** | |
| 42 | 28 | * 从请求中,获得认证 Token |
| 43 | 29 | * |
| 44 | 30 | * @param request 请求 |
| ... | ... | @@ -46,9 +32,6 @@ public class SecurityFrameworkUtils { |
| 46 | 32 | * @return 认证 Token |
| 47 | 33 | */ |
| 48 | 34 | public static String obtainAuthorization(HttpServletRequest request, String header) { |
| 49 | - if (request.getRequestURI().startsWith("/jmreport/")) { | |
| 50 | - return getToken(request); | |
| 51 | - } | |
| 52 | 35 | String authorization = request.getHeader(header); |
| 53 | 36 | if (!StringUtils.hasText(authorization)) { |
| 54 | 37 | return null; | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java
| ... | ... | @@ -27,6 +27,8 @@ public class SecurityConfiguration { |
| 27 | 27 | .antMatchers("/swagger-resources/**").anonymous() |
| 28 | 28 | .antMatchers("/webjars/**").anonymous() |
| 29 | 29 | .antMatchers("/*/api-docs").anonymous(); |
| 30 | + //积木报表 | |
| 31 | + registry.antMatchers("/jmreport/**").permitAll(); | |
| 30 | 32 | // Spring Boot Actuator 的安全配置 |
| 31 | 33 | registry.antMatchers("/actuator").anonymous() |
| 32 | 34 | .antMatchers("/actuator/**").anonymous(); | ... | ... |
yudao-module-visualization/yudao-module-visualization-biz/pom.xml
| ... | ... | @@ -23,6 +23,12 @@ |
| 23 | 23 | <version>${revision}</version> |
| 24 | 24 | </dependency> |
| 25 | 25 | |
| 26 | + <dependency> | |
| 27 | + <groupId>cn.iocoder.boot</groupId> | |
| 28 | + <artifactId>yudao-module-system-biz</artifactId> | |
| 29 | + <version>${revision}</version> | |
| 30 | + </dependency> | |
| 31 | + | |
| 26 | 32 | <!-- 业务组件 --> |
| 27 | 33 | <dependency> |
| 28 | 34 | <groupId>cn.iocoder.boot</groupId> |
| ... | ... | @@ -57,5 +63,6 @@ |
| 57 | 63 | <groupId>org.jeecgframework.jimureport</groupId> |
| 58 | 64 | <artifactId>jimureport-spring-boot-starter</artifactId> |
| 59 | 65 | </dependency> |
| 66 | + | |
| 60 | 67 | </dependencies> |
| 61 | 68 | </project> |
| 62 | 69 | \ No newline at end of file | ... | ... |
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/config/JimuReportTokenService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.visualization.config; | |
| 2 | + | |
| 3 | +import cn.hutool.core.util.StrUtil; | |
| 4 | +import cn.iocoder.yudao.module.system.api.oauth2.OAuth2TokenApi; | |
| 5 | +import cn.iocoder.yudao.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO; | |
| 6 | +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | |
| 7 | +import cn.iocoder.yudao.module.system.service.user.AdminUserService; | |
| 8 | +import org.jeecg.modules.jmreport.api.JmReportTokenServiceI; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +@Component | |
| 13 | +public class JimuReportTokenService implements JmReportTokenServiceI { | |
| 14 | + @Autowired | |
| 15 | + private OAuth2TokenApi oauth2TokenApi; | |
| 16 | + | |
| 17 | + @Autowired | |
| 18 | + private AdminUserService adminUserService; | |
| 19 | + | |
| 20 | + @Override | |
| 21 | + public String getUsername(String token) { | |
| 22 | + if (StrUtil.isNotEmpty(token)) { | |
| 23 | + OAuth2AccessTokenCheckRespDTO accessToken = oauth2TokenApi.checkAccessToken(token); | |
| 24 | + if (accessToken != null) { | |
| 25 | + Long userId = accessToken.getUserId(); | |
| 26 | + System.out.println(userId); | |
| 27 | + AdminUserDO user = adminUserService.getUser(userId); | |
| 28 | + if (user != null) { | |
| 29 | + return user.getUsername(); | |
| 30 | + } | |
| 31 | + } | |
| 32 | + } | |
| 33 | + return null; | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Override | |
| 37 | + public Boolean verifyToken(String token) { | |
| 38 | + if (StrUtil.isNotEmpty(token)) { | |
| 39 | + OAuth2AccessTokenCheckRespDTO accessToken = oauth2TokenApi.checkAccessToken(token); | |
| 40 | + return accessToken != null; | |
| 41 | + } | |
| 42 | + return false; | |
| 43 | + } | |
| 44 | +} | |
| 0 | 45 | \ No newline at end of file | ... | ... |
yudao-module-visualization/yudao-module-visualization-biz/src/main/java/cn/iocoder/yudao/module/visualization/framework/security/config/SecurityConfiguration.java deleted
| 1 | -package cn.iocoder.yudao.module.visualization.framework.security.config; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; | |
| 4 | -import org.springframework.context.annotation.Bean; | |
| 5 | -import org.springframework.context.annotation.Configuration; | |
| 6 | -import org.springframework.http.HttpMethod; | |
| 7 | -import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
| 8 | -import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * visualization 模块的 Security 配置 | |
| 12 | - */ | |
| 13 | -@Configuration("visualizationSecurityConfiguration") | |
| 14 | -public class SecurityConfiguration { | |
| 15 | - | |
| 16 | - @Bean("visualizationAuthorizeRequestsCustomizer") | |
| 17 | - public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { | |
| 18 | - return new AuthorizeRequestsCustomizer() { | |
| 19 | - @Override | |
| 20 | - public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { | |
| 21 | - registry.antMatchers(HttpMethod.GET, "/jmreport/**").permitAll(); | |
| 22 | - } | |
| 23 | - }; | |
| 24 | - } | |
| 25 | - | |
| 26 | -} |