diff --git a/src/main/java/app/annotations/enums/FirstTouch.java b/src/main/java/app/annotations/enums/FirstTouch.java new file mode 100644 index 0000000..b528266 --- /dev/null +++ b/src/main/java/app/annotations/enums/FirstTouch.java @@ -0,0 +1,6 @@ +package app.annotations.enums; + +public enum FirstTouch { + NON_ALLOW, + FIRST_PAGE +} diff --git a/src/main/java/app/annotations/impl/WebAccessAspect.java b/src/main/java/app/annotations/impl/WebAccessAspect.java index 41cd81e..e1fbac4 100644 --- a/src/main/java/app/annotations/impl/WebAccessAspect.java +++ b/src/main/java/app/annotations/impl/WebAccessAspect.java @@ -1,6 +1,7 @@ package app.annotations.impl; import app.annotations.enums.AuthMethod; +import app.annotations.enums.FirstTouch; import app.annotations.exceptions.InvalidCookie; import app.annotations.exceptions.InvalidSecretKey; import app.annotations.exceptions.NeedCookie; @@ -85,25 +86,33 @@ public class WebAccessAspect { @Before("@annotation(app.annotations.interfaces.CheckWebAccess)") public void before(JoinPoint joinPoint) { if (!enabled) return; - AuthMethod auth_method = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(CheckWebAccess.class).auth_method(); - checkWebAccess(auth_method, this.request); + checkWebAccess(((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(CheckWebAccess.class), this.request); } @Before("@annotation(app.annotations.interfaces.CheckWebAccess) && args(request,..)") public void before(JoinPoint joinPoint, HttpServletRequest request){ if (!enabled) return; - AuthMethod auth_method = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(CheckWebAccess.class).auth_method(); - checkWebAccess(auth_method, request); + checkWebAccess(((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(CheckWebAccess.class), request); } - private void checkWebAccess(AuthMethod auth_method, HttpServletRequest request) { + private void checkWebAccess(CheckWebAccess checkWebAccess, HttpServletRequest request) { logger.info("check web access"); if(!(request instanceof HttpServletRequest)) { logger.error("Invalid request"); throw new RuntimeException("cannot read cookie from invalid request"); } + if (FirstTouch.FIRST_PAGE.equals(checkWebAccess.firstTouch())) { + if (request.getParameter("page")!=null&&request.getParameter("size")!=null){ + try { + if (request.getParameter("page").equals("0")&&Integer.parseInt(request.getParameter("size"))<=20) { + return; + } + } catch (Exception ignored) {} + } + } + if(request.getHeader("Cookie") == null) { logger.warn("[{}] Request not contain cookies", request.getHeader("X-Forwarded-For")); throw new NeedCookie(); @@ -135,7 +144,7 @@ public class WebAccessAspect { throw new InvalidSecretKey(); } - switch (auth_method){ + switch (checkWebAccess.auth_method()){ case COMBINED -> { if (!secret_key.isEmpty() && !steam64.isEmpty()) { if (saltedCookie.ValidateSecretKey(secret_key)) { diff --git a/src/main/java/app/annotations/interfaces/CheckWebAccess.java b/src/main/java/app/annotations/interfaces/CheckWebAccess.java index 301a188..0febb81 100644 --- a/src/main/java/app/annotations/interfaces/CheckWebAccess.java +++ b/src/main/java/app/annotations/interfaces/CheckWebAccess.java @@ -1,6 +1,7 @@ package app.annotations.interfaces; import app.annotations.enums.AuthMethod; +import app.annotations.enums.FirstTouch; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -14,4 +15,5 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) public @interface CheckWebAccess { public AuthMethod auth_method() default AuthMethod.COMBINED; + public FirstTouch firstTouch() default FirstTouch.NON_ALLOW; } diff --git a/src/main/java/app/controllers/user/DetailController.java b/src/main/java/app/controllers/user/DetailController.java index dda01ee..c740bfe 100644 --- a/src/main/java/app/controllers/user/DetailController.java +++ b/src/main/java/app/controllers/user/DetailController.java @@ -1,6 +1,7 @@ package app.controllers.user; import app.annotations.enums.AuthMethod; +import app.annotations.enums.FirstTouch; import app.annotations.interfaces.BurstUpdatePlayers; import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CollectStatistic; @@ -113,7 +114,7 @@ public class DetailController { } @PostMapping("/donate") - @CheckWebAccess(auth_method = AuthMethod.STEAM64) + @CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE) @WaitAfterNext(order = "donatelist") @CollectStatistic public ResponseEntity> getDonatePage(Pageable pageable, @RequestBody(required = false) SearchFilter searchFilter) { diff --git a/src/main/java/app/controllers/user/KillFeedController.java b/src/main/java/app/controllers/user/KillFeedController.java index 68d5c09..264f00b 100644 --- a/src/main/java/app/controllers/user/KillFeedController.java +++ b/src/main/java/app/controllers/user/KillFeedController.java @@ -1,6 +1,7 @@ package app.controllers.user; import app.annotations.enums.AuthMethod; +import app.annotations.enums.FirstTouch; import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CollectStatistic; import app.annotations.interfaces.WaitAfterNext; @@ -82,7 +83,7 @@ public class KillFeedController { } @PostMapping - @CheckWebAccess(auth_method = AuthMethod.STEAM64) + @CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE) @WaitAfterNext(order = "killfeed") @CollectStatistic public Page getKillFeed(Pageable pageable, diff --git a/src/main/java/app/controllers/user/MessagesController.java b/src/main/java/app/controllers/user/MessagesController.java index dc1bb11..7deaa23 100644 --- a/src/main/java/app/controllers/user/MessagesController.java +++ b/src/main/java/app/controllers/user/MessagesController.java @@ -1,6 +1,7 @@ package app.controllers.user; import app.annotations.enums.AuthMethod; +import app.annotations.enums.FirstTouch; import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CollectStatistic; import app.annotations.interfaces.WaitAfterNext; @@ -61,7 +62,7 @@ public class MessagesController { } @PostMapping(value = "/pages", consumes = {MediaType.APPLICATION_JSON_VALUE}) - @CheckWebAccess(auth_method = AuthMethod.STEAM64) + @CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE) @WaitAfterNext(order = "messages") @CollectStatistic public Page getMessagesWithFilters(Pageable pageable, diff --git a/src/main/java/app/controllers/user/PublicController.java b/src/main/java/app/controllers/user/PublicController.java index 482dad2..fe1e214 100644 --- a/src/main/java/app/controllers/user/PublicController.java +++ b/src/main/java/app/controllers/user/PublicController.java @@ -1,6 +1,7 @@ package app.controllers.user; import app.annotations.enums.AuthMethod; +import app.annotations.enums.FirstTouch; import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CollectStatistic; import app.annotations.interfaces.WaitAfterNext; @@ -70,7 +71,7 @@ public class PublicController { } @PostMapping("/banlist") - @CheckWebAccess(auth_method = AuthMethod.STEAM64) + @CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE) @WaitAfterNext(order = "banlist") @CollectStatistic public ResponseEntity> getBanListWithFilters(Pageable pageable, @RequestBody(required = false) BanSearchFilter banSearchFilter) { @@ -92,7 +93,7 @@ public class PublicController { } @PostMapping("/reports") - @CheckWebAccess(auth_method = AuthMethod.STEAM64) + @CheckWebAccess(auth_method = AuthMethod.STEAM64, firstTouch = FirstTouch.FIRST_PAGE) @WaitAfterNext(order = "reports") @CollectStatistic public Page getReports(Pageable pageable,