From c125f20de4794990da7cc89ddd13c2727594bb43 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Thu, 21 Nov 2024 15:48:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/constant/DeviceValidMessage.java | 21 ++++++++++++++++++ .../system/auth/filter/AuthGlobalFilter.java | 22 ++++++++++++------- .../pojo/constant/SystemValidMessage.java | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java index 040b4521..1884edf6 100644 --- a/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java +++ b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java @@ -90,4 +90,25 @@ public interface DeviceValidMessage { String ENABLE_FORMAT_ERROR = "是否启用格式错误,请检查enable参数"; + String ERR_SYS_ID_NOT_BLANK = "误差体系ID不能为空,请检查errSysId参数"; + + String ERR_SYS_DTLS_TYPE_NOT_BLANK = "电能质量检测指标类型不能为空,请检查errSysDtlsType参数"; + + String ERR_SYS_DTLS_TYPE_FORMAT_ERROR = "电能质量检测指标类型格式错误,请检查errSysDtlsType参数"; + + String START_VALUE_NOT_NULL = "起始值不能为空,请检查startValue参数"; + + String START_FLAG_NOT_NULL = "是否包含起始值不能为空,请检查startFlag参数"; + + String END_VALUE_NOT_NULL = "结束值不能为空,请检查endValue参数"; + + String END_FLAG_NOT_NULL = "是否包含结束值不能为空,请检查endFlag参数"; + + String CONDITION_TYPE_NOT_BLANK = "判断条件类型不能为空,请检查conditionType参数"; + + String ERROR_VALUE_FORMAT_ERROR = "误差值格式错误,请检查errorValue参数"; + + String MAX_ERROR_VALUE_NOT_NULL = "最大误差值不能为空,请检查maxErrorValue参数"; + + String ERROR_VALUE_TYPE_NOT_BLANK = "误差值类型不能为空,请检查errorValueType参数"; } diff --git a/system/src/main/java/com/njcn/gather/system/auth/filter/AuthGlobalFilter.java b/system/src/main/java/com/njcn/gather/system/auth/filter/AuthGlobalFilter.java index 81791fb6..28c3f057 100644 --- a/system/src/main/java/com/njcn/gather/system/auth/filter/AuthGlobalFilter.java +++ b/system/src/main/java/com/njcn/gather/system/auth/filter/AuthGlobalFilter.java @@ -5,7 +5,6 @@ import com.njcn.common.pojo.constant.SecurityConstants; import com.njcn.common.utils.JwtUtil; import com.njcn.gather.system.pojo.constant.SystemValidMessage; import lombok.extern.slf4j.Slf4j; -import org.apache.logging.log4j.util.Strings; import org.springframework.core.Ordered; import org.springframework.stereotype.Component; @@ -54,15 +53,22 @@ public class AuthGlobalFilter implements Filter, Ordered { filterChain.doFilter(req, res); } else { String tokenStr = req.getHeader(SecurityConstants.AUTHORIZATION_KEY); - if (StrUtil.isNotBlank(tokenStr)) { - tokenStr = tokenStr.replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY); - } - if (StrUtil.isBlank(tokenStr) || !JwtUtil.verifyToken(tokenStr) || JwtUtil.isExpired(tokenStr)) { + if (StrUtil.isBlank(tokenStr) || !tokenStr.startsWith(SecurityConstants.AUTHORIZATION_PREFIX)) { + res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + res.getWriter().write(SystemValidMessage.TOKEN_VALID_ERROR); + return; + } + tokenStr = tokenStr.substring(SecurityConstants.AUTHORIZATION_PREFIX.length()); + try { + if (StrUtil.isBlank(tokenStr) || !JwtUtil.verifyToken(tokenStr) || JwtUtil.isExpired(tokenStr)) { + res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + res.getWriter().write(SystemValidMessage.TOKEN_VALID_ERROR); + } else { + filterChain.doFilter(req, res); + } + } catch (Exception e) { res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); res.getWriter().write(SystemValidMessage.TOKEN_VALID_ERROR); - res.sendRedirect("/admin/login"); - } else { - filterChain.doFilter(req, res); } } } diff --git a/system/src/main/java/com/njcn/gather/system/pojo/constant/SystemValidMessage.java b/system/src/main/java/com/njcn/gather/system/pojo/constant/SystemValidMessage.java index c8f561bc..13beb26f 100644 --- a/system/src/main/java/com/njcn/gather/system/pojo/constant/SystemValidMessage.java +++ b/system/src/main/java/com/njcn/gather/system/pojo/constant/SystemValidMessage.java @@ -87,5 +87,5 @@ public interface SystemValidMessage { String AUTO_GENERATE_FORMAT_ERROR = "是否自动生成格式错误,请检查autoGenerate参数"; - String TOKEN_VALID_ERROR = "token校验失败,请重新登录"; + String TOKEN_VALID_ERROR = "token校验失败"; }