public static ResponseEntity<String> createResponseEntityForAuthnFailure(final AuthenticationException e,
final HttpServletRequest request,
final ApplicationContext applicationContext) {
try {
val authnExceptions = e.getHandlerErrors().values()
.stream()
.map(ex -> mapExceptionToMessage(e, request, applicationContext, ex))
.collect(Collectors.toList());
val errorsMap = new HashMap<String, List<String>>();
errorsMap.put("authentication_exceptions", authnExceptions);
LOGGER.warn("[{}] Caused by: [{}]", e.getMessage(), authnExceptions);
return new ResponseEntity<>(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(errorsMap), HttpStatus.UNAUTHORIZED);
} catch (final JsonProcessingException exception) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}