diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserRoleController.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserRoleController.java deleted file mode 100644 index d1e51fa..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/controller/UserRoleController.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ningdatech.pmapi.user.controller; - - -import org.springframework.web.bind.annotation.RequestMapping; - -import org.springframework.stereotype.Controller; - -/** - *
- * 用户角色表 前端控制器 - *
- * - * @author Liuxinxin - * @since 2023-01-05 - */ -@Controller -@RequestMapping("/pmapi.user/user-role") -public class UserRoleController { - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java index e6a9128..b797168 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/agent/AgentAuthFilter.java @@ -53,7 +53,7 @@ public class AgentAuthFilter extends AbstractAuthenticationProcessingFilter { setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); } catch (AuthenticationException e) { - throw new BadCredentialsException("账号或密码错误"); + throw new BadCredentialsException("用户id 不能为空"); } catch (BizException e) { throw new BadCredentialsException(e.getMessage()); } catch (Exception e) { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java index 1ecfa09..671906b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialAuthFilter.java @@ -2,6 +2,7 @@ package com.ningdatech.pmapi.user.security.auth.credential; import com.ningdatech.basic.exception.BizException; import com.ningdatech.pmapi.user.constant.LoginTypeEnum; +import com.ningdatech.pmapi.user.security.auth.validate.CommonLoginException; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.AuthenticationServiceException; @@ -53,7 +54,6 @@ public class CredentialAuthFilter extends AbstractAuthenticationProcessingFilter } paramValid(identifier, credential, loginType); - identifier = trim(identifier); credential = trim(credential); loginType = trim(loginType); @@ -62,6 +62,10 @@ public class CredentialAuthFilter extends AbstractAuthenticationProcessingFilter // Allow subclasses to set the "details" property setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); + } catch (CommonLoginException e) { + throw new CommonLoginException(e.getMessage()); + } catch (BadCredentialsException e) { + throw new BadCredentialsException(e.getMessage()); } catch (AuthenticationException e) { throw new BadCredentialsException("账号或密码错误"); } catch (BizException e) { @@ -80,19 +84,19 @@ public class CredentialAuthFilter extends AbstractAuthenticationProcessingFilter switch (loginTypeEnum) { case DING_QR_LOGIN: { if (StringUtils.isBlank(credential)) { - throw new BadCredentialsException("浙政钉扫码登陆 授权码 不能为空 credential"); + throw new CommonLoginException("浙政钉扫码登陆 授权码 不能为空 credential"); } } break; case USERNAME_PASSWORD_LOGIN: { if (StringUtils.isBlank(identifier) || StringUtils.isBlank(credential)) { - throw new BadCredentialsException("账号密码登陆 账号密码不能为空 identifier credential"); + throw new CommonLoginException("账号密码登陆 账号密码不能为空 identifier credential"); } } break; case PHONE_VERIFICATION_CODE_LOGIN: { if (StringUtils.isBlank(identifier) || StringUtils.isBlank(credential)) { - throw new BadCredentialsException("手机号验证码登陆 手机号或验证码不能为空 identifier credential"); + throw new CommonLoginException("手机号验证码登陆 手机号或验证码不能为空 identifier credential"); } } break; diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java index cf1ebc7..8b5d8fa 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultLoginFailureHandler.java @@ -3,6 +3,7 @@ package com.ningdatech.pmapi.user.security.auth.handler; import com.fasterxml.jackson.databind.ObjectMapper; import com.ningdatech.basic.model.ApiResponse; import com.ningdatech.pmapi.user.security.auth.errorcode.AuthErrorCodeEnum; +import com.ningdatech.pmapi.user.security.auth.validate.CommonLoginException; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -32,7 +33,10 @@ public class DefaultLoginFailureHandler extends SimpleUrlAuthenticationFailureHa String errorMsg; // 所有的认证异常都可以在这里添加,目前只支持用户名密码错误异常 - if (exception instanceof BadCredentialsException || exception instanceof UsernameNotFoundException) { + if (exception instanceof CommonLoginException) { + errorCode = 400; + errorMsg = exception.getMessage(); + } else if (exception instanceof BadCredentialsException || exception instanceof UsernameNotFoundException) { errorCode = AuthErrorCodeEnum.USERNAME_OR_PASSWORD_ERROR.getCode(); errorMsg = exception.getMessage(); } else { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/CommonLoginException.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/CommonLoginException.java new file mode 100644 index 0000000..a399f2e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/CommonLoginException.java @@ -0,0 +1,17 @@ +package com.ningdatech.pmapi.user.security.auth.validate; + +import org.springframework.security.core.AuthenticationException; + +/** + * @author liuxinxin + * @date 2023/3/24 上午11:47 + * 通用登陆错误 + */ +public class CommonLoginException extends AuthenticationException { + + public CommonLoginException(String message) { + super(message); + } + + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java index c9fb080..a7616ea 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/validate/DingQrLoginException.java @@ -1,10 +1,14 @@ package com.ningdatech.pmapi.user.security.auth.validate; +import lombok.Data; + /** * @author liuxinxin * @date 2023/3/24 上午11:47 + * 浙政钉扫码登陆错误 */ +@Data public class DingQrLoginException extends RuntimeException { private Integer code;