Question 1
When is @PostAuthorize evaluated relative to the method it guards?
A. Before the method executes, like @PreAuthorize
Running the check before the method describes @PreAuthorize; @PostAuthorize is the opposite, evaluating after invocation.
B. Only during application startup
@PostAuthorize is a per-call runtime check on each invocation, not something that runs only at application startup.
C. After the method executes — typically to authorize based on the returned object (referenced via returnObject)Correct answer
@PostAuthorize is evaluated after the method executes so the rule can authorize based on the returned object (referenced via returnObject), throwing if access is denied.
D. It never runs unless @PreAuthorize is also present
@PostAuthorize works independently and does not require @PreAuthorize to be present.
Explanation
@PostAuthorize runs after the guarded method returns so its expression can inspect the result — for example comparing returnObject.owner to the authenticated name — and deny access by throwing if the rule fails. It is a per-invocation runtime check that stands on its own, in contrast to the before-invocation check performed by @PreAuthorize.