zhangxin hace 1 semana
padre
commit
22a30936d1

+ 1 - 1
yami-shop-security/yami-shop-security-comment/src/main/java/com/yami/shop/security/comment/exception/BaseYamiAuth2Exception.java

@@ -23,7 +23,7 @@ public abstract class BaseYamiAuth2Exception extends AuthenticationException {
 
 	public int getHttpErrorCode() {
 		// 400 not 401
-		return HttpStatus.BAD_REQUEST.value();
+		return HttpStatus.INTERNAL_SERVER_ERROR.value();
 	}
 
 	public abstract String getOAuth2ErrorCode();

+ 1 - 1
yami-shop-security/yami-shop-security-comment/src/main/java/com/yami/shop/security/comment/filter/YamiAuthenticationProcessingFilter.java

@@ -143,7 +143,7 @@ public class YamiAuthenticationProcessingFilter extends AbstractAuthenticationPr
         RedisUtil.del(kaptchaKey);
 
         if(StrUtil.isBlank(authenticationToken.getImageCode()) || !authenticationToken.getImageCode().equalsIgnoreCase(kaptcha)){
-            throw new GlobalException("验证码有误或已过期");
+            throw new BadCredentialsException("验证码有误或已过期");
         }
     }
 

+ 6 - 2
yami-shop-security/yami-shop-security-comment/src/main/java/com/yami/shop/security/comment/handler/LoginAuthFailedHandler.java

@@ -11,6 +11,8 @@
 package com.yami.shop.security.comment.handler;
 
 import cn.hutool.core.util.CharsetUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.yami.shop.common.util.R;
 import com.yami.shop.security.comment.exception.BaseYamiAuth2Exception;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -23,13 +25,14 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.PrintWriter;
 
+
 /**
  * 登陆失败处理
  */
 @Component
 @Slf4j
 public class LoginAuthFailedHandler implements AuthenticationFailureHandler {
-
+    private final ObjectMapper objectMapper = new ObjectMapper();
     /**
      * {@inheritDoc}
      */
@@ -48,7 +51,8 @@ public class LoginAuthFailedHandler implements AuthenticationFailureHandler {
         response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
         response.setStatus(auth2Exception.getHttpErrorCode());
         PrintWriter printWriter = response.getWriter();
-        printWriter.append(auth2Exception.getMessage());
+        objectMapper.writeValue(printWriter, R.FAIL(auth2Exception.getMessage()));
+//        printWriter.append(auth2Exception.getMessage());
     }
 
 }