code: 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);
          }
      }
docs: Create response entity for authn failure response.
  
  @param e                  the e
  @param request            the http request
  @param applicationContext the application context
  @return the response entity