Commit fd832e23fd1d5395d385d92dad0a31d59fb6d95d
1 parent
07515741
bugfix:非 json 请求(文件上传)时,token 过期时,错误读取 request body 问题
Showing
6 changed files
with
14 additions
and
20 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java
| ... | ... | @@ -93,11 +93,19 @@ public class ServletUtils { |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | public static String getBody(HttpServletRequest request) { |
| 96 | - return JakartaServletUtil.getBody(request); | |
| 96 | + // 只有在 json 请求在读取,因为只有 CacheRequestBodyFilter 才会进行缓存,支持重复读取 | |
| 97 | + if (isJsonRequest(request)) { | |
| 98 | + return JakartaServletUtil.getBody(request); | |
| 99 | + } | |
| 100 | + return null; | |
| 97 | 101 | } |
| 98 | 102 | |
| 99 | 103 | public static byte[] getBodyBytes(HttpServletRequest request) { |
| 100 | - return JakartaServletUtil.getBodyBytes(request); | |
| 104 | + // 只有在 json 请求在读取,因为只有 CacheRequestBodyFilter 才会进行缓存,支持重复读取 | |
| 105 | + if (isJsonRequest(request)) { | |
| 106 | + return JakartaServletUtil.getBodyBytes(request); | |
| 107 | + } | |
| 108 | + return null; | |
| 101 | 109 | } |
| 102 | 110 | |
| 103 | 111 | public static String getClientIP(HttpServletRequest request) { | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/sql/clean.sql
| ... | ... | @@ -6,7 +6,6 @@ DELETE FROM "infra_job_log"; |
| 6 | 6 | DELETE FROM "infra_api_access_log"; |
| 7 | 7 | DELETE FROM "infra_api_error_log"; |
| 8 | 8 | DELETE FROM "infra_file_config"; |
| 9 | -DELETE FROM "infra_test_demo"; | |
| 10 | 9 | DELETE FROM "infra_data_source_config"; |
| 11 | 10 | DELETE FROM "infra_codegen_table"; |
| 12 | 11 | DELETE FROM "infra_codegen_column"; | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -146,21 +146,6 @@ CREATE TABLE IF NOT EXISTS "infra_api_error_log" ( |
| 146 | 146 | primary key ("id") |
| 147 | 147 | ) COMMENT '系统异常日志'; |
| 148 | 148 | |
| 149 | -CREATE TABLE IF NOT EXISTS "infra_test_demo" ( | |
| 150 | - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 151 | - "name" varchar(100) NOT NULL, | |
| 152 | - "status" tinyint NOT NULL, | |
| 153 | - "type" tinyint NOT NULL, | |
| 154 | - "category" tinyint NOT NULL, | |
| 155 | - "remark" varchar(500), | |
| 156 | - "creator" varchar(64) DEFAULT '''', | |
| 157 | - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 158 | - "updater" varchar(64) DEFAULT '''', | |
| 159 | - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 160 | - "deleted" bit NOT NULL DEFAULT FALSE, | |
| 161 | - PRIMARY KEY ("id") | |
| 162 | -) COMMENT '字典类型表'; | |
| 163 | - | |
| 164 | 149 | CREATE TABLE IF NOT EXISTS "infra_data_source_config" ( |
| 165 | 150 | "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 166 | 151 | "name" varchar(100) NOT NULL, | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/oauth2/OAuth2AccessTokenMapper.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.oauth2; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; | |
| 6 | 7 | import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; |
| 8 | 9 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -13,6 +14,7 @@ import java.util.List; |
| 13 | 14 | @Mapper |
| 14 | 15 | public interface OAuth2AccessTokenMapper extends BaseMapperX<OAuth2AccessTokenDO> { |
| 15 | 16 | |
| 17 | + @TenantIgnore // 获取 token 的时候,需要忽略租户编号。原因是:一些场景下,可能不会传递 tenant-id 请求头,例如说文件上传、积木报表等等 | |
| 16 | 18 | default OAuth2AccessTokenDO selectByAccessToken(String accessToken) { |
| 17 | 19 | return selectOne(OAuth2AccessTokenDO::getAccessToken, accessToken); |
| 18 | 20 | } | ... | ... |
yudao-server/src/main/resources/application-local.yaml
| ... | ... | @@ -165,10 +165,11 @@ logging: |
| 165 | 165 | # 配置自己写的 MyBatis Mapper 打印日志 |
| 166 | 166 | cn.iocoder.yudao.module.bpm.dal.mysql: debug |
| 167 | 167 | cn.iocoder.yudao.module.infra.dal.mysql: debug |
| 168 | + cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiErrorLogMapper: INFO # 配置 ApiErrorLogMapper 的日志级别为 info,避免和 GlobalExceptionHandler 重复打印 | |
| 168 | 169 | cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper: INFO # 配置 JobLogMapper 的日志级别为 info |
| 169 | 170 | cn.iocoder.yudao.module.infra.dal.mysql.file.FileConfigMapper: INFO # 配置 FileConfigMapper 的日志级别为 info |
| 170 | 171 | cn.iocoder.yudao.module.pay.dal.mysql: debug |
| 171 | - cn.iocoder.yudao.module.pay.dal.mysql.notify.PayNotifyTaskMapper: INFO # 配置 JobLogMapper 的日志级别为 info | |
| 172 | + cn.iocoder.yudao.module.pay.dal.mysql.notify.PayNotifyTaskMapper: INFO # 配置 PayNotifyTaskMapper 的日志级别为 info | |
| 172 | 173 | cn.iocoder.yudao.module.system.dal.mysql: debug |
| 173 | 174 | cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper: INFO # 配置 SmsChannelMapper 的日志级别为 info |
| 174 | 175 | cn.iocoder.yudao.module.tool.dal.mysql: debug | ... | ... |
yudao-server/src/main/resources/application.yaml