AccessDeniedException: Access is denied (Spring Security 403)
The user is authenticated but lacks the role or authority required for the endpoint, so Spring returns 403.
AccessDeniedException Access is deniedAccess is deniedSpring 403 forbidden Meaning
This is authorisation, not login. The SecurityFilterChain or @PreAuthorize rule needs a role the principal does not have. A common trap is the ROLE_ prefix: hasRole('ADMIN') checks ROLE_ADMIN.
Common causes
- Principal missing the required authority
ROLE_prefix mismatch (hasRolevshasAuthority)- Rule order in
authorizeHttpRequests - Method security on but roles not loaded
⚡ Quick fix
- Print
SecurityContextHolder.getContext().getAuthentication().getAuthorities() - Use
hasAuthority('ROLE_ADMIN')or add the prefix - Put specific matchers before
anyRequest()
Detailed fix by platform
Spring Boot
.requestMatchers("/admin/**").hasRole("ADMIN")and grantROLE_ADMINinUserDetails
How to diagnose
- Authorities — What authorities does the principal hold?
- Prefix — ROLE_ prefix correct?
- Order — Matcher order correct?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Authentication
- disallowed_useragent Google OAuth: Error 403: disallowed_useragent (sign-in from an embedded WebView)
- Access blocked: has not completed the Google verification process Google OAuth: Error 403: access_denied — The developer hasn't given you access to this app / has not completed the Google verification process
- redirect_uri_mismatch OAuth Error: redirect_uri_mismatch
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 28 Nov 2026