Skip to content

Spring 7 webmvc and @PreAuthorize: AuthorizationDeniedException results in 500 response status #35287

@ah1508

Description

@ah1508

When a @PreAuthorize annotated method is called with insufficient permissions (anonymous call, missing authorities, missing roles), a AuthorizationDeniedException is thrown (like with Spring 6) but it is translated into HTTP 500 response.

With Spring 6 the response status is 401 or 403 with WWW-Authenticate header. Writing a @ExceptionHandler for this exception is possible but error prone.

When endpoints are secured by request matchers in the SecurityFilterChain configuration the status is 401 or 403 with WWW-Authenticate header.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectNeeds a fix in external projectin: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions