Announcement Announcement Module
Collapse
No announcement yet.
@Before advice to get the (spring)bean ID ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Before advice to get the (spring)bean ID ?

    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 ?

  • #2
    Really no way for doing this ???

    Comment


    • #3
      Well, there is a bean() pointcut designator (see http://blog.springsource.com/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

      Comment


      • #4
        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.

        Comment


        • #5
          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("execution(* *.*(..))")
          	public Object secure(ProceedingJoinPoint proceedingJoinPoint)
          			throws Throwable {
          
          		String[] beanNames = applicationContext.getBeanNamesForType(proceedingJoinPoint
          				.getSignature().getDeclaringType(), false, false);
          
                  ...
          		return proceedingJoinPoint.proceed();
          	}
          }

          Comment

          Working...
          X