chore: 记录apikeyfilter 报错日志,方便查询

This commit is contained in:
CaptainB 2023-06-19 15:32:50 +08:00 committed by 刘瑞斌
parent aa4ad894f9
commit 858abed065
2 changed files with 9 additions and 3 deletions

View File

@ -20,9 +20,12 @@ public class ApiKeyFilter extends AnonymousFilter {
// 不是apikey的通过
if (!ApiKeyHandler.isApiKeyCall(httpRequest) && !SecurityUtils.getSubject().isAuthenticated()) {
// sso 带了token的
String userId = SSOSessionHandler.validate(httpRequest);
if (StringUtils.isNotBlank(userId)) {
SecurityUtils.getSubject().login(new UsernamePasswordToken(userId, SSOSessionHandler.random));
String token = httpRequest.getHeader(SessionConstants.SSO_TOKEN);
if (StringUtils.isNotBlank(token)) {
String userId = SSOSessionHandler.validate(httpRequest);
if (StringUtils.isNotBlank(userId)) {
SecurityUtils.getSubject().login(new UsernamePasswordToken(userId, SSOSessionHandler.random));
}
}
return true;
}

View File

@ -7,6 +7,8 @@ import io.metersphere.commons.utils.LogUtil;
import org.apache.commons.lang3.StringUtils;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.UUID;
public class SSOSessionHandler {
@ -30,6 +32,7 @@ public class SSOSessionHandler {
csrfToken = CodingUtil.aesDecrypt(csrfToken, SessionUser.secret, SessionUser.iv);
String[] signatureArray = StringUtils.split(StringUtils.trimToNull(csrfToken), "|");
if (signatureArray.length != 4) {
LogUtil.error("invalid token: {}", signatureArray);
throw new RuntimeException("invalid token");
}
return signatureArray[0];