From f9493fe2d7fbb8c7d38b05555790c02674a0f213 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Mon, 2 Aug 2021 18:27:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20token=E8=BF=87=E6=9C=9F=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E7=A1=AE=E5=AE=9A=E6=B2=A1=E6=9C=89=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/dataease/auth/filter/JWTFilter.java | 3 +++ .../java/io/dataease/auth/server/AuthServer.java | 14 ++++++++++++-- frontend/src/components/Notification/index.vue | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java b/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java index 1c45756a52..ba23292a7a 100644 --- a/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java +++ b/backend/src/main/java/io/dataease/auth/filter/JWTFilter.java @@ -49,6 +49,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter { protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String authorization = httpServletRequest.getHeader("Authorization"); + if (StringUtils.startsWith(authorization, "Basic")) { + return false; + } // 当没有出现登录超时 且需要刷新token 则执行刷新token if (JWTUtils.loginExpire(authorization)){ throw new AuthenticationException(expireMessage); diff --git a/backend/src/main/java/io/dataease/auth/server/AuthServer.java b/backend/src/main/java/io/dataease/auth/server/AuthServer.java index 09a311c22c..74bf04c371 100644 --- a/backend/src/main/java/io/dataease/auth/server/AuthServer.java +++ b/backend/src/main/java/io/dataease/auth/server/AuthServer.java @@ -12,6 +12,7 @@ import io.dataease.auth.util.JWTUtils; import io.dataease.auth.util.RsaUtil; import io.dataease.commons.utils.BeanUtils; import io.dataease.commons.utils.CodingUtil; +import io.dataease.commons.utils.LogUtil; import io.dataease.commons.utils.ServletUtils; import io.dataease.exception.DataEaseException; @@ -84,8 +85,17 @@ public class AuthServer implements AuthApi { @Override public String logout() { String token = ServletUtils.getToken(); - Long userId = JWTUtils.tokenInfoByToken(token).getUserId(); - authUserService.clearCache(userId); + if (StringUtils.isEmpty(token) || StringUtils.equals("null", token) || StringUtils.equals("undefined", token)) { + return "success"; + } + try{ + Long userId = JWTUtils.tokenInfoByToken(token).getUserId(); + authUserService.clearCache(userId); + }catch (Exception e) { + LogUtil.error(e); + return "fail"; + } + return "success"; } diff --git a/frontend/src/components/Notification/index.vue b/frontend/src/components/Notification/index.vue index e295018421..6e0d6cae1a 100644 --- a/frontend/src/components/Notification/index.vue +++ b/frontend/src/components/Notification/index.vue @@ -64,6 +64,7 @@ import { query, updateStatus } from '@/api/system/msg' import { getTypeName, loadMsgTypes } from '@/utils/webMsg' import { mapGetters } from 'vuex' import bus from '@/utils/bus' +import { getToken } from '@/utils/auth' export default { data() { return { @@ -172,6 +173,11 @@ export default { query(currentPage, pageSize, param).then(response => { this.data = response.data.listObject this.paginationConfig.total = response.data.itemCount + }).catch(() => { + const token = getToken() + if (!token || token === 'null' || token === 'undefined') { + this.timer && clearInterval(this.timer) + } }) }, getTypeName(value) {