Debugging unexpected access denials in Spring Security is a systematic process of checking configuration, roles, and logs in order—from the security rules themselves down to what authorities the user actually holds at runtime.
Debug logging reveals that a request is being matched by an earlier, more general requestMatcher than the intended specific one, because the general rule was declared first in the chain.
# 1. See which filter and which rule decided the outcome
logging:
level:
org.springframework.security: TRACE
// 2. A common cause: rules are checked in order, and the first match wins
.authorizeHttpRequests(a -> a
.requestMatchers("/api/**").hasRole("USER") // matches first...
.requestMatchers("/api/reports/**").hasRole("ANALYST") // ...so this never applies
.anyRequest().authenticated())
// Fix: most specific rules first
.authorizeHttpRequests(a -> a
.requestMatchers("/api/reports/**").hasAnyRole("ANALYST", "ADMIN")
.requestMatchers("/api/**").hasRole("USER")
.anyRequest().authenticated())
// 3. Another common cause: hasRole("ADMIN") checks the authority "ROLE_ADMIN".
// If your token contains "ADMIN" without the prefix, use hasAuthority("ADMIN").A concise interview answer is
I'd start by re-checking the security configuration for matcher ordering and role names, then enable Spring Security's debug logging to see exactly which rule rejected the request. I'd also verify the user's actual granted authorities and check for any conflicting method-level annotations that might be more restrictive than the URL rule.
Last updated: 1 November 2026
Previous question: How does Spring Security handle session management, and what are the options for handling concurrent sessions?
Next question: Describe how to implement dynamic access-control policies in Spring Security.