Describe how to implement dynamic access-control policies in Spring Security.

Dynamic access-control policies evaluate authorization rules at runtime rather than relying on static role checks, typically using Spring Expression Language inside @PreAuthorize or @PostAuthorize to reference live data such as method arguments, the current user, or database-backed permissions.

Key Points

Example

A document-sharing app uses @PreAuthorize("@docPermissionEvaluator.canEdit(#docId, authentication)") to check, at runtime, whether the current user has been granted edit rights on that specific document by looking it up in the database.

@PreAuthorize("@docPermissionEvaluator.canEdit(#docId, authentication)")
public void editDocument(Long docId, String content) {
    // edit logic
}

Interview Tip

A concise interview answer is

I'd use SpEL inside @PreAuthorize or @PostAuthorize to evaluate access rules at runtime, referencing method parameters or a custom PermissionEvaluator bean that checks permissions dynamically, often against a database. This supports attribute- or resource-based access control beyond simple static roles.

Last updated: 16 July 2026

Previous question: You've encountered an issue where users are being unexpectedly denied access to a resource they should have access to. Describe your approach to debugging this issue in a Spring Security-enabled application.

Next question: How do you test security configurations in Spring applications?

More Spring Security - Level I interview questions

All Spring Security - Level I questions