Commit 72342a61 authored by 向怀芳's avatar 向怀芳 🎱

1. 处理账号登录锁定,返回状态码423

parent 4cf1983e
...@@ -17,6 +17,8 @@ import org.springframework.security.oauth2.provider.error.WebResponseExceptionTr ...@@ -17,6 +17,8 @@ import org.springframework.security.oauth2.provider.error.WebResponseExceptionTr
import org.springframework.security.web.util.ThrowableAnalyzer; import org.springframework.security.web.util.ThrowableAnalyzer;
import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;
import javax.security.auth.login.AccountLockedException;
/** /**
* @Description * @Description
* @Author * @Author
...@@ -37,6 +39,9 @@ public class SictWebResponseExceptionTranslator implements WebResponseExceptionT ...@@ -37,6 +39,9 @@ public class SictWebResponseExceptionTranslator implements WebResponseExceptionT
Exception ase = (AuthenticationException) throwableAnalyzer.getFirstThrowableOfType(AuthenticationException.class, Exception ase = (AuthenticationException) throwableAnalyzer.getFirstThrowableOfType(AuthenticationException.class,
causeChain); causeChain);
if (ase != null) { if (ase != null) {
if(ase instanceof AccountLockedException){
return handleOAuth2Exception(new UnauthorizedException(e.getMessage(), e, HttpStatus.LOCKED.value()));
}
return handleOAuth2Exception(new UnauthorizedException(e.getMessage(), e)); return handleOAuth2Exception(new UnauthorizedException(e.getMessage(), e));
} }
......
package cn.sh.stc.sict.cloud.common.security.exception; 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 cn.sh.stc.sict.cloud.common.security.component.SictAuth2ExceptionSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
/** /**
* @author lengleng * @author F_xh
* @date 2018/7/8 * @date 2018/7/8
*/ */
@JsonSerialize(using = SictAuth2ExceptionSerializer.class) @JsonSerialize(using = SictAuth2ExceptionSerializer.class)
public class UnauthorizedException extends SictAuth2Exception { public class UnauthorizedException extends SictAuth2Exception {
private Integer httpErrorCode;
public UnauthorizedException(String msg, Throwable t) { public UnauthorizedException(String msg, Throwable t) {
super(msg); super(msg);
} }
@Override public UnauthorizedException(String msg, Throwable t, Integer httpErrorCode) {
public String getOAuth2ErrorCode() { super(msg);
return "unauthorized"; this.httpErrorCode = httpErrorCode;
} }
@Override @Override
public int getHttpErrorCode() { public String getOAuth2ErrorCode() {
return HttpStatus.UNAUTHORIZED.value(); return "unauthorized";
} }
@Override
public int getHttpErrorCode() {
return NumberUtil.isNullOrZero(this.httpErrorCode) ? HttpStatus.UNAUTHORIZED.value() : this.httpErrorCode;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment