@Test public void testWfsCascadeEntityExpansion() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); DataStoreInfo ds = cb.buildDataStore("wfs-xxe"); URL url = getClass().getResource("wfs1.1.0Capabilities-xxe.xml"); ds.getConnectionParameters().put(WFSDataStoreFactory.URL.key, url); // required or the store won't fetch caps from a file ds.getConnectionParameters().put("TESTING", Boolean.TRUE); final ResourcePool rp = getCatalog().getResourcePool(); try { rp.getDataStore(ds); fail("Store creation should have failed to to XXE attack"); } catch (Exception e) { String message = e.getMessage(); assertThat(message, containsString("Entity resolution disallowed")); assertThat(message, containsString("file:///file/not/there")); } }
@Test public void testMetadataFromFeatueSource() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); cb.setStore(cb.buildDataStore("fooStore")); FeatureType ft = createMock(FeatureType.class); expect(ft.getName()).andReturn(new NameImpl("foo")).anyTimes(); expect(ft.getCoordinateReferenceSystem()).andReturn(null).anyTimes(); expect(ft.getGeometryDescriptor()).andReturn(null).anyTimes(); replay(ft); ResourceInfo rInfo = createMock(ResourceInfo.class); expect(rInfo.getTitle()).andReturn("foo title"); expect(rInfo.getDescription()).andReturn("foo description"); expect(rInfo.getKeywords()) .andReturn(new LinkedHashSet<String>(Arrays.asList("foo", "bar", "baz", ""))) .anyTimes(); replay(rInfo); FeatureSource fs = createMock(FeatureSource.class); expect(fs.getSchema()).andReturn(ft).anyTimes(); expect(fs.getInfo()).andReturn(rInfo).anyTimes(); expect(fs.getName()).andReturn(ft.getName()).anyTimes(); replay(fs); FeatureTypeInfo ftInfo = cb.buildFeatureType(fs); assertEquals("foo title", ftInfo.getTitle()); assertEquals("foo description", ftInfo.getDescription()); assertTrue(ftInfo.getKeywords().contains(new Keyword("foo"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("bar"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("baz"))); }
@Test public void testLookupFreshlyAdded() { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(getCatalog()); String nsURI = catalog.getDefaultNamespace().getURI(); URL buildings = MockData.class.getResource("Buildings.properties"); File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("freshOffTheBoat"); storeInfo.getConnectionParameters().put("directory", testData); storeInfo.getConnectionParameters().put("namespace", nsURI); catalog.save(storeInfo); CatalogRepository repository = getCatalog().getResourcePool().getRepository(); DataStore store = repository.dataStore(new NameImpl("freshOffTheBoat")); assertNotNull(store); } }
URL buildings = MockData.class.getResource("Buildings.properties"); File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("store"); storeInfo.getConnectionParameters().put("directory", testData); storeInfo.getConnectionParameters().put("namespace", nsURI);
public DataStoreInfo createStore(ImportData data, WorkspaceInfo workspace, Catalog catalog) throws IOException { Map<String,Serializable> params = createConnectionParameters(data); if (params == null) { return null; } CatalogBuilder cb = new CatalogBuilder(catalog); cb.setWorkspace(workspace); DataStoreInfo store = cb.buildDataStore(data.getName()); store.setType(factory().getDisplayName()); store.getConnectionParameters().putAll(params); return store; }
public DataStoreInfo createStore(ImportData data, WorkspaceInfo workspace, Catalog catalog) throws IOException { Map<String, Serializable> params = createConnectionParameters(data, catalog); if (params == null) { return null; } CatalogBuilder cb = new CatalogBuilder(catalog); cb.setWorkspace(workspace); DataStoreInfo store = cb.buildDataStore(data.getName()); DataStoreFactorySpi factory = factory(); if (store.getName() == null) { store.setName(factory.getDisplayName()); } store.setType(factory().getDisplayName()); store.getConnectionParameters().putAll(params); return store; }
si = builder.buildDataStore(generalParams.name); si.setDescription(generalParams.description); si.getConnectionParameters().putAll(params);
LOGGER.info("Auto-configuring datastore: " + storeName); info = builder.buildDataStore(storeName); add = true;
/** * Either retrieves the corresponding FeatureTypeInfo from the catalog or fakes one with the * necessary information * * @param c */ private FeatureTypeInfo getFeatureTypeInfo(SimpleFeatureType schema) { FeatureTypeInfo ftInfo = catalog.getFeatureTypeByName(schema.getName()); if (ftInfo == null) { // SG the fc might have been generated by the WPS therefore there is no such a thing // inside the GeoServer catalogue final SimpleFeatureSource featureSource = DataUtilities.source(new ListFeatureCollection(schema)); final CatalogBuilder catalogBuilder = new CatalogBuilder(catalog); catalogBuilder.setStore(catalogBuilder.buildDataStore(schema.getName().getLocalPart())); ftInfo = catalogBuilder.buildFeatureType(featureSource); } return ftInfo; }
LOGGER.info("Auto-configuring datastore: " + datastore); info = builder.buildDataStore( datastore ); add = true;
DataStoreInfo store = cb.buildDataStore("dummy"); cb.setStore(store);
DataStoreInfo store = cb.buildDataStore("dummy"); cb.setStore(store);
builder.setWorkspace(workspace); StoreInfo si = builder.buildDataStore(generalParams.name); si.setDescription(generalParams.description); si.getConnectionParameters().putAll(params);