|
@@ -1,10 +1,7 @@
|
|
|
package com.yonge.cooleshow.auth.core.handler;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import org.apache.http.HttpStatus;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -13,8 +10,9 @@ import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
@Component
|
|
|
public class BaseAuthenticationFailureEvenHandler extends ExceptionMappingAuthenticationFailureHandler {
|
|
@@ -30,6 +28,8 @@ public class BaseAuthenticationFailureEvenHandler extends ExceptionMappingAuthen
|
|
|
int resultCode = HttpStatus.SC_CONFLICT;
|
|
|
|
|
|
String message = exception.getLocalizedMessage();
|
|
|
+
|
|
|
+ String data = null;
|
|
|
if (message.equals("Bad credentials")) {
|
|
|
message = "用户名或密码错误";
|
|
|
}else if(message.equals("User is disabled")){
|
|
@@ -37,9 +37,16 @@ public class BaseAuthenticationFailureEvenHandler extends ExceptionMappingAuthen
|
|
|
}else if(message.equals("404.9")){
|
|
|
message = "用户名或密码错误";
|
|
|
resultCode = 99;
|
|
|
+ } else if (message.startsWith("MA:404:")) {
|
|
|
+ // 返回用户绑定openId
|
|
|
+ data = message.split(":")[2];
|
|
|
+ // 用户未绑定openId错误码
|
|
|
+ resultCode = 5001;
|
|
|
+ // 用户未绑定openId错误信息
|
|
|
+ message = "用户未绑定小程序账号";
|
|
|
}
|
|
|
logger.info("登录失败,异常:{}", message);
|
|
|
- HttpResponseResult result = new HttpResponseResult(false, resultCode, null, message);
|
|
|
+ HttpResponseResult result = new HttpResponseResult(false, resultCode, data, message);
|
|
|
response.setContentType("application/json; charset=utf-8");
|
|
|
response.getWriter().write(objectMapper.writeValueAsString(result));
|
|
|
}
|