advancedMethod-Level Security
Why doesn't @PreAuthorize work when a method calls another annotated method on 'this' (the same object)?
Method security is implemented via Spring AOP proxies wrapping the bean — the proxy intercepts calls made TO the bean from OUTSIDE (through the injected reference), but a call made from within the same object (self-invocation, e.g., this.approve()) goes directly to the real method, bypassing the proxy and therefore bypassing the security check entirely. The common fix is to move the annotated logic into a separate bean and inject/call it externally.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response