Commit a352022f authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-7442] XStream remote execution filters disallow changing configuration of JMS clusters

parent 1d2939c9
......@@ -235,6 +235,21 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-restconfig</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -26,6 +26,8 @@ import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Resource;
import com.thoughtworks.xstream.XStream;
/**
*
* @author Carlo Cancellieri - GeoSolutions SAS
......@@ -135,5 +137,10 @@ public class ClusterResource extends ReflectiveResource {
return cfg;
}
}
@Override
protected void configureXStream(XStream xstream) {
xstream.allowTypes(new Class[] { Properties.class });
}
}
package org.geoserver.cluster.rest;
import static org.junit.Assert.*;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import org.geoserver.test.GeoServerSystemTestSupport;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletResponse;
import org.w3c.dom.Document;
public class ClusterResourceTest extends GeoServerSystemTestSupport {
@Before
public void login() throws Exception {
login("admin", "geoserver", "ROLE_ADMINISTRATOR");
}
@Test
public void testGetConfiguration() throws Exception {
Document dom = getAsDOM("rest/cluster.xml");
// print(dom);
// checking a property that's unlikely to change
assertXpathEvaluatesTo("VirtualTopic.>", "/properties/property[@name='topicName']/@value", dom);
}
@Test
public void testUpdateConfiguration() throws Exception {
String config = "<properties><property name=\"toggleSlave\" value=\"false\"/></properties>";
MockHttpServletResponse response = postAsServletResponse("rest/cluster.xml", config);
assertEquals(201, response.getStatus());
Document dom = getAsDOM("rest/cluster.xml");
// print(dom);
// checking the property just modified
assertXpathEvaluatesTo("false", "/properties/property[@name='toggleSlave']/@value", dom);
}
}
package org.geoserver.jms.test.rest;
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
//
//package org.geoserver.cluster.test.rest;
//
//
//import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
//import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.FilenameFilter;
//import java.io.IOException;
//
//import org.apache.commons.io.FilenameUtils;
//import org.apache.commons.io.filefilter.SuffixFileFilter;
//import org.apache.log4j.Logger;
//import org.junit.Test;
//import org.springframework.core.io.ClassPathResource;
//
///**
// * Testcase for publishing layers on geoserver.
// * We need a running GeoServer to properly run the tests.
// * Login credentials are hardcoded at the moment (localhost:8080 admin/geoserver).
// * If such geoserver instance cannot be contacted, tests will be skipped.
// *
// *
// * @author etj
// */
//public class ConfigTest extends GeoserverRESTTest {
// private final static Logger LOGGER = Logger.getLogger(ConfigTest.class);
//
// private static final String DEFAULT_WS = "geosolutions";
//
//
// public ConfigTest() {
// super("ConfigTest");
// }
//
//
// @Test
//// @Ignore
// public void publishDBLayer() throws FileNotFoundException, IOException {
// if (!enabled()) return;
// deleteAll();
//
//// assertTrue(reader.getWorkspaces().isEmpty());
// assertTrue(publisher.createWorkspace(DEFAULT_WS));
//
// insertStyles();
// insertExternalGeotiff();
// insertShape();
//
// boolean ok = publisher.publishDBLayer(DEFAULT_WS, "pg_kids", "easia_gaul_0_aggr", "EPSG:4326", "default_polygon");
// assertTrue(ok);
// }
//
// @Test
//// @Ignore
// public void insertStyles() throws FileNotFoundException, IOException {
// if (!enabled()) return;
// deleteAll();
//
// File sldDir = new ClassPathResource("testdata").getFile();
// for(File sldFile : sldDir.listFiles((FilenameFilter)new SuffixFileFilter(".sld"))) {
// String basename = FilenameUtils.getBaseName(sldFile.toString());
// LOGGER.info("Publishing style " + sldFile + " as " + basename);
// assertTrue("Cound not publish " + sldFile, publisher.publishStyle(sldFile, basename));
// }
// }
//
// @Test
//// @Ignore
// public void insertExternalGeotiff() throws FileNotFoundException, IOException {
// if (!enabled()) return;
// deleteAll();
//
// String storeName = "testRESTStoreGeotiff";
//
// File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
// RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
//
// assertNotNull(pc);
// }
//
// @Test
//// @Ignore
// public void insertShape() {
// if (!enabled()) return;
// deleteAll();
//
// File zipFile;
// try {
// zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
// assertTrue("publish() failed", publisher.publishShp(DEFAULT_WS, "anyname", "anyname", zipFile, "EPSG:4326", "default_point"));
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// fail();
// }
//
// //test delete
//// boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, "anyname", "cities");
//// assertTrue("Unpublish() failed", ok);
//
// // remove also datastore
//// boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, "anyname");
//// assertTrue("removeDatastore() failed", dsRemoved);
// }
//
//}
\ No newline at end of file
package org.geoserver.jms.test.rest;
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
//
//package org.geoserver.cluster.test.rest;
//
//import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
//import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
//import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
//import it.geosolutions.geoserver.rest.encoder.coverage.GSImageMosaicEncoder;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//
//import org.apache.log4j.Logger;
//import org.junit.Test;
//import org.springframework.core.io.ClassPathResource;
//
///**
// * Testcase for publishing layers on geoserver. We need a running GeoServer to
// * properly run the tests. If such geoserver instance cannot be contacted, tests
// * will be skipped.
// *
// * @author etj
// * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
// */
//public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
//
// private final static Logger LOGGER = Logger.getLogger(GeoserverRESTPublisherTest.class);
//
// public GeoserverRESTPublisherTest() {
// super("GeoserverRESTPublisherTest");
// }
//
// @Test
// public void testWorkspaces() {
// if (!enabled())
// return;
// deleteAll();
//
// assertEquals(0, masterReader.getWorkspaces().size());
//
// assertTrue(publisher.createWorkspace("WS1"));
// assertTrue(publisher.createWorkspace("WS2"));
// assertEquals(2, masterReader.getWorkspaces().size());
//
// try {
// Thread.sleep(TIMEOUT);
// } catch (InterruptedException e) {
// fail(e.getLocalizedMessage());
// }
// for (int i = 0; i < nSlaves; i++) {
// assertEquals(2, reader[i].getWorkspaces().size());
// }
// }
//
// final static String styleName = "restteststyle";
//
// @Test
// public void testExternalGeotiff() throws FileNotFoundException, IOException {
// if (!enabled())
// return;
// deleteAll();
//
// assertEquals(0, masterReader.getStyles().size());
//
// File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
//
// // insert style
// assertTrue(publisher.publishStyle(sldFile));
// assertTrue(masterReader.existsStyle(styleName));
//
// try {
// Thread.sleep(TIMEOUT);
// } catch (InterruptedException e) {
// fail(e.getLocalizedMessage());
// }
// for (int i = 0; i < nSlaves; i++) {
// assertTrue(reader[i].existsStyle(styleName));
// }
//
// String storeName = "testRESTStoreGeotiff";
// String layerName = "resttestdem";
//
// if (masterReader.getWorkspaces().isEmpty())
// assertTrue(publisher.createWorkspace(DEFAULT_WS));
//
// File geotiff = new File("/media/share/testdata/resttestdem.tif");
//
// // known state?
// // assertFalse("Cleanup failed", existsLayer(layerName));
//
// // test insert
// assertTrue("publish() failed", publisher.publishGeoTIFF(DEFAULT_WS, storeName, storeName, geotiff,
// "EPSG:4326", ProjectionPolicy.FORCE_DECLARED,
// styleName));
//
// assertTrue(existsLayer(layerName));
//
// RESTCoverageStore reloadedCS = masterReader.getCoverageStore(DEFAULT_WS, storeName);
// assertNotNull(reloadedCS);
// try {
// Thread.sleep(TIMEOUT);
// } catch (InterruptedException e) {
// fail(e.getLocalizedMessage());
// }
// for (int i = 0; i < nSlaves; i++) {
// RESTCoverageStore slaveCS = reader[i].getCoverageStore(DEFAULT_WS, storeName);
// assertNotNull("Unable to get coverageStore for reader n.:" + i, slaveCS);
// // assertTrue(reloadedCS.equals(slaveCS));
// }
//
// }
//
// @Test
// public void testCreateDeleteImageMosaicDatastore() {
// if (!enabled()) {
// return;
// }
// deleteAll();
//
// final String coverageStoreName = "resttestImageMosaic";
//
// final GSImageMosaicEncoder coverageEncoder = new GSImageMosaicEncoder();
//
// coverageEncoder.setAllowMultithreading(true);
// coverageEncoder.setBackgroundValues("");
// coverageEncoder.setFilter("");
// coverageEncoder.setInputTransparentColor("");
// coverageEncoder.setLatLonBoundingBox(-180, -90, 180, 90, "EPSG:4326");
// coverageEncoder.setMaxAllowedTiles(6000);
// coverageEncoder.setNativeBoundingBox(-180, -90, 180, 90, "EPSG:4326");
// coverageEncoder.setOutputTransparentColor("");
// coverageEncoder.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
// coverageEncoder.setSRS("EPSG:4326");
// coverageEncoder.setSUGGESTED_TILE_SIZE("256,256");
// coverageEncoder.setUSE_JAI_IMAGEREAD(true);
// // activate time
// // final GSDimensionInfoEncoder time=new GSDimensionInfoEncoder(true);
// // time.setPresentation(Presentation.LIST);
// // // set time metadata
// // coverageEncoder.setMetadata("time", time);
// // // not active elevation
// // coverageEncoder.setMetadata("elevation", new
// // GSDimensionInfoEncoder());
//
// if (masterReader.getWorkspaces().isEmpty())
// assertTrue(publisher.createWorkspace(DEFAULT_WS));
//
// LOGGER.info(coverageEncoder.toString());
//
// // final String styleName = "testRasterStyle3";
// // File sldFile;
// // try {
// // sldFile = new ClassPathResource("testdata/raster.sld").getFile();
// // // insert style
// // assertTrue(publisher.publishStyle(sldFile,styleName));
// // } catch (IOException e1) {
// // assertFalse(e1.getLocalizedMessage(),Boolean.FALSE);
// // e1.printStackTrace();
// // }
//
// GSLayerEncoder layerEncoder = new GSLayerEncoder();
//
// layerEncoder.setDefaultStyle(styleName);
// LOGGER.info(layerEncoder.toString());
// // creation test
// RESTCoverageStore coverageStore = null;
// try {
// final File mosaicFile = new File("/media/share/time_geotiff/");
//
// if (!publisher.createExternalMosaic(DEFAULT_WS, coverageStoreName, mosaicFile, coverageEncoder,
// layerEncoder)) {
// fail();
// }
// coverageStore = masterReader.getCoverageStore(DEFAULT_WS, coverageStoreName);
//
// if (coverageStore == null) {
// LOGGER.error("*** coveragestore " + coverageStoreName + " has not been created.");
// fail("*** coveragestore " + coverageStoreName + " has not been created.");
// }
//
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// fail(e.getLocalizedMessage());
// } catch (IOException e) {
// e.printStackTrace();
// fail(e.getLocalizedMessage());
// }
//
// // removing recursively coveragestore
// boolean removed = publisher.removeCoverageStore(coverageStore.getWorkspaceName(),
// coverageStore.getName(), true);
// if (!removed) {
// LOGGER.error("*** CoverageStore " + coverageStoreName + " has not been removed.");
// fail("*** CoverageStore " + coverageStoreName + " has not been removed.");
// }
//
// }
//
// private boolean existsLayer(String layername) {
// try {
// Thread.sleep(TIMEOUT);
// } catch (InterruptedException e) {
// fail(e.getLocalizedMessage());
// }
// boolean test = masterReader.getLayer(layername) != null;
// if (!test) {
// LOGGER.info("Layer is not present on the master");
// return test;
// }
// for (int i = 0; i < nSlaves; i++) {
// test = test && (reader[i].getLayer(layername) != null);
// if (!test) {
// LOGGER.info("Layer is not present on slave n: " + i + " toString: " + reader[i].toString());
// }
// }
// return test;
// }
//}
package org.geoserver.jms.test.rest;
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
//package org.geoserver.cluster.test.rest;
//
//
//
//import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
//import it.geosolutions.geoserver.rest.GeoServerRESTReader;
//import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
//import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
//import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
//import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
//import it.geosolutions.geoserver.rest.decoder.RESTLayer;
//import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
//import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
//
//import java.net.MalformedURLException;
//import java.net.URL;
//import java.util.List;
//
//import org.apache.log4j.Logger;
//import org.junit.Assert;
//import org.junit.Before;
//
///**
// * Initializes REST params.
// * <P>
// * <B>These tests are destructive, so you have to explicitly enable them</B>
// * by setting the env var <TT>jms_mastertest</TT> to <TT>true</TT>.
// * <P>
// * The target geoserver instance can be customized by defining the following env vars: <ul>
// * <LI><TT>jms_masterurl</TT> (default <TT>http://localhost:8181/geoserver</TT>)</LI>
// * <LI><TT>jms_masteruser</TT> (default: <TT>admin</TT>)</LI>
// * <LI><TT>jms_masterpass</TT> (default: <TT>geoserver</TT>)</LI>
// * </ul>
// *
// * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
// * @author etj
// */
//public abstract class GeoserverRESTTest extends Assert {
// private final static Logger LOGGER = Logger.getLogger(GeoserverRESTTest.class);
//
// protected static final String DEFAULT_WS = "geosolutions";
//
// public static final String RESTURL;
// public static final String RESTUSER;
// public static final String RESTPW;
// public static final GeoServerRESTReader masterReader;
//
// public static final String CLIENT_RESTURL[];
// public static final String CLIENT_RESTUSER[];
// public static final String CLIENT_RESTPW[];
// public static final GeoServerRESTReader reader[];
// public static final int nSlaves;
//
// public static final long TIMEOUT;
// public static final GeoServerRESTPublisher publisher;
//
// private static boolean enabled = false;
// private static Boolean existgs = null;
//
// static {
// RESTURL = getenv("jms_masterurl", "http://192.168.1.56:8080/geoserver");
// RESTUSER = getenv("jms_masteruser", "admin");
// RESTPW = getenv("jms_masterpass", "geoserver");
// URL lurl = null;
// try {
// lurl = new URL(RESTURL);
//
// } catch (MalformedURLException e) {
// fail(e.getLocalizedMessage());
// }
// masterReader = new GeoServerRESTReader(lurl, RESTUSER, RESTPW);
//
//
// final String CLIENT_RESTURL_str = getenv("jms_slaveurl", "http://192.168.1.57:8080/geoserver,http://192.168.1.58:8080/geoserver");
// final String CLIENT_RESTUSER_str = getenv("jms_slaveuser", "admin,admin");
// final String CLIENT_RESTPW_str = getenv("jms_slavepw", "geoserver,geoserver");
//
// TIMEOUT= Integer.parseInt(getenv("jms_slavetimeout", "1000"));
//
// CLIENT_RESTURL=CLIENT_RESTURL_str.split(",");
// CLIENT_RESTUSER=CLIENT_RESTUSER_str.split(",");
// CLIENT_RESTPW=CLIENT_RESTPW_str.split(",");
//
// nSlaves=CLIENT_RESTURL.length;
// if (nSlaves!= CLIENT_RESTPW.length || nSlaves!= CLIENT_RESTUSER.length){
// throw new IllegalArgumentException("bad nSlaves settings");
// }
//
// // These tests will destroy data, so let's make sure we do want to run them
// enabled = getenv("jms_mastertest", "false").equalsIgnoreCase("true");
// if( ! enabled )
// LOGGER.warn("Tests are disabled. Please read the documentation to enable them.");
//
// reader = new GeoServerRESTReader[nSlaves];
// for (int i=0; i< nSlaves; i++){
// try {
//
// lurl = new URL(CLIENT_RESTURL[i]);
// reader[i] = new GeoServerRESTReader(lurl, CLIENT_RESTUSER[i], CLIENT_RESTPW[i]);
//
// } catch (MalformedURLException ex) {
// fail(ex.getLocalizedMessage());
// }
// }
//
// publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);
// }
//
// private static String getenv(String envName, String envDefault) {
// String env = System.getenv(envName);
// String ret = System.getProperty(envName, env);
// LOGGER.debug("env var " + envName + " is " + ret);
// return ret != null? ret : envDefault;
// }
//
//
//
// private String testName;
//
// public GeoserverRESTTest(String testName) {
// this.testName=testName;
// }
//
// @Before
// public void setUp() throws Exception {
//
// if(enabled) {
// if(existgs == null) {
// existgs=masterReader.existGeoserver();
// for (int i=0; i< nSlaves; i++){
// existgs = (existgs.booleanValue() && reader[i].existGeoserver());
// }
// if ( ! existgs ) {
// LOGGER.error("TESTS WILL FAIL BECAUSE NO GEOSERVER WAS FOUND AT " + RESTURL + " ("+ RESTUSER+":"+RESTPW+")");
// } else {
// LOGGER.info("Using geoserver instance " + RESTUSER+":"+RESTPW+ " @ " + RESTURL);
// }
// }
// if ( ! existgs ) {
// System.out.println("Failing test " + this.getClass().getSimpleName() + "::" + this.testName + " : geoserver not found");
// fail("GeoServer not found");