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