DATACMNS-776 - Made ProxyingHandlerMethodArgumentResolver to only support user types or annotated ones.

ProxyingHandlerMethodArgumentResolver is now more lenient when it comes to which types to support for proxying. As indicated in the ticket, we've been to aggressive opting in for all interfaces which - depending on the order of converter registrations - caused us interfering with other interface based resolutions (e.g. in Spring Mobile, Security etc.).

We now only aggressively kick in if either the type or parameter is annotated with @ProjectedPayload or the type itself is not a Spring Framework or native Java one. This should leave user defined types still be accepted whereas the types we previously erroneously interfered with should now be ignored.
This commit is contained in:
Oliver Gierke
2017-01-23 11:35:32 +01:00
parent 50b84e701f
commit 88e70a2730
4 changed files with 150 additions and 2 deletions

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.data.web;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanClassLoaderAware;
@@ -22,9 +25,11 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
@@ -40,6 +45,8 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodProcessor
implements BeanFactoryAware, ResourceLoaderAware, BeanClassLoaderAware {
private static final List<String> IGNORED_PACKAGES = Arrays.asList("java", "org.springframework");
private final SpelAwareProxyProjectionFactory proxyFactory;
private final ConversionService conversionService;
@@ -90,7 +97,31 @@ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodP
*/
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().isInterface();
Class<?> type = parameter.getParameterType();
if (!type.isInterface()) {
return false;
}
// Annotated parameter
if (parameter.getParameterAnnotation(ProjectedPayload.class) != null) {
return true;
}
// Annotated type
if (AnnotatedElementUtils.findMergedAnnotation(type, ProjectedPayload.class) != null) {
return true;
}
// Fallback for only user defined interfaces
for (String prefix : IGNORED_PACKAGES) {
if (ClassUtils.getPackageName(type).startsWith(prefix)) {
return false;
}
}
return true;
}
/*