mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
token校验返回异常信息,未排单查询大板SQL更改
This commit is contained in:
+27
@@ -1,6 +1,8 @@
|
||||
package com.cf.imes.gateway.filter.security;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import com.cf.imes.framework.common.exception.ErrorCode;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.gateway.util.SecurityFrameworkUtils;
|
||||
@@ -21,6 +23,8 @@ import reactor.core.publisher.Mono;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* Token 过滤器,验证 token 的有效性
|
||||
* 1. 验证通过时,将 userId、userType、organId 通过 Header 转发给服务
|
||||
@@ -37,6 +41,10 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
|
||||
private static final TypeReference<CommonResult<OAuth2AccessTokenCheckRespDTO>> CHECK_RESULT_TYPE_REFERENCE
|
||||
= new TypeReference<CommonResult<OAuth2AccessTokenCheckRespDTO>>() {};
|
||||
|
||||
|
||||
private static final TypeReference<CommonResult> TOKEN_RESULT
|
||||
= new TypeReference<CommonResult>() {};
|
||||
|
||||
/**
|
||||
* 空的 LoginUser 的结果
|
||||
*
|
||||
@@ -104,6 +112,25 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
|
||||
}
|
||||
|
||||
private LoginUser buildUser(String body) {
|
||||
|
||||
CommonResult commonResult = JsonUtils.parseObject(body, TOKEN_RESULT);
|
||||
if(commonResult != null) {
|
||||
Integer code = commonResult.getCode();
|
||||
String msg = commonResult.getMsg();
|
||||
if(code != 0) {
|
||||
if (TOKEN_TIME_IS_EXPIRES.getCode().equals(code)) {
|
||||
throw new ServiceException(TOKEN_TIME_IS_EXPIRES);
|
||||
} else if (TOKEN_CONFIG_NOT_EXISTS.getCode().equals(code)) {
|
||||
throw new ServiceException(TOKEN_CONFIG_NOT_EXISTS);
|
||||
} else if (ORGAN_NOT_EXISTS.getCode().equals(code)) {
|
||||
throw new ServiceException(ORGAN_NOT_EXISTS);
|
||||
} else if (ORGAN_DISABLE.getCode().equals(code)) {
|
||||
throw new ServiceException(new ErrorCode(code, msg));
|
||||
} else if (ORGAN_EXPIRE.getCode().equals(code)) {
|
||||
throw new ServiceException(new ErrorCode(code, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理结果,结果不正确
|
||||
CommonResult<OAuth2AccessTokenCheckRespDTO> result = JsonUtils.parseObject(body, CHECK_RESULT_TYPE_REFERENCE);
|
||||
if (result == null) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cf.imes.gateway.handler;
|
||||
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.gateway.util.WebFrameworkUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -39,7 +40,10 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler {
|
||||
CommonResult result;
|
||||
if (ex instanceof ResponseStatusException) {
|
||||
result = responseStatusExceptionHandler(exchange, (ResponseStatusException) ex);
|
||||
} else {
|
||||
} else if(ex instanceof ServiceException){
|
||||
result = serviceExceptionHandler((ServiceException) ex);
|
||||
}
|
||||
else {
|
||||
result = defaultExceptionHandler(exchange, ex);
|
||||
}
|
||||
|
||||
@@ -71,4 +75,10 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler {
|
||||
return CommonResult.error(INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = ServiceException.class)
|
||||
public CommonResult serviceExceptionHandler(ServiceException ex) {
|
||||
log.info(String.format("========[serviceExceptionHandler]========,%s: %s", ex.getCode(),ex.getMessage()));
|
||||
return CommonResult.error(ex.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user