|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2002-2018 the original author or authors.
|
|
|
+ * Copyright 2002-2020 the original author or authors.
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -35,6 +35,7 @@ import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* A {@link HttpMessageConverter} for an {@link OAuth2Error OAuth 2.0 Error}.
|
|
@@ -47,8 +48,8 @@ import java.util.Map;
|
|
|
public class OAuth2ErrorHttpMessageConverter extends AbstractHttpMessageConverter<OAuth2Error> {
|
|
|
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
|
|
|
|
|
- private static final ParameterizedTypeReference<Map<String, String>> PARAMETERIZED_RESPONSE_TYPE =
|
|
|
- new ParameterizedTypeReference<Map<String, String>>() {};
|
|
|
+ private static final ParameterizedTypeReference<Map<String, Object>> PARAMETERIZED_RESPONSE_TYPE =
|
|
|
+ new ParameterizedTypeReference<Map<String, Object>>() {};
|
|
|
|
|
|
private GenericHttpMessageConverter<Object> jsonMessageConverter = HttpMessageConverters.getJsonMessageConverter();
|
|
|
|
|
@@ -70,10 +71,16 @@ public class OAuth2ErrorHttpMessageConverter extends AbstractHttpMessageConverte
|
|
|
throws IOException, HttpMessageNotReadableException {
|
|
|
|
|
|
try {
|
|
|
+ // gh-8157
|
|
|
+ // Parse parameter values as Object in order to handle potential JSON Object and then convert values to String
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- Map<String, String> errorParameters = (Map<String, String>) this.jsonMessageConverter.read(
|
|
|
+ Map<String, Object> errorParameters = (Map<String, Object>) this.jsonMessageConverter.read(
|
|
|
PARAMETERIZED_RESPONSE_TYPE.getType(), null, inputMessage);
|
|
|
- return this.errorConverter.convert(errorParameters);
|
|
|
+ return this.errorConverter.convert(
|
|
|
+ errorParameters.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ entry -> String.valueOf(entry.getValue()))));
|
|
|
} catch (Exception ex) {
|
|
|
throw new HttpMessageNotReadableException("An error occurred reading the OAuth 2.0 Error: " +
|
|
|
ex.getMessage(), ex, inputMessage);
|