Spring Boot & Microservices (50 Qs)•Part 3: Microservices, Distributed Systems & Observability (25 - 35)
How does Method-Level Security (`@PreAuthorize`) work?
senior LevelSecurity & AuthSystem DesignMicroservices
In Simple Words:
@PreAuthorize uses Spring Expression Language (SpEL) to evaluate permissions before a method executes:
@PreAuthorize("hasRole('ADMIN')")@PreAuthorize("#userId == authentication.principal.id or hasRole('MANAGER')")Enabled via@EnableMethodSecurity.