From c5aaca51633b256d33e17937b1c9dff4050e190a Mon Sep 17 00:00:00 2001 From: "wei.zhang2" Date: Mon, 16 Oct 2017 09:37:05 +0800 Subject: [PATCH] 1 --- .../security/server/config/SecurityHandlerConfig.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/boot/security/server/config/SecurityHandlerConfig.java b/src/main/java/com/boot/security/server/config/SecurityHandlerConfig.java index c42cb47..6c624d6 100644 --- a/src/main/java/com/boot/security/server/config/SecurityHandlerConfig.java +++ b/src/main/java/com/boot/security/server/config/SecurityHandlerConfig.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; +import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.AuthenticationFailureHandler; @@ -67,8 +68,14 @@ public class SecurityHandlerConfig { @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { - ResponseInfo info = ResponseInfo.builder().code(HttpStatus.UNAUTHORIZED.value() + "") - .message(exception.getMessage()).build(); + String msg = null; + if (exception instanceof BadCredentialsException) { + msg = "密码错误"; + } else { + msg = exception.getMessage(); + } + ResponseInfo info = ResponseInfo.builder().code(HttpStatus.UNAUTHORIZED.value() + "").message(msg) + .build(); ResponseUtil.responseJson(response, HttpStatus.UNAUTHORIZED.value(), info); } };