-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOS-9254] WMTS multidimensional community module summaries are not …
…affected by the security subsystem
- Loading branch information
Showing
5 changed files
with
184 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...dimensional/src/test/java/org/geoserver/gwc/wmts/ResourceAccessManagerVectorTimeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ty/wmts-multi-dimensional/src/test/java/org/geoserver/gwc/wmts/VectorTimeTestSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/community/wmts-multi-dimensional/src/test/resources/ResourceAccessManagerContext.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |