Commit 3245f121 authored by Kevin Michael Smith's avatar Kevin Michael Smith Committed by Kevin Smith
Browse files

Move JDBCConfig's XStream whitelist to a persister initializer

parent 61a161d4
package org.geoserver.jdbcconfig.internal;
import org.geoserver.config.util.XStreamPersister;
import org.geoserver.config.util.XStreamPersisterInitializer;
public class JDBCConfigXStreamPersisterInitializer implements
XStreamPersisterInitializer {
@Override
public void init(XStreamPersister persister) {
persister.getXStream().allowTypes(new String[] {
"org.geoserver.wfs.WFSInfo.Version",
"org.geoserver.wfs.WFSInfo$Version",
"org.geoserver.wms.WatermarkInfoImpl",
"org.geoserver.wfs.GMLInfoImpl"
});
}
}
...@@ -26,12 +26,7 @@ public class XStreamInfoSerialBinding { ...@@ -26,12 +26,7 @@ public class XStreamInfoSerialBinding {
public XStreamInfoSerialBinding(final XStreamPersisterFactory xspf) { public XStreamInfoSerialBinding(final XStreamPersisterFactory xspf) {
this.xstreamPersister = xspf.createXMLPersister(); this.xstreamPersister = xspf.createXMLPersister();
this.xstreamPersister.setLoggingLevel(Level.WARNING); this.xstreamPersister.setLoggingLevel(Level.WARNING);
this.xstreamPersister.getXStream().allowTypes(new String[] { //new JDBCConfigXStreamPersisterInitializer().init(this.xstreamPersister);
"org.geoserver.wfs.WFSInfo.Version",
"org.geoserver.wfs.WFSInfo$Version",
"org.geoserver.wms.WatermarkInfoImpl",
"org.geoserver.wfs.GMLInfoImpl"
});
} }
public <T extends Info> T entryToObject(InputStream in, Class<T> target) { public <T extends Info> T entryToObject(InputStream in, Class<T> target) {
......
...@@ -60,5 +60,6 @@ ...@@ -60,5 +60,6 @@
</bean> </bean>
<bean id="JDBCCacheProvider" class="org.geoserver.jdbcconfig.internal.JDBCCacheProvider"/> <bean id="JDBCCacheProvider" class="org.geoserver.jdbcconfig.internal.JDBCCacheProvider"/>
<bean id="JDBCConfigXStreamPersisterInitializer" class="org.geoserver.jdbcconfig.internal.JDBCConfigXStreamPersisterInitializer"/>
</beans> </beans>
...@@ -16,17 +16,19 @@ import java.util.ArrayList; ...@@ -16,17 +16,19 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.dbcp.BasicDataSource;
import org.geoserver.catalog.impl.CatalogImpl; import org.geoserver.catalog.impl.CatalogImpl;
import org.geoserver.config.util.XStreamPersisterFactory; import org.geoserver.config.util.XStreamPersisterFactory;
import org.geoserver.config.util.XStreamPersisterInitializer;
import org.geoserver.jdbcconfig.internal.ConfigDatabase; import org.geoserver.jdbcconfig.internal.ConfigDatabase;
import org.geoserver.jdbcconfig.internal.DbMappings; import org.geoserver.jdbcconfig.internal.DbMappings;
import org.geoserver.jdbcconfig.internal.Dialect; import org.geoserver.jdbcconfig.internal.Dialect;
import org.geoserver.jdbcconfig.internal.JDBCConfigXStreamPersisterInitializer;
import org.geoserver.jdbcconfig.internal.Util; import org.geoserver.jdbcconfig.internal.Util;
import org.geoserver.jdbcconfig.internal.XStreamInfoSerialBinding; import org.geoserver.jdbcconfig.internal.XStreamInfoSerialBinding;
import org.geoserver.platform.GeoServerExtensionsHelper; import org.geoserver.platform.GeoServerExtensionsHelper;
...@@ -211,11 +213,13 @@ public class JDBCConfigTestSupport { ...@@ -211,11 +213,13 @@ public class JDBCConfigTestSupport {
// just to avoid hundreds of warnings in the logs about extension lookups with no app // just to avoid hundreds of warnings in the logs about extension lookups with no app
// context set // context set
appContext = createNiceMock(WebApplicationContext.class); appContext = createNiceMock(WebApplicationContext.class);
GeoServerExtensionsHelper.init(appContext);
configureAppContext(appContext); configureAppContext(appContext);
replay(appContext); replay(appContext);
GeoServerExtensionsHelper.init(appContext);
GeoServerExtensionsHelper.singleton("JDBCConfigXStreamPersisterInitializer", new JDBCConfigXStreamPersisterInitializer(), XStreamPersisterInitializer.class);
// final File testDbDir = new File("target", "jdbcconfig"); // final File testDbDir = new File("target", "jdbcconfig");
// FileUtils.deleteDirectory(testDbDir); // FileUtils.deleteDirectory(testDbDir);
// testDbDir.mkdirs(); // testDbDir.mkdirs();
...@@ -238,10 +242,13 @@ public class JDBCConfigTestSupport { ...@@ -238,10 +242,13 @@ public class JDBCConfigTestSupport {
} }
protected void configureAppContext(WebApplicationContext appContext) { protected void configureAppContext(WebApplicationContext appContext) {
expect(appContext.containsBean("JDBCConfigXStreamPersisterInitializer")).andStubReturn(true);
expect(appContext.getBeansOfType((Class) anyObject())) expect(appContext.getBeansOfType((Class) anyObject()))
.andReturn(Collections.EMPTY_MAP).anyTimes(); .andReturn(Collections.EMPTY_MAP).anyTimes();
expect(appContext.getBeanNamesForType((Class) anyObject())) expect(appContext.getBeanNamesForType((Class) anyObject()))
.andReturn(new String[] {}).anyTimes(); .andReturn(new String[] {}).anyTimes();
ServletContext servletContext = createNiceMock(ServletContext.class); ServletContext servletContext = createNiceMock(ServletContext.class);
replay(servletContext); replay(servletContext);
...@@ -259,6 +266,7 @@ public class JDBCConfigTestSupport { ...@@ -259,6 +266,7 @@ public class JDBCConfigTestSupport {
dataSource.close(); dataSource.close();
} }
} }
GeoServerExtensionsHelper.clear();
} }
public GeoServerResourceLoader getResourceLoader() { public GeoServerResourceLoader getResourceLoader() {
......
...@@ -19,9 +19,12 @@ import org.geoserver.config.ServiceInfo; ...@@ -19,9 +19,12 @@ import org.geoserver.config.ServiceInfo;
import org.geoserver.config.impl.GeoServerImpl; import org.geoserver.config.impl.GeoServerImpl;
import org.geoserver.config.impl.ServiceInfoImpl; import org.geoserver.config.impl.ServiceInfoImpl;
import org.geoserver.config.impl.SettingsInfoImpl; import org.geoserver.config.impl.SettingsInfoImpl;
import org.geoserver.config.util.XStreamPersisterInitializer;
import org.geoserver.jdbcconfig.JDBCConfigTestSupport; import org.geoserver.jdbcconfig.JDBCConfigTestSupport;
import org.geoserver.jdbcconfig.catalog.JDBCCatalogFacade; import org.geoserver.jdbcconfig.catalog.JDBCCatalogFacade;
import org.geoserver.jdbcconfig.internal.ConfigDatabase; import org.geoserver.jdbcconfig.internal.ConfigDatabase;
import org.geoserver.jdbcconfig.internal.JDBCConfigXStreamPersisterInitializer;
import org.geoserver.platform.GeoServerExtensionsHelper;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment