Browse Source

AOP Annotation field

master
gsd 2 years ago
parent
commit
626db52a46
  1. 12
      src/main/java/app/annotations/impl/PermitionFlagAspect.java

12
src/main/java/app/annotations/impl/PermitionFlagAspect.java

@ -3,11 +3,16 @@ package app.annotations.impl;
import app.annotations.exceptions.InvalidCookie; import app.annotations.exceptions.InvalidCookie;
import app.annotations.exceptions.LowPermition; import app.annotations.exceptions.LowPermition;
import app.annotations.exceptions.NeedCookie; import app.annotations.exceptions.NeedCookie;
import app.annotations.interfaces.CheckPermitionFlag;
import app.entities.db.Permition; import app.entities.db.Permition;
import app.services.ProfileService; import app.services.ProfileService;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -30,8 +35,9 @@ public class PermitionFlagAspect {
return permition.getFlags().contains(flag); return permition.getFlags().contains(flag);
} }
@Before("@annotation(app.annotations.interfaces.CheckPermitionFlag) && args(request,..)") @Before(value = "@annotation(app.annotations.interfaces.CheckPermitionFlag) && args(request,..)")
public void before(HttpServletRequest request){ public void before(JoinPoint joinPoint, HttpServletRequest request){
String flag = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(CheckPermitionFlag.class).flag();
System.out.println("check permition flag"); System.out.println("check permition flag");
if(!(request instanceof HttpServletRequest)) { if(!(request instanceof HttpServletRequest)) {
throw new RuntimeException("invalid request"); throw new RuntimeException("invalid request");
@ -50,7 +56,7 @@ public class PermitionFlagAspect {
throw new InvalidCookie(); throw new InvalidCookie();
} }
if(!ValidateAdmin(steam64, "z")){ if(!ValidateAdmin(steam64, flag)){
throw new LowPermition(); throw new LowPermition();
} }
} }

Loading…
Cancel
Save