Commit 92ace031fe17017ae577cf2e7ca3979fae9ebe21

Authored by YunaiV
1 parent 3310b766

【修复】访问数据库存储的文件,path 多层级时,无法访问的问题

yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
1 package cn.iocoder.yudao.module.infra.controller.admin.file; 1 package cn.iocoder.yudao.module.infra.controller.admin.file;
2 2
3 import cn.hutool.core.io.IoUtil; 3 import cn.hutool.core.io.IoUtil;
  4 +import cn.hutool.core.util.StrUtil;
4 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; 7 import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
@@ -13,7 +14,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; @@ -13,7 +14,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
13 import cn.iocoder.yudao.module.infra.service.file.FileService; 14 import cn.iocoder.yudao.module.infra.service.file.FileService;
14 import io.swagger.annotations.Api; 15 import io.swagger.annotations.Api;
15 import io.swagger.annotations.ApiImplicitParam; 16 import io.swagger.annotations.ApiImplicitParam;
16 -import io.swagger.annotations.ApiImplicitParams;  
17 import io.swagger.annotations.ApiOperation; 17 import io.swagger.annotations.ApiOperation;
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 import org.springframework.http.HttpStatus; 19 import org.springframework.http.HttpStatus;
@@ -24,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile; @@ -24,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
24 24
25 import javax.annotation.Resource; 25 import javax.annotation.Resource;
26 import javax.annotation.security.PermitAll; 26 import javax.annotation.security.PermitAll;
  27 +import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse; 28 import javax.servlet.http.HttpServletResponse;
28 import javax.validation.Valid; 29 import javax.validation.Valid;
29 30
@@ -57,16 +58,20 @@ public class FileController { @@ -57,16 +58,20 @@ public class FileController {
57 return success(true); 58 return success(true);
58 } 59 }
59 60
60 - @GetMapping("/{configId}/get/{path}") 61 + @GetMapping("/{configId}/get/**")
61 @PermitAll 62 @PermitAll
62 @ApiOperation("下载文件") 63 @ApiOperation("下载文件")
63 - @ApiImplicitParams({  
64 - @ApiImplicitParam(name = "configId", value = "配置编号", required = true, dataTypeClass = Long.class),  
65 - @ApiImplicitParam(name = "path", value = "文件路径", required = true, dataTypeClass = String.class)  
66 - })  
67 - public void getFileContent(HttpServletResponse response,  
68 - @PathVariable("configId") Long configId,  
69 - @PathVariable("path") String path) throws Exception { 64 + @ApiImplicitParam(name = "configId", value = "配置编号", required = true, dataTypeClass = Long.class)
  65 + public void getFileContent(HttpServletRequest request,
  66 + HttpServletResponse response,
  67 + @PathVariable("configId") Long configId) throws Exception {
  68 + // 获取请求的路径
  69 + String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false);
  70 + if (StrUtil.isEmpty(path)) {
  71 + throw new IllegalArgumentException("结尾的 path 路径必须传递");
  72 + }
  73 +
  74 + // 读取内容
70 byte[] content = fileService.getFileContent(configId, path); 75 byte[] content = fileService.getFileContent(configId, path);
71 if (content == null) { 76 if (content == null) {
72 log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path); 77 log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java
@@ -27,7 +27,7 @@ public class SecurityConfiguration { @@ -27,7 +27,7 @@ public class SecurityConfiguration {
27 .antMatchers("/swagger-resources/**").anonymous() 27 .antMatchers("/swagger-resources/**").anonymous()
28 .antMatchers("/webjars/**").anonymous() 28 .antMatchers("/webjars/**").anonymous()
29 .antMatchers("/*/api-docs").anonymous(); 29 .antMatchers("/*/api-docs").anonymous();
30 - //积木报表 30 + // 积木报表
31 registry.antMatchers("/jmreport/**").permitAll(); 31 registry.antMatchers("/jmreport/**").permitAll();
32 // Spring Boot Actuator 的安全配置 32 // Spring Boot Actuator 的安全配置
33 registry.antMatchers("/actuator").anonymous() 33 registry.antMatchers("/actuator").anonymous()
@@ -37,6 +37,8 @@ public class SecurityConfiguration { @@ -37,6 +37,8 @@ public class SecurityConfiguration {
37 // Spring Boot Admin Server 的安全配置 37 // Spring Boot Admin Server 的安全配置
38 registry.antMatchers(adminSeverContextPath).anonymous() 38 registry.antMatchers(adminSeverContextPath).anonymous()
39 .antMatchers(adminSeverContextPath + "/**").anonymous(); 39 .antMatchers(adminSeverContextPath + "/**").anonymous();
  40 + // 文件读取
  41 + registry.antMatchers(buildAdminApi("/infra/file/*/get/**")).permitAll();
40 } 42 }
41 43
42 }; 44 };
yudao-server/pom.xml
@@ -68,11 +68,11 @@ @@ -68,11 +68,11 @@
68 <!-- <version>${revision}</version>--> 68 <!-- <version>${revision}</version>-->
69 <!-- </dependency>--> 69 <!-- </dependency>-->
70 <!-- 工作流 --> 70 <!-- 工作流 -->
71 - <dependency>  
72 - <groupId>cn.iocoder.boot</groupId>  
73 - <artifactId>yudao-module-bpm-biz</artifactId>  
74 - <version>${revision}</version>  
75 - </dependency> 71 +<!-- <dependency>-->
  72 +<!-- <groupId>cn.iocoder.boot</groupId>-->
  73 +<!-- <artifactId>yudao-module-bpm-biz</artifactId>-->
  74 +<!-- <version>${revision}</version>-->
  75 +<!-- </dependency>-->
76 <dependency> 76 <dependency>
77 <groupId>cn.iocoder.boot</groupId> 77 <groupId>cn.iocoder.boot</groupId>
78 <artifactId>yudao-spring-boot-starter-biz-error-code</artifactId> 78 <artifactId>yudao-spring-boot-starter-biz-error-code</artifactId>