Browse Source

first touch for pages

master
gsd 2 weeks ago
parent
commit
685f9b34f8
  1. 6
      src/main/java/app/annotations/enums/FirstTouch.java
  2. 21
      src/main/java/app/annotations/impl/WebAccessAspect.java
  3. 2
      src/main/java/app/annotations/interfaces/CheckWebAccess.java
  4. 3
      src/main/java/app/controllers/user/DetailController.java
  5. 3
      src/main/java/app/controllers/user/KillFeedController.java
  6. 3
      src/main/java/app/controllers/user/MessagesController.java
  7. 5
      src/main/java/app/controllers/user/PublicController.java

6
src/main/java/app/annotations/enums/FirstTouch.java

@ -0,0 +1,6 @@
package app.annotations.enums;
public enum FirstTouch {
NON_ALLOW,
FIRST_PAGE
}

21
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)) {

2
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;
}

3
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<Page<DonateStat>> getDonatePage(Pageable pageable, @RequestBody(required = false) SearchFilter searchFilter) {

3
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<KillsInFeed> getKillFeed(Pageable pageable,

3
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<Message> getMessagesWithFilters(Pageable pageable,

5
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<Page<Ban>> 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<Report> getReports(Pageable pageable,

Loading…
Cancel
Save