From ec4c6ce9b76e21592b503b2d48e161b025043ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Tue, 26 Nov 2024 12:38:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(security):=20sa-token=20=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E4=BB=A4=E7=89=8C=20424=20json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/security/config/ResourceServerConfiguration.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/config/ResourceServerConfiguration.java b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/config/ResourceServerConfiguration.java index ef54b0e9..9c62f4f4 100644 --- a/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/config/ResourceServerConfiguration.java +++ b/pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/config/ResourceServerConfiguration.java @@ -8,13 +8,16 @@ import cn.dev33.satoken.oauth2.template.SaOAuth2Util; import cn.dev33.satoken.router.SaRouter; import cn.dev33.satoken.stp.SaLoginConfig; import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.json.JSONUtil; import com.pig4cloud.pig.common.core.util.R; import com.pig4cloud.pig.common.core.util.WebUtils; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Lazy; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -60,8 +63,9 @@ public class ResourceServerConfiguration implements WebMvcConfigurer { }); }).setError(e -> { // 校验令牌失败 424 (主要是和401区分) + SaHolder.getResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); SaHolder.getResponse().setStatus(HttpStatus.FAILED_DEPENDENCY.value()); - return R.failed(e.getMessage()); + return JSONUtil.toJsonStr(R.failed(e.getMessage())); }); for (String url : permitAllUrlProperties.getUrls()) {