1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| @Component @Aspect public class AccessControlAspect { private static final Logger log = Logger .getLogger(AccessControlAspect.class);
@Pointcut("execution(* xx.*Bean.*()) ") public void accessControl() { }
@Around("accessControl()") public Object checkRight(ProceedingJoinPoint jp) throws Throwable { String methodName = jp.getSignature().getName(); log.info("check right: " + methodName); Method method = jp.getTarget().getClass().getDeclaredMethod(methodName); if (method.isAnnotationPresent(AccessRight.class)) { AccessRight right = method.getAnnotation(AccessRight.class); FunctionPermission permission = getRight(right.code()); if (right.access() && permission.hasAccessPermission()) { log.info("has right to do"); return jp.proceed(); } else { log.error("no right to do"); }
} return jp.proceed(); }
private FunctionPermission getRight(String code) { } }
|