protected boolean handleLayerGroup() { // NamedLayer - LayerGroup: ignore any defined styles and use the layer group instead if (info != null && info instanceof LayerGroupInfo) { LayerGroupInfo lg = (LayerGroupInfo) info; List<LayerInfo> layers = lg.layers(); List<StyleInfo> styles = lg.styles(); try { for (int i = 0; i < layers.size(); i++) { info = layers.get(i); StyleInfo style = styles.get(i); if (style == null) { visit(layers.get(i).getDefaultStyle().getStyle()); } else { visit(styles.get(i).getStyle()); } } } catch (IOException e) { throw new UncheckedIOException(e); } return true; } return false; }
@Test public void testLayerGroupNullLayerReferences() { addLayer(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setWorkspace(null); lg.setName("layerGroup2"); lg.getLayers().add(null); lg.getStyles().add(null); lg.getLayers().add(l); lg.getStyles().add(s); lg.getLayers().add(null); lg.getStyles().add(null); catalog.add(lg); LayerGroupInfo resolved = catalog.getLayerGroupByName("layerGroup2"); assertEquals(1, resolved.layers().size()); assertEquals(1, resolved.styles().size()); assertEquals(s, resolved.styles().get(0)); }
@Test public void testLayerGroupNullLayerOrStyleReferences() throws IOException { Catalog catalog = getCatalog(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); LayerInfo l = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS)); StyleInfo s = catalog.getStyleByName("singleStyleGroup"); lg.setWorkspace(null); lg.setName("threeTypeLayerGroup"); // layer with default style lg.getLayers().add(l); lg.getStyles().add(null); // style group lg.getLayers().add(null); lg.getStyles().add(s); lg.getLayers().add(null); lg.getStyles().add(null); catalog.add(lg); LayerGroupInfo resolved = catalog.getLayerGroupByName("threeTypeLayerGroup"); assertEquals(2, resolved.layers().size()); assertEquals(2, resolved.styles().size()); assertEquals(l, resolved.layers().get(0)); assertEquals(s.getStyle(), resolved.styles().get(1).getStyle()); }
@Test public void testSingleStyleGroup() throws Exception { Catalog catalog = getCatalog(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); StyleInfo s = catalog.getStyleByName("singleStyleGroup"); lg.setWorkspace(null); lg.setName("singleStyleLayerGroup"); lg.getLayers().add(null); lg.getStyles().add(s); catalog.add(lg); LayerGroupInfo resolved = catalog.getLayerGroupByName("singleStyleLayerGroup"); assertEquals(1, resolved.layers().size()); assertEquals(1, resolved.styles().size()); assertEquals(s.getStyle(), resolved.styles().get(0).getStyle()); // Test bounds calculation new LayerGroupHelper(lg).calculateBounds(); assertEquals( catalog.getLayerByName((getLayerId(MockData.STREAMS))) .getResource() .getLatLonBoundingBox(), lg.getBounds()); }
assertEquals(lg2.getLayers(), lg2.layers()); assertEquals(lg2.getStyles(), lg2.styles()); assertEquals(lg2.getLayers(), lg2.layers()); assertEquals(lg2.getStyles(), lg2.styles()); assertEquals(lg2.getLayers(), lg2.layers()); assertEquals(lg2.getStyles(), lg2.styles()); assertEquals(lg2.getLayers(), lg2.layers()); fail("Layer group of Type Container can not be rendered"); } catch (UnsupportedOperationException e) { assertEquals(1, lg2.layers().size()); assertEquals(1, lg2.styles().size()); assertEquals(l, lg2.layers().iterator().next()); assertEquals(s, lg2.styles().iterator().next());
LayerGroupInfo resolved = catalog.getLayerGroupByName("multiStyleLayerGroup"); List<LayerInfo> layers = resolved.layers(); List<StyleInfo> styles = resolved.styles();
private List<Interpolation> parseInterpolations( List<Object> requestedLayers, List<String> interpolationList) { List<Interpolation> interpolations = new ArrayList<Interpolation>(); for (int i = 0; i < requestedLayers.size(); i++) { // null interpolation means: // use the default WMS one Interpolation interpolation = null; if (i < interpolationList.size()) { String interpolationName = interpolationList.get(i); if (!interpolationName.trim().equals("")) { interpolation = getInterpolationObject(interpolationName); } } Object o = requestedLayers.get(i); if (o instanceof LayerInfo) { interpolations.add(interpolation); } else if (o instanceof LayerGroupInfo) { List<LayerInfo> subLayers = ((LayerGroupInfo) o).layers(); for (LayerInfo layer : subLayers) { interpolations.add(interpolation); } } else { throw new IllegalArgumentException("Unknown layer info type: " + o); } } return interpolations; }
public List<MapLayerInfo> parseLayerInfos( List<String> requestedLayerNames, URL remoteOwsUrl, String remoteOwsType) throws Exception { List requestedLayerInfos = super.parseLayers(requestedLayerNames, remoteOwsUrl, remoteOwsType); List<MapLayerInfo> layers = new ArrayList<MapLayerInfo>(); for (Object o : requestedLayerInfos) { if (o instanceof LayerInfo) { layers.add(new MapLayerInfo((LayerInfo) o)); } else if (o instanceof LayerGroupInfo) { for (LayerInfo l : ((LayerGroupInfo) o).layers()) { layers.add(new MapLayerInfo(l)); } } else if (o instanceof MapLayerInfo) { // it was a remote OWS layer, add it directly layers.add((MapLayerInfo) o); } } return layers; } }
protected LayerGroupInfo buildEOLayerGroup( String name, LayerInfo rootLayer, StyleInfo style, WorkspaceInfo ws, PublishedInfo... contents) { LayerGroupInfo layerGroup = createNiceMock(LayerGroupInfo.class); expect(layerGroup.getName()).andReturn(name).anyTimes(); expect(layerGroup.prefixedName()) .andReturn((ws != null ? ws.getName() + ":" : "") + name) .anyTimes(); expect(layerGroup.getMode()).andReturn(Mode.EO).anyTimes(); expect(layerGroup.getRootLayer()).andReturn(rootLayer).anyTimes(); expect(layerGroup.getLayers()) .andReturn(new ArrayList<PublishedInfo>(Arrays.asList(contents))) .anyTimes(); expect(layerGroup.getStyles()).andReturn(Arrays.asList(style)).anyTimes(); expect(layerGroup.getWorkspace()).andReturn(ws).anyTimes(); expect(layerGroup.layers()) .andAnswer(() -> new LayerGroupHelper(layerGroup).allLayers()) .anyTimes(); expect(layerGroup.getId()) .andAnswer(() -> (ws == null ? name : ws.getName() + ":" + name) + "-id") .anyTimes(); replay(layerGroup); return layerGroup; }
protected LayerGroupInfo buildLayerGroup( String name, Mode type, WorkspaceInfo ws, PublishedInfo... contents) { LayerGroupInfo layerGroup = createNiceMock(LayerGroupInfo.class); expect(layerGroup.getName()).andReturn(name).anyTimes(); expect(layerGroup.prefixedName()) .andReturn((ws != null ? ws.getName() + ":" : "") + name) .anyTimes(); expect(layerGroup.getMode()).andReturn(type).anyTimes(); expect(layerGroup.getLayers()) .andReturn(new ArrayList<PublishedInfo>(Arrays.asList(contents))) .anyTimes(); expect(layerGroup.getStyles()).andReturn(buildUniqueStylesForLayers(contents)).anyTimes(); expect(layerGroup.getWorkspace()).andReturn(ws).anyTimes(); expect(layerGroup.layers()) .andAnswer(() -> new LayerGroupHelper(layerGroup).allLayers()) .anyTimes(); expect(layerGroup.getId()) .andAnswer(() -> (ws == null ? name : ws.getName() + ":" + name) + "-id") .anyTimes(); replay(layerGroup); return layerGroup; }
@Test public void testWmsNamedTreeAMilitaryOnlyGroupContents() throws Exception { // prepare the stage setupRequestThreadLocal("WMS"); buildManager("lockDownStates.properties"); // try with read only user SecurityContextHolder.getContext().setAuthentication(roUser); final LayerGroupInfo group = sc.getLayerGroupByName(namedTreeA.getName()); assertNotNull(group); // the group should not contain states any more final List<LayerInfo> layers = group.layers(); assertEquals(2, layers.size()); final List<StyleInfo> styles = group.styles(); assertEquals(2, styles.size()); // check the layers and styles are not mis-aligned assertEquals("roads", layers.get(0).getName()); assertEquals("topp-roads-style", styles.get(0).getName()); assertEquals("cities", layers.get(1).getName()); assertEquals("nurc-cities-style", styles.get(1).getName()); }
@Test public void testOpaqueGroup() throws Exception { Document dom = dom(get("wms?request=GetCapabilities&version=1.3.0"), true); // the layer group is there, but not the contained layers assertXpathEvaluatesTo("1", "count(//wms:Layer[wms:Name='opaqueGroup'])", dom); for (LayerInfo l : getCatalog().getLayerGroupByName(OPAQUE_GROUP).layers()) { assertXpathNotExists("//wms:Layer[wms:Name='" + l.prefixedName() + "']", dom); } ; }
@Test public void testOpaqueGroup() throws Exception { Document dom = dom(get("wms?request=GetCapabilities&version=1.1.0"), true); // the layer group is there, but not the contained layers assertXpathEvaluatesTo("1", "count(//Layer[Name='opaqueGroup'])", dom); for (LayerInfo l : getCatalog().getLayerGroupByName(OPAQUE_GROUP).layers()) { assertXpathNotExists("//Layer[Name='" + l.prefixedName() + "']", dom); } }
@Test public void testNestedOpaqueGroup() throws Exception { setupRequestThreadLocal("WMS"); // setup groups LayerGroupInfo opaque = buildLayerGroup( OPAQUE_GROUP_NAME, Mode.OPAQUE_CONTAINER, null, statesLayer, roadsLayer); LayerGroupInfo named = buildLayerGroup(NAMED_GROUP_NAME, Mode.NAMED, null, forestsLayer, opaque); layerGroups = Arrays.asList(named, opaque); populateCatalog(); // setup security buildManager(DEFAULT_RULES); // direct access forests allowed but not states and roads assertNotNull(sc.getLayerByName(forestsLayer.prefixedName())); assertNull(sc.getLayerByName(statesLayer.prefixedName())); assertNull(sc.getLayerByName(roadsLayer.prefixedName())); // however via group access we can see all layers LayerGroupInfo securedNamedGroup = sc.getLayerGroupByName(NAMED_GROUP_NAME); assertEquals(3, securedNamedGroup.layers().size()); LayerGroupInfo securedOpaqueGroup = sc.getLayerGroupByName(OPAQUE_GROUP_NAME); assertEquals(2, securedOpaqueGroup.layers().size()); }
/** * Same as {@link #testWmsStandaloneOpaqueGroup()} but with a nested group as the testing target */ @Test public void testWmsNestedInStandaloneOpaqueGroup() throws Exception { setupRequestThreadLocal("WMS"); // setup group LayerGroupInfo nested = buildLayerGroup(NESTED_GROUP_NAME, Mode.NAMED, null, statesLayer); LayerGroupInfo opaque = buildLayerGroup(OPAQUE_GROUP_NAME, Mode.OPAQUE_CONTAINER, null, nested, roadsLayer); layerGroups = Arrays.asList(nested, opaque); populateCatalog(); // setup security buildManager(DEFAULT_RULES); SecurityContextHolder.getContext().setAuthentication(roUser); // direct access to nested group not allowed, nor to its layers assertNull(sc.getLayerGroupByName(NESTED_GROUP_NAME)); assertNull(sc.getLayerByName(statesLayer.prefixedName())); assertNull(sc.getLayerByName(roadsLayer.prefixedName())); // however we can access the group as part of the opaque one LayerGroupInfo securedGroup = sc.getLayerGroupByName(opaque.prefixedName()); assertNotNull(securedGroup); assertEquals(2, securedGroup.getLayers().size()); assertThat(securedGroup.getLayers(), contains(nested, roadsLayer)); assertThat(securedGroup.layers(), contains(statesLayer, roadsLayer)); }
@Test public void testGetMapLayersInOpaqueGroup() throws Exception { LayerGroupInfo group = getCatalog().getLayerGroupByName(OPAQUE_GROUP); for (PublishedInfo pi : group.layers()) { String url = "wms?LAYERS=" + pi.prefixedName() + "&STYLES=&FORMAT=image%2Fpng" + "&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG%3A4326&WIDTH=256&HEIGHT=256&BBOX=-0.0043,-0.0025,0.0043,0.0025"; Document dom = getAsDOM(url); // print(dom); // should not be found XMLAssert.assertXpathEvaluatesTo("1", "count(/ServiceExceptionReport)", dom); XMLAssert.assertXpathEvaluatesTo("layers", "//ServiceException/@locator", dom); XMLAssert.assertXpathEvaluatesTo("LayerNotDefined", "//ServiceException/@code", dom); } }
@Test public void testFeatureInfoLayersInOpaqueGroup() throws Exception { LayerGroupInfo group = getCatalog().getLayerGroupByName(OPAQUE_GROUP); for (PublishedInfo pi : group.layers()) { final String layerName = pi.prefixedName(); String url = "wms?LAYERS=" + layerName + "&STYLES=&FORMAT=image%2Fpng" + "&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&SRS=EPSG%3A4326&WIDTH=256&HEIGHT=256&BBOX=-0.0043,-0.0025,0.0043,0.0025" + "&info_format=text/plain&request=GetFeatureInfo&&query_layers=" + layerName + "&x=105&y=107"; Document dom = getAsDOM(url); // print(dom); // should not be found XMLAssert.assertXpathEvaluatesTo("1", "count(/ServiceExceptionReport)", dom); XMLAssert.assertXpathEvaluatesTo("layers", "//ServiceException/@locator", dom); XMLAssert.assertXpathEvaluatesTo("LayerNotDefined", "//ServiceException/@code", dom); } }
@Test public void testNestedOpaqueDenyNestedGroup() throws Exception { setupRequestThreadLocal("WMS"); // setup groups LayerGroupInfo opaque = buildLayerGroup( OPAQUE_GROUP_NAME, Mode.OPAQUE_CONTAINER, null, statesLayer, roadsLayer); LayerGroupInfo named = buildLayerGroup(NAMED_GROUP_NAME, Mode.NAMED, null, forestsLayer, opaque); layerGroups = Arrays.asList(named, opaque); populateCatalog(); // setup security, disallow nested group buildManager(new String[] {OPAQUE_GROUP_NAME + ".r=MILITARY"}); // try the ro user SecurityContextHolder.getContext().setAuthentication(roUser); // direct access forests allowed but not states and roads assertNotNull(sc.getLayerByName(forestsLayer.prefixedName())); assertNull(sc.getLayerByName(statesLayer.prefixedName())); assertNull(sc.getLayerByName(roadsLayer.prefixedName())); // and via group access we cannot reach the nested one either LayerGroupInfo securedNamedGroup = sc.getLayerGroupByName(NAMED_GROUP_NAME); assertEquals(1, securedNamedGroup.layers().size()); assertEquals(forestsLayer.getName(), securedNamedGroup.getLayers().get(0).getName()); // nested nor accessible directly either assertNull(sc.getLayerGroupByName(OPAQUE_GROUP_NAME)); }
@Test public void testWmsSingleGroupCMilitaryOnly() throws Exception { // prepare the stage setupRequestThreadLocal("WMS"); buildManager("singleGroupCMilitaryOnly.properties"); // try with read only user, layer group A and its contents should be fine SecurityContextHolder.getContext().setAuthentication(roUser); assertNotNull(sc.getLayerGroupByName(namedTreeA.getName())); assertNotNull(sc.getLayerByName(statesLayer.prefixedName())); assertNotNull(sc.getLayerByName(roadsLayer.prefixedName())); assertNotNull(sc.getLayerByName(citiesLayer.prefixedName())); // layer group B and landmarks should also be accessible assertNotNull(sc.getLayerGroupByName(containerTreeB.prefixedName())); assertNotNull(sc.getLayerByName(landmarksLayer.prefixedName())); // check the single group is not available, but its extra layer is assertNull(sc.getLayerGroupByName(singleGroupC.prefixedName())); assertNotNull(sc.getLayerByName(basesLayer.prefixedName())); // check the mil user sees everything instead SecurityContextHolder.getContext().setAuthentication(milUser); assertNotNull(sc.getFeatureTypeByName("topp:states")); assertNotNull(sc.getLayerGroupByName(namedTreeA.getName())); assertNotNull(sc.getLayerByName(statesLayer.prefixedName())); assertNotNull(sc.getLayerByName(roadsLayer.prefixedName())); assertNotNull(sc.getLayerGroupByName(containerTreeB.prefixedName())); LayerGroupInfo securedSingleGroup = sc.getLayerGroupByName(singleGroupC.prefixedName()); assertNotNull(securedSingleGroup); assertEquals(2, securedSingleGroup.layers().size()); assertEquals(statesLayer.prefixedName(), securedSingleGroup.layers().get(0).prefixedName()); assertEquals(basesLayer.prefixedName(), securedSingleGroup.layers().get(1).prefixedName()); }