From 8d0faea64136f2ed18b01bbefea00580d147d5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Tue, 22 Oct 2024 00:03:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(security):=20check-token=20=20token?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF=E6=97=B6?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #5998 --- .../pigx/auth/endpoint/PigxTokenEndpoint.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java index 3473eb08c..9f762ca8e 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/endpoint/PigxTokenEndpoint.java @@ -26,7 +26,6 @@ import com.pig4cloud.pigx.admin.api.entity.SysTenant; import com.pig4cloud.pigx.admin.api.feign.RemoteClientDetailsService; import com.pig4cloud.pigx.admin.api.feign.RemoteTenantService; import com.pig4cloud.pigx.admin.api.vo.TokenVO; -import com.pig4cloud.pigx.auth.support.handler.PigxAuthenticationFailureEventHandler; import com.pig4cloud.pigx.common.core.constant.CacheConstants; import com.pig4cloud.pigx.common.core.constant.CommonConstants; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; @@ -55,7 +54,6 @@ import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; import org.springframework.security.oauth2.server.authorization.OAuth2Authorization; import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService; import org.springframework.security.oauth2.server.authorization.OAuth2TokenType; -import org.springframework.security.oauth2.server.resource.InvalidBearerTokenException; import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; @@ -78,8 +76,6 @@ import java.util.stream.Collectors; @RequestMapping("/token") public class PigxTokenEndpoint { - private final PigxAuthenticationFailureEventHandler authenticationFailureHandler; - private final OAuth2AuthorizationService authorizationService; private final RemoteClientDetailsService clientDetailsService; @@ -153,16 +149,14 @@ public class PigxTokenEndpoint { if (StrUtil.isBlank(token)) { httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED); - this.authenticationFailureHandler.onAuthenticationFailure(request, response, - new InvalidBearerTokenException(OAuth2ErrorCodesExpand.TOKEN_MISSING)); - return R.failed(); + return R.failed(OAuth2ErrorCodesExpand.TOKEN_MISSING); } OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN); // 如果令牌不存在 返回401 if (authorization == null || authorization.getAccessToken() == null) { - this.authenticationFailureHandler.onAuthenticationFailure(request, response, - new InvalidBearerTokenException(OAuth2ErrorCodesExpand.INVALID_BEARER_TOKEN)); + httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED); + return R.failed(OAuth2ErrorCodesExpand.INVALID_BEARER_TOKEN); } // 获取令牌