How can you use Spring Expression Language (SpEL) for fine-grained access control?

Spring Expression Language enables fine-grained access control by letting security annotations evaluate runtime expressions—referencing the current user, method arguments, or bean methods—rather than being limited to static role names.

Key Points

Example

An expense-approval method uses @PreAuthorize("hasRole('MANAGER') and #expense.amount <= 5000") so managers can only approve expenses under a certain threshold without a separate hardcoded rule per amount tier.

@PreAuthorize("hasRole('MANAGER') and #expense.amount <= 5000")
public void approveExpense(Expense expense) {
    // approval logic
}

Interview Tip

A concise interview answer is

SpEL inside @PreAuthorize or @PostAuthorize lets me write expressions that go beyond static roles—checking method arguments, calling custom permission beans, or inspecting the returned object. That gives fine-grained, context-aware access control tailored to the specific business rule rather than a blunt role check.

Last updated: 11 November 2026

Previous question: Explain salting and its usage in Spring Security.

Next question: What are AuthenticationManager and ProviderManager in Spring Security?

More Spring Security - Level I interview questions

All Spring Security - Level I questions