From 72342a61da39fc5574b662f1de5a4ca9cc228223 Mon Sep 17 00:00:00 2001 From: fshenye <512914587@qq.com> Date: Fri, 21 Oct 2022 16:50:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A4=84=E7=90=86=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=94=81=E5=AE=9A=EF=BC=8C=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=A0=81423?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SictWebResponseExceptionTranslator.java | 5 +++ .../exception/UnauthorizedException.java | 31 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictWebResponseExceptionTranslator.java b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictWebResponseExceptionTranslator.java index 9cd928e..bd68dae 100644 --- a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictWebResponseExceptionTranslator.java +++ b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/component/SictWebResponseExceptionTranslator.java @@ -17,6 +17,8 @@ import org.springframework.security.oauth2.provider.error.WebResponseExceptionTr import org.springframework.security.web.util.ThrowableAnalyzer; import org.springframework.web.HttpRequestMethodNotSupportedException; +import javax.security.auth.login.AccountLockedException; + /** * @Description * @Author @@ -37,6 +39,9 @@ public class SictWebResponseExceptionTranslator implements WebResponseExceptionT Exception ase = (AuthenticationException) throwableAnalyzer.getFirstThrowableOfType(AuthenticationException.class, causeChain); if (ase != null) { + if(ase instanceof AccountLockedException){ + return handleOAuth2Exception(new UnauthorizedException(e.getMessage(), e, HttpStatus.LOCKED.value())); + } return handleOAuth2Exception(new UnauthorizedException(e.getMessage(), e)); } diff --git a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/exception/UnauthorizedException.java b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/exception/UnauthorizedException.java index 08a3675..96f02d0 100644 --- a/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/exception/UnauthorizedException.java +++ b/cloud-common/cloud-common-security/src/main/java/cn/sh/stc/sict/cloud/common/security/exception/UnauthorizedException.java @@ -1,28 +1,35 @@ package cn.sh.stc.sict.cloud.common.security.exception; +import cn.sh.stc.sict.cloud.common.core.util.NumberUtil; import cn.sh.stc.sict.cloud.common.security.component.SictAuth2ExceptionSerializer; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.springframework.http.HttpStatus; /** - * @author lengleng + * @author F_xh * @date 2018/7/8 */ @JsonSerialize(using = SictAuth2ExceptionSerializer.class) public class UnauthorizedException extends SictAuth2Exception { + private Integer httpErrorCode; - public UnauthorizedException(String msg, Throwable t) { - super(msg); - } + public UnauthorizedException(String msg, Throwable t) { + super(msg); + } - @Override - public String getOAuth2ErrorCode() { - return "unauthorized"; - } + public UnauthorizedException(String msg, Throwable t, Integer httpErrorCode) { + super(msg); + this.httpErrorCode = httpErrorCode; + } - @Override - public int getHttpErrorCode() { - return HttpStatus.UNAUTHORIZED.value(); - } + @Override + public String getOAuth2ErrorCode() { + return "unauthorized"; + } + + @Override + public int getHttpErrorCode() { + return NumberUtil.isNullOrZero(this.httpErrorCode) ? HttpStatus.UNAUTHORIZED.value() : this.httpErrorCode; + } } -- 2.22.0