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(); }