2V0-72.22PSE · Question #5
Which two use cases can be addressed by the method level security annotation @PreAuthorize? (Choose two.)
The correct answer is A. Allow access to a method based on user identity. E. Allow access to a method based on roles. @PreAuthorize is a Spring Security method-level annotation that evaluates a SpEL (Spring Expression Language) expression before a method executes, making it ideal for checking who is calling (identity) and what roles they hold - which is why A and E are correct. For example…
Question
Which two use cases can be addressed by the method level security annotation @PreAuthorize? (Choose two.)
Options
- AAllow access to a method based on user identity.
- BAllow access to a method based on the returned object.
- CAllow access to a method based on HTTP method.
- DAllow access to a method based on request URL.
- EAllow access to a method based on roles.
How the community answered
(41 responses)- A73% (30)
- B7% (3)
- C2% (1)
- D17% (7)
Explanation
@PreAuthorize is a Spring Security method-level annotation that evaluates a SpEL (Spring Expression Language) expression before a method executes, making it ideal for checking who is calling (identity) and what roles they hold - which is why A and E are correct. For example, @PreAuthorize("hasRole('ADMIN') or #username == authentication.name") enforces both role-based (E) and identity-based (A) rules in a single expression.
Why the distractors are wrong:
- B describes
@PostAuthorize, which evaluates after the method returns and can inspect the return value viareturnObject. - C and D describe HTTP-layer security (method type and URL patterns), which belongs in
HttpSecurityconfiguration (e.g.,requestMatchers(...).hasRole(...)), not on individual methods.
Memory tip: Think of @PreAuthorize as the "who are you, and what can you do?" guard - it checks the caller (identity + roles) before letting them in. Anything about what came back (B) or how the request arrived (C, D) is handled elsewhere.
Topics
Community Discussion
No community discussion yet for this question.