From 8dfb6983c3d2196ddd8122dfed3c7af8b8fea2eb Mon Sep 17 00:00:00 2001 From: zlt2000 Date: Thu, 10 Dec 2020 23:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96oauth2=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/config/SecurityHandlerConfig.java | 16 +++++++++------- .../central/oauth/filter/OauthTokenAspect.java | 5 ----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java b/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java index 2867ac18..83f853c7 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java +++ b/zlt-uaa/src/main/java/com/central/oauth/config/SecurityHandlerConfig.java @@ -1,5 +1,6 @@ package com.central.oauth.config; +import com.central.oauth.exception.ValidateCodeException; import com.central.oauth.handler.OauthLogoutHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; @@ -34,19 +35,20 @@ public class SecurityHandlerConfig { @Bean public WebResponseExceptionTranslator webResponseExceptionTranslator() { return new DefaultWebResponseExceptionTranslator() { - public static final String BAD_MSG = "坏的凭证"; + private static final String BAD_MSG = "坏的凭证"; + private static final String BAD_MSG_EN = "Bad credentials"; @Override public ResponseEntity translate(Exception e) throws Exception { OAuth2Exception oAuth2Exception; - if (e.getMessage() != null && e.getMessage().equals(BAD_MSG)) { + if (e.getMessage() != null + && (BAD_MSG.equals(e.getMessage()) || BAD_MSG_EN.equals(e.getMessage()))) { oAuth2Exception = new InvalidGrantException("用户名或密码错误", e); - } else if (e instanceof InternalAuthenticationServiceException) { - oAuth2Exception = new InvalidGrantException(e.getMessage(), e); - } else if (e instanceof RedirectMismatchException) { - oAuth2Exception = new InvalidGrantException(e.getMessage(), e); - } else if (e instanceof InvalidScopeException) { + } else if (e instanceof InternalAuthenticationServiceException + || e instanceof ValidateCodeException) { oAuth2Exception = new InvalidGrantException(e.getMessage(), e); + } else if (e instanceof OAuth2Exception) { + oAuth2Exception = (OAuth2Exception)e; } else { oAuth2Exception = new UnsupportedResponseTypeException("服务内部错误", e); } diff --git a/zlt-uaa/src/main/java/com/central/oauth/filter/OauthTokenAspect.java b/zlt-uaa/src/main/java/com/central/oauth/filter/OauthTokenAspect.java index 694b4ef6..2468b66b 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/filter/OauthTokenAspect.java +++ b/zlt-uaa/src/main/java/com/central/oauth/filter/OauthTokenAspect.java @@ -63,11 +63,6 @@ public class OauthTokenAspect { .status(HttpStatus.OK) .body(Result.succeed(body)); } - } catch (Exception e) { - log.error("授权错误", e); - return ResponseEntity - .status(HttpStatus.BAD_REQUEST) - .body(Result.failed(e.getMessage())); } finally { TenantContextHolder.clear(); }