From d071985eca1152202dd77b410d305ded8bc38425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 23 Feb 2018 09:13:42 +0800 Subject: [PATCH] =?UTF-8?q?fixed=EF=BC=9A=20=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/component/PigWebResponseExceptionTranslator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java b/pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java index ab9db0ee..3cf8b0e4 100644 --- a/pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java +++ b/pig-auth/src/main/java/com/github/pig/auth/component/PigWebResponseExceptionTranslator.java @@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.InternalAuthenticationServiceException; import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; +import org.springframework.security.oauth2.common.exceptions.UnsupportedResponseTypeException; import org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator; import org.springframework.stereotype.Component; @@ -25,6 +26,8 @@ import org.springframework.stereotype.Component; @Component public class PigWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator { + public static final String BAD_MSG = "坏的凭证"; + /** * @param e spring security内部异常 * @return 经过处理的异常信息 @@ -33,12 +36,12 @@ public class PigWebResponseExceptionTranslator extends DefaultWebResponseExcepti @Override public ResponseEntity translate(Exception e) throws Exception { OAuth2Exception oAuth2Exception; - if (e instanceof InvalidGrantException && StringUtils.equals("坏的凭证",e.getMessage())) { + if (e instanceof InvalidGrantException && StringUtils.equals(BAD_MSG, e.getMessage())) { oAuth2Exception = new InvalidGrantException("密码错误", e); } else if (e instanceof InternalAuthenticationServiceException) { oAuth2Exception = new InvalidGrantException("用户名不存在", e); } else { - oAuth2Exception = (OAuth2Exception) e; + oAuth2Exception = new UnsupportedResponseTypeException("服务处理异常", e); } return super.translate(oAuth2Exception); }