Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion service in Spring 3.1 removes items from Lists in Maps causing Spring Security exceptions [SPR-8364] #13011

Closed
spring-projects-issues opened this issue May 22, 2011 · 7 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

!!Use pwebb rather than philw opened SPR-8364 and commented

Using the latest snapshot build of Spring 3.1 an IllegalArgumentException is thrown from Spring Security FilterChainProxy.checkContents.

After a bit of hunting I believe that this is due to an error in the converter service. The conversion services is being invoked to convert Map<String,List<Filter>> to Map<Object,Object>, this invokes the MapToMapConverter for the Map and then the CollectionToObjectConverter. The collection to object converter returns the 1st item in the list and discards the rest.

Here is a test case that you can use to verify. This will pass on 3.0.5 and fail on 3.1.0.BUILD-SNAPSHOT

@Test
@SuppressWarnings("unchecked")
public void shouldConvertMaps() throws Exception {
	HashMap<String, List<Integer>> src = new LinkedHashMap<String, List<Integer>>();
	List<Integer> value = new ArrayList<Integer>();
	value.add(1);
	value.add(2);
	value.add(3);
	src.put("k", value);
	GenericConversionService cs = ConversionServiceFactory.createDefaultConversionService();
	Map<Object, Object> converted = cs.convert(src, Map.class);
	assertEquals(value, converted.get("k"));
}

Affects: 3.1 M1

Referenced from: commits 4d6a584, 7430fcd

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Phil, is this something that just started happening in a recent snapshot, or has happened since you upgraded to 3.1? Is it reproducible in 3.1 M1 as well?

@spring-projects-issues
Copy link
Collaborator Author

!!Use pwebb rather than philw commented

This is the first time that I have tried 3.1 but the test above fails against M1 as well. Looking though the logs my guess is something around the commits that happened early Jan could be to blame. Surprised that nobody else has hit this in though as I am working with a MVC app based on the booking-faces webflow example.

@spring-projects-issues
Copy link
Collaborator Author

!!Use pwebb rather than philw commented

Here is a stacktrace from the web-app against 3.1.0.M1

 
22-May-2011 13:41:13 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChainProxy': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'filterChainMap' threw exception; nested exception is java.lang.IllegalArgumentException: Value must be a filter listObject of class [org.springframework.security.web.context.SecurityContextPersistenceFilter] must be an instance of interface java.util.List
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455)
	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:294)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'filterChainMap' threw exception; nested exception is java.lang.IllegalArgumentException: Value must be a filter listObject of class [org.springframework.security.web.context.SecurityContextPersistenceFilter] must be an instance of interface java.util.List
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
	... 28 more

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

It's likely this problem only shows up when a default "conversionService" bean is configured in the context. In my app, the Spring MVC conversion service is named "webMvcConversionService", so the container doesn't use it (and doesn't use a ConversionService for bean configuration at all, then). There's definitely a bug though. The MapToMapConverter is asking the service to convert a List to an Object, because target generic information is not available, and yes the CollectionToObject converter is treating the target as a scalar and extracting the list's first element.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 23, 2011

!!Use pwebb rather than philw commented

Whilst you are in the code any chance of considering #12253 & #12252, both have patches attached. #12253 would be particularly useful for me.

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Phil,
Can you give the latest nightly snapshot a try and let me know how it works for you? This issue should be fixed.

@spring-projects-issues
Copy link
Collaborator Author

!!Use pwebb rather than philw commented

It is indeed fixed. Thanks Keith!

INFO: FrameworkServlet 'Spring MVC Dispatcher Servlet': initialization completed in 13 ms
23-May-2011 22:02:17 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
23-May-2011 22:02:17 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
23-May-2011 22:02:17 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/29  config=null
23-May-2011 22:02:17 org.apache.catalina.startup.Catalina start
INFO: Server startup in 8689 ms

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.1 M2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant