}
@Test
public void testPublicRead() throws Exception {
SecureCatalogImpl sc = buildTestObject("publicRead.properties", catalog);
// try with read only user
SecurityContextHolder.getContext().setAuthentication(roUser);
assertSame(arcGrid, sc.getCoverageByName("nurc:arcgrid"));
assertSame(arcGrid, sc.getResourceByName("nurc:arcgrid", CoverageInfo.class));
assertEquals(toppWs, sc.getWorkspaceByName("topp"));
assertSame(arcGridStore, sc.getCoverageStoreByName("arcGrid"));
// .. the following should have been wrapped
assertNotNull(sc.getFeatureTypeByName("topp:states"));
assertTrue(sc.getFeatureTypeByName("topp:states") instanceof SecuredFeatureTypeInfo);
assertTrue(sc.getResourceByName("topp:states", FeatureTypeInfo.class) instanceof SecuredFeatureTypeInfo);
assertThatBoth(sc.getFeatureTypes(),
sc.list(FeatureTypeInfo.class, Predicates.acceptAll()),
allOf((Matcher)hasSize(featureTypes.size()),
(Matcher)everyItem(Matchers.<FeatureTypeInfo>instanceOf(SecuredFeatureTypeInfo.class))));
assertThatBoth(sc.getCoverages(),
sc.list(CoverageInfo.class, Predicates.acceptAll()),
equalTo(coverages));
assertThatBoth(sc.getWorkspaces(),
sc.list(WorkspaceInfo.class, Predicates.acceptAll()),
equalTo(workspaces));
assertNotNull(sc.getLayerByName("topp:states"));
assertTrue(sc.getLayerByName("topp:states") instanceof SecuredLayerInfo);
assertTrue(sc.getDataStoreByName("states") instanceof SecuredDataStoreInfo);
assertTrue(sc.getDataStoreByName("roads") instanceof SecuredDataStoreInfo);
// try with write enabled user (nothing has been wrapped)
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(featureTypes, sc.getFeatureTypes());
assertEquals(coverages, sc.getCoverages());
assertEquals(workspaces, sc.getWorkspaces());
assertEquals(toppWs, sc.getWorkspaceByName("topp"));
assertSame(statesStore, sc.getDataStoreByName("states"));
assertSame(roadsStore, sc.getDataStoreByName("roads"));
assertSame(arcGridStore, sc.getCoverageStoreByName("arcGrid"));
}