Announcement Announcement Module
No announcement yet.
Using @annotation with Spring Security Annotations Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using @annotation with Spring Security Annotations

    I have a service interface that has a method that looks like the following:

    public interface FooService {
       public void doSomething();
    My Spring application context xml configuration file looks partially like:

    HTML Code:
    <bean id="foo" class="" />
    <sec:global-method-security pre-post-annotations="enabled" access-decision-manager-ref="serviceAccessDecisionManager">
       <sec:expression-handler ref="expressionHandler"/>
       <aop:advisor pointcut="execution(**.*(..)) and @annotation(" advice-ref="aceCreator" />
    I've found that when using the @annotation pointcut, my advice is not executed (even when removing the execution clause). However, if I do pointcut="bean(foo)" then my advice is executed. I am wondering if the proxies that are being created for the PrePost Spring Security annotation support are "hiding" my custom annotation on the service. Is that what's happening here, or is something else wrong?

  • #2
    If you put your annotation on your FooServiceImpl class, your advice will most likely fire (unless something else is wrong). I had that same problem, since good programing practice says that the interface should have that information, not to mention that I would forget to put it on a MockFooService. I don't understand the logic for that decision, perhaps someone with a better understanding of the internals could explain.


    • #3
      Thanks, that does indeed work. However, if I do that, then I cannot get to the annotation which is present on the class from my interceptor (which implements org.aopalliance.intercept.MethodInterceptor):

      // invocation is instanceof org.aopalliance.intercept.MethodInvocation anno = invocation.getMethod().getAnnotation(;
      Assert.assertNotNull(anno); //this fails, as the annotation is not present on the method invocation
      Would switching to AspectJ aspects and advice allow me to capture that annotation when it is on the class?