Access is denied Authentication Origin: Application & API OSI layer 7 · Application Last updated 28 Nov 2026

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.

Exact message you may see AccessDeniedException Access is deniedAccess is deniedSpring 403 forbidden
Seen on: Java Spring Boot

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 (hasRole vs hasAuthority)
  • Rule order in authorizeHttpRequests
  • Method security on but roles not loaded

⚡ Quick fix

  1. Print SecurityContextHolder.getContext().getAuthentication().getAuthorities()
  2. Use hasAuthority('ROLE_ADMIN') or add the prefix
  3. Put specific matchers before anyRequest()

Detailed fix by platform

Spring Boot

  1. .requestMatchers("/admin/**").hasRole("ADMIN") and grant ROLE_ADMIN in UserDetails

How to diagnose

  1. Authorities — What authorities does the principal hold?
  2. Prefix — ROLE_ prefix correct?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

401 — 401 because the Authorization header is stripped (HTTP)401403 — HTTP 403 Forbidden (HTTP)403authorization_request_not_found — [authorization_request_not_found] Spring OAuth2 login callback (Authentication)authorization_request…Bad credentials — Spring Security: BadCredentialsException: Bad credentials (Authentication)Bad credentialsContent type not supported — Spring: HttpMediaTypeNotSupportedException: Content type 'text/plain' not supported (415) (API)Content type not supp…does not look like BCrypt — WARN: Encoded password does not look like BCrypt (Authentication)does not look like BC…Full authentication is required — Full authentication is required to access this resource (401) (Authentication)Full authentication i…HttpClientErrorException — org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 Unauthorized (API)HttpClientErrorExcept…Access is…

Explore the map of this error Full error map →

🧠 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.