}
@Test
public void testLockedMixed() throws Exception {
SecureCatalogImpl sc = buildTestObject("lockedDownMixed.properties", catalog);
// try with read only user and GetFeatures request
SecurityContextHolder.getContext().setAuthentication(roUser);
Request request = org.easymock.classextension.EasyMock.createNiceMock(Request.class);
org.easymock.classextension.EasyMock.expect(request.getRequest()).andReturn("GetFeatures").anyTimes();
org.easymock.classextension.EasyMock.replay(request);
Dispatcher.REQUEST.set(request);
// check a direct access does trigger a security challenge
try {
sc.getFeatureTypeByName("topp:states");
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
try {
sc.getCoverageByName("nurc:arcgrid");
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
try {
sc.getResourceByName("topp:states", FeatureTypeInfo.class);
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
try {
sc.getResourceByName("nurc:arcgrid", CoverageInfo.class);
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
try {
sc.getWorkspaceByName("topp");
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
try {
sc.getDataStoreByName("states");
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
try {
sc.getDataStoreByName("roads");
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
try {
sc.getCoverageStoreByName("arcGrid");
fail("Should have failed with a security exception");
} catch(Exception e) {
if (ReadOnlyDataStoreTest.isSpringSecurityException(e)==false)
fail("Should have failed with a security exception");
}
// try with a getCapabilities, make sure the lists are empty
request = org.easymock.classextension.EasyMock.createNiceMock(Request.class);
org.easymock.classextension.EasyMock.expect(request.getRequest()).andReturn("GetCapabilities").anyTimes();
org.easymock.classextension.EasyMock.replay(request);
Dispatcher.REQUEST.set(request);
// check the lists used to build capabilities are empty
assertThatBoth(
sc.getFeatureTypes(),
sc.list(FeatureTypeInfo.class, Predicates.acceptAll()),
empty());
assertThatBoth(
sc.getCoverages(),
sc.list(CoverageInfo.class, Predicates.acceptAll()),
empty());
assertThatBoth(
sc.getWorkspaces(),
sc.list(WorkspaceInfo.class, Predicates.acceptAll()),
empty());
// try with write enabled user
SecurityContextHolder.getContext().setAuthentication(rwUser);
assertSame(states, sc.getFeatureTypeByName("topp:states"));
assertSame(arcGrid, sc.getCoverageByName("nurc:arcgrid"));
assertSame(states, sc.getResourceByName("topp:states", FeatureTypeInfo.class));
assertSame(arcGrid, sc.getResourceByName("nurc:arcgrid", CoverageInfo.class));
assertEquals(toppWs, sc.getWorkspaceByName("topp"));
assertSame(statesStore, sc.getDataStoreByName("states"));
assertSame(roadsStore, sc.getDataStoreByName("roads"));
assertSame(arcGridStore, sc.getCoverageStoreByName("arcGrid"));
assertThatBoth(
sc.getFeatureTypes(),
sc.list(FeatureTypeInfo.class, Predicates.acceptAll()),
equalTo(featureTypes));
assertThatBoth(
sc.getCoverages(),
sc.list(CoverageInfo.class, Predicates.acceptAll()),
equalTo(coverages));
assertThatBoth(
sc.getWorkspaces(),
sc.list(WorkspaceInfo.class, Predicates.acceptAll()),
equalTo(workspaces));
}