Use static weaving with spring-security

aop, spring-security

Solution

There is an Aspectj sample in the Spring Security codebase. It compiles against the `spring-security-aspects` module and then uses:

<global-method-security secured-annotations="enabled" mode="aspectj" />

to enable secured annotations. The code is very simple - it is really just a set of JUnit tests. If you take a look, you'll see that these include tests for both Spring-bean instances and instances created using the `new` operator.

If you want to know how `spring-security-aspects` works, check out the aspect source.

Problem

Colleagues, In the spring security documentation I met following notion: If you want to secure instances which are not created by Spring (using the new operator, for example) then you need to use AspectJ. Could anybody please show me workable example of such usage. The best case if this is done with help of static weaving. Thank you in advance!

Original source