From 8edb3ab00f22e4ba365b66d38d5629314efa9fb5 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 1 Feb 2023 17:47:03 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20referer=5Furl=20=E8=BF=87=E9=95=BF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/forest/core/service/log/VisitAspect.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java b/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java index e7df59f..1faa63c 100644 --- a/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java +++ b/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java @@ -59,6 +59,10 @@ public class VisitAspect { String url = request.getRequestURL().toString(); String ua = request.getHeader("user-agent"); String referer = request.getHeader("Referer"); + int maxVisitRefererUrlLength = 256; + if (StringUtils.isNotBlank(referer) && referer.length() > maxVisitRefererUrlLength) { + referer = referer.substring(0, maxVisitRefererUrlLength - 1); + } String fingerprint = request.getHeader("fingerprint"); Visit visit = new Visit(); visit.setVisitUrl(url); @@ -71,9 +75,7 @@ public class VisitAspect { String authHeader = request.getHeader(JwtConstants.AUTHORIZATION); if (StringUtils.isNotBlank(authHeader)) { TokenUser tokenUser = UserUtils.getTokenUser(authHeader); - if (Objects.nonNull(tokenUser)) { - visit.setVisitUserId(tokenUser.getIdUser()); - } + visit.setVisitUserId(tokenUser.getIdUser()); } visitService.save(visit);