@Override public SimpleFeatureCollection getFeatures() throws IOException { return DataUtilities.simple(super.getFeatures()); }
public void modifyFeatures(AttributeDescriptor type, Object value, Filter filter) throws IOException { modifyFeatures(new AttributeDescriptor[] {type}, new Object[] {value}, filter); }
new SecuredFeatureStore(store, WrapperPolicy.readOnlyChallenge(null)); ro.addFeatures(fc); fail("Should have failed with a spring security exception"); } catch (Exception e) { ro.removeFeatures(Filter.INCLUDE); fail("Should have failed with a spring security exception"); } catch (Exception e) { ro.removeFeatures(ECQL.toFilter("IN ('testSchema.1')")); fail("Should have failed with a spring security exception"); } catch (Exception e) { ro.removeFeatures(Filter.EXCLUDE); fail("Should have failed with a spring security exception"); } catch (Exception e) { FeatureCollection rofc = ro.getFeatures(); FeatureIterator roit = rofc.features(); roit.hasNext();
@Test public void testHide() throws Exception { SecuredFeatureStore ro = new SecuredFeatureStore(store, WrapperPolicy.hide(null)); DefaultFeatureCollection fc = new DefaultFeatureCollection(); fc.add(feature); // check the easy ones, those that are not implemented in a read only // collection try { ro.addFeatures(fc); fail("Should have failed with an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // ok } try { ro.removeFeatures(Filter.INCLUDE); fail("Should have failed with an UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // ok } }
@Test public void testUpdateTwiceComplex() throws Exception { // build up the mock FeatureStore fs = createMock(FeatureStore.class); Name[] names = new Name[] {new NameImpl("foo")}; Object[] values = new Object[] {"abc"}; Filter filter = Filter.INCLUDE; fs.modifyFeatures(eq(names), eq(values), eq(filter)); expectLastCall().once(); replay(fs); VectorAccessLimits limits = new VectorAccessLimits( CatalogMode.HIDE, null, Filter.INCLUDE, null, Filter.INCLUDE); SecuredFeatureStore store = new SecuredFeatureStore(fs, WrapperPolicy.readWrite(limits)); store.modifyFeatures(names, values, filter); verify(fs); }
@Test public void testReadOnly() throws Exception { SecuredFeatureStore ro = new SecuredFeatureStore(store, WrapperPolicy.readOnlyHide(null)); // let's check the iterator, should allow read but not remove FeatureCollection rofc = ro.getFeatures(); FeatureIterator roit = rofc.features(); roit.hasNext(); roit.next(); // check derived collections are still read only and share the same // challenge policy SecuredFeatureCollection sorted = (SecuredFeatureCollection) rofc.sort(SortBy.NATURAL_ORDER); assertEquals(ro.policy, sorted.policy); SecuredFeatureCollection sub = (SecuredFeatureCollection) rofc.subCollection(Filter.INCLUDE); assertEquals(ro.policy, sorted.policy); }
} else if (writeQuery.getFilter() == Filter.EXCLUDE || writeQuery.getPropertyNames() == Query.NO_NAMES) { throw unsupportedOperation(); Query mixed = mixQueries(local, writeQuery); final String localName = names[i].getLocalPart(); if (queryNames.contains(localName)) { String typeName = getSchema().getName().getLocalPart(); if (policy.getResponse() == Response.CHALLENGE) { throw SecureCatalogImpl.unauthorizedAccess(typeName);
@Test public void testReadOnlyFeatureStore() throws Exception { // build up the mock SimpleFeatureType schema = createNiceMock(SimpleFeatureType.class); expect(schema.getName()).andReturn(new NameImpl("testFT")); replay(schema); FeatureStore fs = createNiceMock(FeatureStore.class); expect(fs.getSchema()).andReturn(schema); replay(fs); SecuredFeatureStore ro = new SecuredFeatureStore(fs, WrapperPolicy.readOnlyChallenge(null)); try { ro.addFeatures(createNiceMock(FeatureCollection.class)); fail("This should have thrown a security exception"); } catch (Exception e) { if (ReadOnlyDataStoreTest.isSpringSecurityException(e) == false) fail("Should have failed with a security exception"); } }
public void removeFeatures(Filter filter) throws IOException { // are we limiting anything? Query writeQuery = getWriteQuery(policy); if (writeQuery == Query.ALL) { storeDelegate.removeFeatures(filter); } else if (writeQuery.getFilter() == Filter.EXCLUDE || writeQuery.getPropertyNames() == Query.NO_NAMES) { throw unsupportedOperation(); } // get the mixed filter final Query local = new Query(null, filter); Query mixed = mixQueries(local, writeQuery); storeDelegate.removeFeatures(mixed.getFilter()); }
return new SecuredFeatureLocking((FeatureLocking) object, policy); } else if (FeatureStore.class.isAssignableFrom(clazz)) { return new SecuredFeatureStore((FeatureStore) object, policy); } else if (FeatureSource.class.isAssignableFrom(clazz)) { return new SecuredFeatureSource((FeatureSource) object, policy);
throw unsupportedOperation(); } else if (writeQuery == Query.ALL) { new FilteringFeatureCollection<T, F>(collection, writeQuery.getFilter()); if (filtered.size() < collection.size()) { String typeName = getSchema().getName().getLocalPart(); if (policy.response == Response.CHALLENGE) { throw SecureCatalogImpl.unauthorizedAccess(typeName);
/** * Notifies the caller the requested operation is not supported, using a plain {@link * UnsupportedOperationException} in case we have to conceal the fact the data is actually * writable, using an Spring security exception otherwise to force an authentication from the * user */ protected RuntimeException unsupportedOperation() { String typeName = getSchema().getName().getLocalPart(); if (policy.response == Response.CHALLENGE) { return SecureCatalogImpl.unauthorizedAccess(typeName); } else { return new UnsupportedOperationException(typeName + " is read only"); } } }
public void modifyFeatures(Name attributeName, Object attributeValue, Filter filter) throws IOException { modifyFeatures(new Name[] {attributeName}, new Object[] {attributeValue}, filter); }
@Override public SimpleFeatureCollection getFeatures(Filter filter) throws IOException { return DataUtilities.simple(super.getFeatures(filter)); }
public void modifyFeatures(AttributeDescriptor[] types, Object[] values, Filter filter) throws IOException { Name[] names = new Name[types.length]; for (int i = 0; i < types.length; i++) { names[i] = types[i].getName(); } modifyFeatures(names, values, filter); }
@Override public SimpleFeatureCollection getFeatures(Query query) throws IOException { return DataUtilities.simple(super.getFeatures(query)); }