开发者

Advice when a method is called from other module

开发者 https://www.devze.com 2023-03-08 16:01 出处:网络
I have three different maven modules: security-api that contains an annotation and an Aspect. module that is compiled with oven classes from \"security-api\".

I have three different maven modules:

  • security-api that contains an annotation and an Aspect.
  • module that is compiled with oven classes from "security-api".
  • client that calls through an API an annotated method from "module".

Everything will run inside the same JVM.

From the "module"

@Authorization
public String getString(Subject s) {
  return "hello";
}

Aspect in "security-api"

@Aspect
public class AuthorizationAspect {
    @Pointcut(""
    + "execution(* *(org.apache.shiro.subject.Subject, ..)) && "
    + "@annotation(com.company.Authorization) && "
    + "@this(c)")
    public void cutAuthorize(Authorization c) { }

    @Before("cutAuthorize(c)")
    public void callFromAuthorizeBefore(Authorization c) {
        System.out.println("> " + c);
    }
}

So, what I want is when I call getString(subject) from other module, I want to run cutAuthorize(). I can perform this specifying a call pointcut but this only gets caught if the call happens in the same module, i.e. if I call the annotated method inside "module" everything is OK, but since I'm calling from other method through an interface the advice does not run.

Anyone have any idea of what pointcut I have to use in order to advice some code when it runs, rather when it is called? I do开发者_如何学Pythonn't know if I'm making myself clear, but what I'm trying to do is a bit complicated to explain.

Thanks in advance,

Rui


You need to register the security model as aspect library for the aspectj compiler, that should be all.

0

精彩评论

暂无评论...
验证码 换一张
取 消