From a181733365c9800e861c8b4795526b480ae101c5 Mon Sep 17 00:00:00 2001 From: Rob Winch <362503+rwinch@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:25:51 -0500 Subject: [PATCH] Encapsulate GenericHttpMessageConverterAdapter This will allow its removal in gh-18073 --- .../GenericHttpMessageConverterAdapter.java | 99 +++++++++++++++++++ .../web/server/HttpMessageConverters.java | 1 - .../GenericHttpMessageConverterAdapter.java | 99 +++++++++++++++++++ .../http/converter/HttpMessageConverters.java | 1 - .../GenericHttpMessageConverterAdapter.java | 99 +++++++++++++++++++ .../http/converter/HttpMessageConverters.java | 1 - .../GenericHttpMessageConverterAdapter.java | 99 +++++++++++++++++++ .../web/HttpMessageConverters.java | 1 - .../GenericHttpMessageConverterAdapter.java | 4 +- .../GenericHttpMessageConverterAdapter.java | 99 +++++++++++++++++++ ...OAuth2ProtectedResourceMetadataFilter.java | 1 - 11 files changed, 497 insertions(+), 7 deletions(-) create mode 100644 config/src/main/java/org/springframework/security/config/web/server/GenericHttpMessageConverterAdapter.java create mode 100644 oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/GenericHttpMessageConverterAdapter.java create mode 100644 oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/GenericHttpMessageConverterAdapter.java create mode 100644 oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/GenericHttpMessageConverterAdapter.java create mode 100644 oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/GenericHttpMessageConverterAdapter.java diff --git a/config/src/main/java/org/springframework/security/config/web/server/GenericHttpMessageConverterAdapter.java b/config/src/main/java/org/springframework/security/config/web/server/GenericHttpMessageConverterAdapter.java new file mode 100644 index 0000000000..8a61462f05 --- /dev/null +++ b/config/src/main/java/org/springframework/security/config/web/server/GenericHttpMessageConverterAdapter.java @@ -0,0 +1,99 @@ +/* + * Copyright 2004-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.config.web.server; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; + +import org.jspecify.annotations.Nullable; + +import org.springframework.core.ResolvableType; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.HttpOutputMessage; +import org.springframework.http.MediaType; +import org.springframework.http.converter.GenericHttpMessageConverter; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.http.converter.SmartHttpMessageConverter; + +/** + * {@link GenericHttpMessageConverter} implementation that delegates to a + * {@link SmartHttpMessageConverter}. + * + * @param the converted object type + * @author Sebastien Deleuze + * @since 7.0 + */ +final class GenericHttpMessageConverterAdapter implements GenericHttpMessageConverter { + + private final SmartHttpMessageConverter smartConverter; + + GenericHttpMessageConverterAdapter(SmartHttpMessageConverter smartConverter) { + this.smartConverter = smartConverter; + } + + @Override + public boolean canRead(Type type, @Nullable Class contextClass, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forType(type), mediaType); + } + + @Override + public T read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(ResolvableType.forType(type), inputMessage, null); + } + + @Override + public boolean canWrite(@Nullable Type type, Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(ResolvableType.forType(type), clazz, mediaType); + } + + @Override + public void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, ResolvableType.forType(type), contentType, outputMessage, null); + } + + @Override + public boolean canRead(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forClass(clazz), mediaType); + } + + @Override + public boolean canWrite(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(clazz, mediaType); + } + + @Override + public List getSupportedMediaTypes() { + return this.smartConverter.getSupportedMediaTypes(); + } + + @Override + public T read(Class clazz, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(clazz, inputMessage); + } + + @Override + public void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, contentType, outputMessage); + } + +} diff --git a/config/src/main/java/org/springframework/security/config/web/server/HttpMessageConverters.java b/config/src/main/java/org/springframework/security/config/web/server/HttpMessageConverters.java index a8f262b126..22d18762e5 100644 --- a/config/src/main/java/org/springframework/security/config/web/server/HttpMessageConverters.java +++ b/config/src/main/java/org/springframework/security/config/web/server/HttpMessageConverters.java @@ -22,7 +22,6 @@ import org.springframework.http.converter.json.GsonHttpMessageConverter; import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.http.converter.json.JsonbHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.security.oauth2.core.http.converter.GenericHttpMessageConverterAdapter; import org.springframework.util.ClassUtils; /** diff --git a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/GenericHttpMessageConverterAdapter.java b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/GenericHttpMessageConverterAdapter.java new file mode 100644 index 0000000000..735a0dfb46 --- /dev/null +++ b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/GenericHttpMessageConverterAdapter.java @@ -0,0 +1,99 @@ +/* + * Copyright 2004-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.oauth2.server.authorization.http.converter; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; + +import org.jspecify.annotations.Nullable; + +import org.springframework.core.ResolvableType; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.HttpOutputMessage; +import org.springframework.http.MediaType; +import org.springframework.http.converter.GenericHttpMessageConverter; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.http.converter.SmartHttpMessageConverter; + +/** + * {@link GenericHttpMessageConverter} implementation that delegates to a + * {@link SmartHttpMessageConverter}. + * + * @param the converted object type + * @author Sebastien Deleuze + * @since 7.0 + */ +final class GenericHttpMessageConverterAdapter implements GenericHttpMessageConverter { + + private final SmartHttpMessageConverter smartConverter; + + GenericHttpMessageConverterAdapter(SmartHttpMessageConverter smartConverter) { + this.smartConverter = smartConverter; + } + + @Override + public boolean canRead(Type type, @Nullable Class contextClass, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forType(type), mediaType); + } + + @Override + public T read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(ResolvableType.forType(type), inputMessage, null); + } + + @Override + public boolean canWrite(@Nullable Type type, Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(ResolvableType.forType(type), clazz, mediaType); + } + + @Override + public void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, ResolvableType.forType(type), contentType, outputMessage, null); + } + + @Override + public boolean canRead(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forClass(clazz), mediaType); + } + + @Override + public boolean canWrite(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(clazz, mediaType); + } + + @Override + public List getSupportedMediaTypes() { + return this.smartConverter.getSupportedMediaTypes(); + } + + @Override + public T read(Class clazz, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(clazz, inputMessage); + } + + @Override + public void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, contentType, outputMessage); + } + +} diff --git a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/HttpMessageConverters.java b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/HttpMessageConverters.java index c5daa5e126..623099f7f9 100644 --- a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/HttpMessageConverters.java +++ b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/http/converter/HttpMessageConverters.java @@ -22,7 +22,6 @@ import org.springframework.http.converter.json.GsonHttpMessageConverter; import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.http.converter.json.JsonbHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.security.web.http.GenericHttpMessageConverterAdapter; import org.springframework.util.ClassUtils; /** diff --git a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/GenericHttpMessageConverterAdapter.java b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/GenericHttpMessageConverterAdapter.java new file mode 100644 index 0000000000..2add8e916f --- /dev/null +++ b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/GenericHttpMessageConverterAdapter.java @@ -0,0 +1,99 @@ +/* + * Copyright 2004-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.oauth2.server.authorization.oidc.http.converter; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; + +import org.jspecify.annotations.Nullable; + +import org.springframework.core.ResolvableType; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.HttpOutputMessage; +import org.springframework.http.MediaType; +import org.springframework.http.converter.GenericHttpMessageConverter; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.http.converter.SmartHttpMessageConverter; + +/** + * {@link GenericHttpMessageConverter} implementation that delegates to a + * {@link SmartHttpMessageConverter}. + * + * @param the converted object type + * @author Sebastien Deleuze + * @since 7.0 + */ +final class GenericHttpMessageConverterAdapter implements GenericHttpMessageConverter { + + private final SmartHttpMessageConverter smartConverter; + + GenericHttpMessageConverterAdapter(SmartHttpMessageConverter smartConverter) { + this.smartConverter = smartConverter; + } + + @Override + public boolean canRead(Type type, @Nullable Class contextClass, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forType(type), mediaType); + } + + @Override + public T read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(ResolvableType.forType(type), inputMessage, null); + } + + @Override + public boolean canWrite(@Nullable Type type, Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(ResolvableType.forType(type), clazz, mediaType); + } + + @Override + public void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, ResolvableType.forType(type), contentType, outputMessage, null); + } + + @Override + public boolean canRead(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forClass(clazz), mediaType); + } + + @Override + public boolean canWrite(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(clazz, mediaType); + } + + @Override + public List getSupportedMediaTypes() { + return this.smartConverter.getSupportedMediaTypes(); + } + + @Override + public T read(Class clazz, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(clazz, inputMessage); + } + + @Override + public void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, contentType, outputMessage); + } + +} diff --git a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/HttpMessageConverters.java b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/HttpMessageConverters.java index 4b6e1f929d..f442a6636e 100644 --- a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/HttpMessageConverters.java +++ b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/oidc/http/converter/HttpMessageConverters.java @@ -22,7 +22,6 @@ import org.springframework.http.converter.json.GsonHttpMessageConverter; import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.http.converter.json.JsonbHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.security.web.http.GenericHttpMessageConverterAdapter; import org.springframework.util.ClassUtils; /** diff --git a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/GenericHttpMessageConverterAdapter.java b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/GenericHttpMessageConverterAdapter.java new file mode 100644 index 0000000000..93063d97f5 --- /dev/null +++ b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/GenericHttpMessageConverterAdapter.java @@ -0,0 +1,99 @@ +/* + * Copyright 2004-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.oauth2.server.authorization.web; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; + +import org.jspecify.annotations.Nullable; + +import org.springframework.core.ResolvableType; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.HttpOutputMessage; +import org.springframework.http.MediaType; +import org.springframework.http.converter.GenericHttpMessageConverter; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.http.converter.SmartHttpMessageConverter; + +/** + * {@link GenericHttpMessageConverter} implementation that delegates to a + * {@link SmartHttpMessageConverter}. + * + * @param the converted object type + * @author Sebastien Deleuze + * @since 7.0 + */ +final class GenericHttpMessageConverterAdapter implements GenericHttpMessageConverter { + + private final SmartHttpMessageConverter smartConverter; + + GenericHttpMessageConverterAdapter(SmartHttpMessageConverter smartConverter) { + this.smartConverter = smartConverter; + } + + @Override + public boolean canRead(Type type, @Nullable Class contextClass, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forType(type), mediaType); + } + + @Override + public T read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(ResolvableType.forType(type), inputMessage, null); + } + + @Override + public boolean canWrite(@Nullable Type type, Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(ResolvableType.forType(type), clazz, mediaType); + } + + @Override + public void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, ResolvableType.forType(type), contentType, outputMessage, null); + } + + @Override + public boolean canRead(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forClass(clazz), mediaType); + } + + @Override + public boolean canWrite(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(clazz, mediaType); + } + + @Override + public List getSupportedMediaTypes() { + return this.smartConverter.getSupportedMediaTypes(); + } + + @Override + public T read(Class clazz, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(clazz, inputMessage); + } + + @Override + public void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, contentType, outputMessage); + } + +} diff --git a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/HttpMessageConverters.java b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/HttpMessageConverters.java index 0229c8171c..5c8897f69c 100644 --- a/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/HttpMessageConverters.java +++ b/oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/HttpMessageConverters.java @@ -22,7 +22,6 @@ import org.springframework.http.converter.json.GsonHttpMessageConverter; import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.http.converter.json.JsonbHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.security.web.http.GenericHttpMessageConverterAdapter; import org.springframework.util.ClassUtils; /** diff --git a/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/http/converter/GenericHttpMessageConverterAdapter.java b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/http/converter/GenericHttpMessageConverterAdapter.java index 7f2f0e51a3..3e6aff6725 100644 --- a/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/http/converter/GenericHttpMessageConverterAdapter.java +++ b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/http/converter/GenericHttpMessageConverterAdapter.java @@ -39,11 +39,11 @@ import org.springframework.http.converter.SmartHttpMessageConverter; * @author Sebastien Deleuze * @since 7.0 */ -public class GenericHttpMessageConverterAdapter implements GenericHttpMessageConverter { +final class GenericHttpMessageConverterAdapter implements GenericHttpMessageConverter { private final SmartHttpMessageConverter smartConverter; - public GenericHttpMessageConverterAdapter(SmartHttpMessageConverter smartConverter) { + GenericHttpMessageConverterAdapter(SmartHttpMessageConverter smartConverter) { this.smartConverter = smartConverter; } diff --git a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/GenericHttpMessageConverterAdapter.java b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/GenericHttpMessageConverterAdapter.java new file mode 100644 index 0000000000..724bc82fe8 --- /dev/null +++ b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/GenericHttpMessageConverterAdapter.java @@ -0,0 +1,99 @@ +/* + * Copyright 2004-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.oauth2.server.resource.web; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; + +import org.jspecify.annotations.Nullable; + +import org.springframework.core.ResolvableType; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.HttpOutputMessage; +import org.springframework.http.MediaType; +import org.springframework.http.converter.GenericHttpMessageConverter; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.http.converter.HttpMessageNotWritableException; +import org.springframework.http.converter.SmartHttpMessageConverter; + +/** + * {@link GenericHttpMessageConverter} implementation that delegates to a + * {@link SmartHttpMessageConverter}. + * + * @param the converted object type + * @author Sebastien Deleuze + * @since 7.0 + */ +final class GenericHttpMessageConverterAdapter implements GenericHttpMessageConverter { + + private final SmartHttpMessageConverter smartConverter; + + GenericHttpMessageConverterAdapter(SmartHttpMessageConverter smartConverter) { + this.smartConverter = smartConverter; + } + + @Override + public boolean canRead(Type type, @Nullable Class contextClass, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forType(type), mediaType); + } + + @Override + public T read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(ResolvableType.forType(type), inputMessage, null); + } + + @Override + public boolean canWrite(@Nullable Type type, Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(ResolvableType.forType(type), clazz, mediaType); + } + + @Override + public void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, ResolvableType.forType(type), contentType, outputMessage, null); + } + + @Override + public boolean canRead(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canRead(ResolvableType.forClass(clazz), mediaType); + } + + @Override + public boolean canWrite(Class clazz, @Nullable MediaType mediaType) { + return this.smartConverter.canWrite(clazz, mediaType); + } + + @Override + public List getSupportedMediaTypes() { + return this.smartConverter.getSupportedMediaTypes(); + } + + @Override + public T read(Class clazz, HttpInputMessage inputMessage) + throws IOException, HttpMessageNotReadableException { + return this.smartConverter.read(clazz, inputMessage); + } + + @Override + public void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) + throws IOException, HttpMessageNotWritableException { + this.smartConverter.write(t, contentType, outputMessage); + } + +} diff --git a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/OAuth2ProtectedResourceMetadataFilter.java b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/OAuth2ProtectedResourceMetadataFilter.java index 1a839291eb..d5168e1150 100644 --- a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/OAuth2ProtectedResourceMetadataFilter.java +++ b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/OAuth2ProtectedResourceMetadataFilter.java @@ -35,7 +35,6 @@ import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; import org.springframework.http.converter.json.JsonbHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.security.oauth2.core.http.converter.GenericHttpMessageConverterAdapter; import org.springframework.security.oauth2.server.resource.OAuth2ProtectedResourceMetadata; import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher; import org.springframework.security.web.util.UrlUtils;