Created
May 17, 2023 11:32
-
-
Save levancho/dc545efd0656b271a1ba3da01156ef07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JWTAuthenticationEntryPoint implements AuthenticationEntryPoint { | |
@Override | |
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) | |
throws IOException, ServletException { | |
response.setStatus(403); | |
response.setContentType(MediaType. APPLICATION_JSON_VALUE); | |
String message; | |
if (exception.getCause() != null) { | |
message = exception.getCause().getMessage(); | |
} else { | |
message = exception.getMessage(); | |
} | |
byte[] body = new ObjectMapper().writeValueAsBytes(Collections.singletonMap("error", message)); | |
response.getOutputStream().write(body); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment