mirror of
https://github.com/dataease/dataease.git
synced 2026-05-14 21:12:33 +08:00
fix(仪表板): 未登录状态访问仪表板预览页面未能正常跳转到登录页面
This commit is contained in:
committed by
dataeaseShu
parent
e47d5afb18
commit
8079411dc7
@@ -145,15 +145,15 @@ const showLoginErrorMsg = () => {
|
||||
if (!loginErrorMsg.value) {
|
||||
return
|
||||
}
|
||||
if (loginErrorMsg.value.startsWith('token is empty')) {
|
||||
if (loginErrorMsg.value.includes('token is empty')) {
|
||||
ElMessage.error('token为空!')
|
||||
return
|
||||
}
|
||||
if (loginErrorMsg.value.startsWith('token is Expired')) {
|
||||
if (loginErrorMsg.value.includes('token is Expired')) {
|
||||
ElMessage.error('登录信息已过期,请重新登录!')
|
||||
return
|
||||
}
|
||||
if (loginErrorMsg.value.startsWith('token is destroyed')) {
|
||||
if (loginErrorMsg.value.includes('token is destroyed')) {
|
||||
ElMessage.error('登录信息已销毁,请重新登录!')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ const loadFail = () => {
|
||||
<XpackComponent
|
||||
ref="xpackInvalidPwd"
|
||||
jsname="L2NvbXBvbmVudC9sb2dpbi9JbnZhbGlkUHdk"
|
||||
@load-fail="() => loadFail"
|
||||
@load-fail="loadFail"
|
||||
@call-back="invalidPwdCb"
|
||||
/>
|
||||
<XpackComponent
|
||||
|
||||
@@ -3,22 +3,26 @@ package io.dataease.auth.filter;
|
||||
import io.dataease.auth.bo.TokenUserBO;
|
||||
import io.dataease.constant.AuthConstant;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.license.utils.LicenseUtil;
|
||||
import io.dataease.result.ResultMessage;
|
||||
import io.dataease.utils.*;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TokenFilter implements Filter {
|
||||
|
||||
private static final String headName = "DE-GATEWAY-FLAG";
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
@@ -77,6 +81,19 @@ public class TokenFilter implements Filter {
|
||||
TokenUserBO userBO = TokenUtils.validate(token);
|
||||
UserUtils.setUserInfo(userBO);
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
} catch (Exception e) {
|
||||
if (!LicenseUtil.licenseValid()) {
|
||||
HttpServletResponse res = (HttpServletResponse) servletResponse;
|
||||
ResultMessage resultMessage = new ResultMessage(HttpStatus.UNAUTHORIZED.value(), e.getMessage());
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
String msg = URLEncoder.encode(e.getMessage(), StandardCharsets.UTF_8).replace("+", "%20");
|
||||
headers.add(headName, msg);
|
||||
ResponseEntity<ResultMessage> entity = new ResponseEntity<>(resultMessage, headers, HttpStatus.UNAUTHORIZED);
|
||||
sendResponseEntity(res, entity);
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
UserUtils.removeUser();
|
||||
}
|
||||
@@ -86,6 +103,10 @@ public class TokenFilter implements Filter {
|
||||
HttpStatusCode statusCode = responseEntity.getStatusCode();
|
||||
httpResponse.setStatus(statusCode.value());
|
||||
httpResponse.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
HttpHeaders headers = responseEntity.getHeaders();
|
||||
if (ObjectUtils.isNotEmpty(headers)) {
|
||||
headers.forEach((key, value) -> httpResponse.addHeader(key, value.toString()));
|
||||
}
|
||||
httpResponse.getWriter().write(Objects.requireNonNull(JsonUtil.toJSONString(responseEntity.getBody()).toString()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user