Skip to content

Commit

Permalink
feat: Map AuthorizationDeniedException to 403 Forbidden by default
Browse files Browse the repository at this point in the history
Fixes #97
  • Loading branch information
wimdeblauwe committed Sep 12, 2024
1 parent 6bae263 commit 992abd9
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.*;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.HashMap;
Expand All @@ -22,6 +23,7 @@ public class SpringSecurityApiExceptionHandler extends AbstractApiExceptionHandl
static {
EXCEPTION_TO_STATUS_MAPPING = new HashMap<>();
EXCEPTION_TO_STATUS_MAPPING.put(AccessDeniedException.class, FORBIDDEN);
EXCEPTION_TO_STATUS_MAPPING.put(AuthorizationDeniedException.class, FORBIDDEN);
EXCEPTION_TO_STATUS_MAPPING.put(AccountExpiredException.class, BAD_REQUEST);
EXCEPTION_TO_STATUS_MAPPING.put(AuthenticationCredentialsNotFoundException.class, UNAUTHORIZED);
EXCEPTION_TO_STATUS_MAPPING.put(AuthenticationServiceException.class, INTERNAL_SERVER_ERROR);
Expand Down

0 comments on commit 992abd9

Please sign in to comment.