@Before(value = "@annotation(OwnershipCheck) && args(enquiry)")
public void checkOwnership(Enquiry enquiry) throws Throwable
{
}
The above expression will match for any method with the OwnershipCheck annotation and takes an enquiry as a parameter.
How can I extend this expression for any method with the OwnershipCheck annotation and takes an enquiry in any position with or without another parameters.
That is, needs to match
@OwnershipCheck
public void one(Enquiry enquiry)
@OwnershipCheck
public void two(Object obj, Enquiry enquiry)
@OwnershipCheck
public void three(Enquiry enquiry, Object ob)
@OwnershipCheck
public void four(Object obj, Enquiry enquiry, Object other)
Here is how I did this:
@Pointcut("@annotation(protections) && args(request,..)")
private void httpRequestAsFirstParam(Protections protections, HttpServletRequest request){}
@Pointcut("@annotation(protections) && args(..,request)")
private void httpRequestAsLastParam(Protections protections, HttpServletRequest request){}
@Pointcut("@annotation(protections) && args(*,request,..)")
private void httpRequestAsSecondParam(Protections protections, HttpServletRequest request){}
@Around("httpRequestAsFirstParam(protections, request) " +
"|| httpRequestAsLastParam(protections, request) " +
"|| httpRequestAsSecondParam(protections, request)")
public Object protect(ProceedingJoinPoint joinPoint, Protections protections, HttpServletRequest request) throws Throwable {
//...
}
You can't do args(.., enquiry, ..)
, but it is possible with args(*, enquiry, ..)
and combine with first and last argument matchers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With