Hello
I'd like to write a security advice that will require as parameter the ID of the spring bean beeing intercepted. Accoring to spring AOP reference, the AspectJ expression can be used to bind proxy, target, args .. to the advice, but I've not found anything beeing spring-dedicated
is there something equivalent to the
Code:
bean()join point for binding advice parameters ?
Really no way for doing this ???
Well, there is a bean() pointcut designator (see main/20...bean-pointcut/). However, it does selection based on bean ids (and you seem to want to collect the bean id). For your problem, you may have your beans implement the BeanNameAware interface and collect the bean using this() pointcut to obtain the id.
-Ramnivas
That requires all my adviced beans to implement BeanNameAware + another interface for a custom getBeanName().
I'l try another option to use the @Service annotation to declare my beans and to read it by reflection to retrieve the bean ID.
Ok, I'm a little late but I think I found a solution. Simply ask the applicationContext:Code:
@Aspect
public class SecurityAspect implements ApplicationContextAware {
private ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
}
@Around(quot;execution(* *.*(..))quot;)
public Object secure(ProceedingJoinPoint proceedingJoinPoint)
throws Throwable {
String[] beanNames = applicationContext.getBeanNamesForType(proceedingJoinPoint
.getSignature().getDeclaringType(), false, false);
...
return proceedingJoinPoint.proceed();
}
} |