Hi i needed to add a new exception in Spring security login form, everything work perfectly except that i want to have my own error message (until now it display the \"wrong
A very simple way is defining your custom message in exception handler (@ControllerAdvice), as following:
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
@ExceptionHandler(value = AuthenticationException.class)
public ResponseModal handleAuthenticationExceptions(AuthenticationException ex, HttpServletResponse response) {
LOGGER.info("Authentication Exception: {}", ex.getMessage());
response.addCookie(new Cookie(JWTConfigurer.JWT_TOKEN_COOKIE, null));
return new ResponseModal(HttpStatus.UNAUTHORIZED.value(), "whatever you want");
}