Eric 2 年之前
父節點
當前提交
b59734cbcb

+ 15 - 8
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/handler/BaseAuthenticationFailureEvenHandler.java

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

+ 2 - 3
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/provider/PhoneAuthenticationProvider.java

@@ -15,7 +15,6 @@ import com.yonge.cooleshow.auth.service.SysUserDeviceService;
 import com.yonge.cooleshow.auth.service.SysUserService;
 import com.yonge.cooleshow.common.security.SecurityConstants;
 import com.yonge.cooleshow.common.service.IdGeneratorService;
-import com.yonge.toolset.base.exception.BizException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.security.authentication.BadCredentialsException;
@@ -104,7 +103,7 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
             // 根据用户授权openid,查询机构员工绑定信息
             SysUser sysUser = sysUserService.getSysUserByOpenId(openid, clientId);
             if (Objects.isNull(sysUser)) {
-                throw new BizException("用户不存在");
+                throw new UsernameNotFoundException("MA:404:" + openid);
             }
 
             // 重置登陆账号信息
@@ -133,7 +132,7 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
                     //获取jwt原始内容
                     String claims = jwt.getClaims();
                     if (StringUtils.isEmpty(claims)) {
-                        throw new BizException("三方授权校验失败");
+                        throw new BadCredentialsException("三方授权校验失败");
                     }
                     log.info("retrieveUser claims={}", claims);
                 } catch (Exception e) {