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

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

parent 4cf1983e
......@@ -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));
}
......
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;
}
}
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