Skip to content

Commit

Permalink
[GEOS-9254] WMTS multidimensional community module summaries are not …
Browse files Browse the repository at this point in the history
…affected by the security subsystem
  • Loading branch information
aaime committed Jun 17, 2019
1 parent 987ad40 commit aa90ee1
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ private LayerInfo getLayerInfo(TileLayer tileLayer, String layerName) {
// dimensions are not supported for layers groups
return null;
}
return (LayerInfo) publishedInfo;
// go through the catalog to make sure we get all the wrapping necessary, including
// security
return catalog.getLayer(publishedInfo.getId());
}
// let's see if we are in the context of a virtual service
WorkspaceInfo localWorkspace = LocalWorkspace.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* (c) 2019 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*
*/

/* (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.
*/
package org.geoserver.gwc.wmts;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.DimensionInfo;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.gwc.wmts.dimensions.Dimension;
import org.geoserver.gwc.wmts.dimensions.DimensionsUtils;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.security.CatalogMode;
import org.geoserver.security.ResourceAccessManager;
import org.geoserver.security.TestResourceAccessManager;
import org.geoserver.security.VectorAccessLimits;
import org.geotools.factory.CommonFactoryFinder;
import org.junit.Test;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory;

/**
* Performs integration tests using a mock {@link ResourceAccessManager}
*
* @author Andrea Aime - GeoSolutions
*/
public class ResourceAccessManagerVectorTimeTest extends VectorTimeTestSupport {

/** Add the test resource access manager in the spring context */
@Override
protected void setUpSpring(List<String> springContextLocations) {
super.setUpSpring(springContextLocations);
springContextLocations.add("classpath:/ResourceAccessManagerContext.xml");
}

/** Enable the Spring Security auth filters */
@Override
protected List<javax.servlet.Filter> getFilters() {
return Collections.singletonList(
(javax.servlet.Filter) GeoServerExtensions.bean("filterChainProxy"));
}

/** Add the users */
@Override
protected void onSetUp(SystemTestData testData) throws Exception {
super.onSetUp(testData);
addUser("cite", "cite", null, Collections.singletonList("ROLE_DUMMY"));
addUser("cite_high", "cite", null, Collections.singletonList("ROLE_DUMMY"));
addUser("cite_low", "cite", null, Collections.singletonList("ROLE_DUMMY"));

// ------

FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

// populate the access manager
TestResourceAccessManager tam =
(TestResourceAccessManager) applicationContext.getBean("testResourceAccessManager");
Catalog catalog = getCatalog();
FeatureTypeInfo vector = catalog.getFeatureTypeByName(getLayerId(VECTOR_ELEVATION));

// Give cite_high only records with higher elevation
Filter elevationHigh = ff.greater(ff.property("startElevation"), ff.literal(2));
tam.putLimits(
"cite_high",
vector,
new VectorAccessLimits(CatalogMode.HIDE, null, elevationHigh, null, null));

// And cite_low the opposite
Filter elevationLow = ff.lessOrEqual(ff.property("startElevation"), ff.literal(2));
tam.putLimits(
"cite_low",
vector,
new VectorAccessLimits(CatalogMode.HIDE, null, elevationLow, null, null));
}

@Test
public void testGetDomainsValuesCiteHigh() throws Exception {
login("cite_high", "cite_high");
// high elevations are associated only to the 11th (start date)
testDomainsValuesRepresentation(DimensionsUtils.NO_LIMIT, "2012-02-11T00:00:00.000Z");
testDomainsValuesRepresentation(0, "2012-02-11T00:00:00.000Z--2012-02-11T00:00:00.000Z");
}

@Test
public void testGetDomainsValuesCiteLow() throws Exception {
login("cite_low", "cite_low");
// high elevations are associated only to both start dates
testDomainsValuesRepresentation(
DimensionsUtils.NO_LIMIT, "2012-02-11T00:00:00.000Z", "2012-02-12T00:00:00.000Z");
testDomainsValuesRepresentation(0, "2012-02-11T00:00:00.000Z--2012-02-12T00:00:00.000Z");
}

@Test
public void testGetHistogramHigh() {
login("cite_high", "cite_high");
DimensionInfo dimensionInfo = createDimension(true, null);
Dimension dimension = buildDimension(dimensionInfo);
Tuple<String, List<Integer>> histogram = dimension.getHistogram(Filter.INCLUDE, "P1D");
assertThat(histogram.first, is("2012-02-11T00:00:00.000Z/2012-02-12T00:00:00.000Z/P1D"));
// both in the same day
assertThat(histogram.second, equalTo(Arrays.asList(2)));
}

@Test
public void testGetHistogramLow() {
login("cite_low", "cite_low");
DimensionInfo dimensionInfo = createDimension(true, null);
Dimension dimension = buildDimension(dimensionInfo);
Tuple<String, List<Integer>> histogram = dimension.getHistogram(Filter.INCLUDE, "P1D");
assertThat(histogram.first, is("2012-02-11T00:00:00.000Z/2012-02-13T00:00:00.000Z/P1D"));
// one per day
assertThat(histogram.second, equalTo(Arrays.asList(1, 1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* This class contains tests that check that time dimensions values are correctly extracted from
* vector data.
*/
public class VectorTimeDimensionTest extends TestsSupport {
public class VectorTimeDimensionTest extends VectorTimeTestSupport {

@Test
public void testDisabledDimension() throws Exception {
Expand Down Expand Up @@ -76,16 +76,4 @@ public void testGetHistogram() {
assertThat(histogram.first, is("2012-02-11T00:00:00.000Z/2012-02-13T00:00:00.000Z/P1D"));
assertThat(histogram.second, equalTo(Arrays.asList(3, 1)));
}

/** Helper method that just returns the current layer info. */
private LayerInfo getLayerInfo() {
return catalog.getLayerByName(VECTOR_ELEVATION.getLocalPart());
}

/** Helper method that just returns the current vector info. */
private FeatureTypeInfo getVectorInfo() {
LayerInfo layerInfo = getLayerInfo();
assertThat(layerInfo.getResource(), instanceOf(FeatureTypeInfo.class));
return (FeatureTypeInfo) layerInfo.getResource();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* (c) 2019 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*
*/

package org.geoserver.gwc.wmts;

import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;

import org.geoserver.catalog.DimensionInfo;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.ResourceInfo;
import org.geoserver.gwc.wmts.dimensions.Dimension;
import org.geoserver.gwc.wmts.dimensions.VectorTimeDimension;

/** Common methods to test ND on vector/time */
abstract class VectorTimeTestSupport extends TestsSupport {

@Override
protected Dimension buildDimension(DimensionInfo dimensionInfo) {
dimensionInfo.setAttribute("startTime");
FeatureTypeInfo rasterInfo = getVectorInfo();
Dimension dimension = new VectorTimeDimension(wms, getLayerInfo(), dimensionInfo);
rasterInfo.getMetadata().put(ResourceInfo.TIME, dimensionInfo);
getCatalog().save(rasterInfo);
return dimension;
}

/** Helper method that just returns the current vector info. */
protected FeatureTypeInfo getVectorInfo() {
LayerInfo layerInfo = getLayerInfo();
assertThat(layerInfo.getResource(), instanceOf(FeatureTypeInfo.class));
return (FeatureTypeInfo) layerInfo.getResource();
}

/** Helper method that just returns the current layer info. */
protected LayerInfo getLayerInfo() {
return catalog.getLayerByName(VECTOR_ELEVATION.getLocalPart());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="testResourceAccessManager" class="org.geoserver.security.TestResourceAccessManager"/>
</beans>

0 comments on commit aa90ee1

Please sign in to comment.