DataAccessManager manager = buildManager("lockedDownMixed.properties");
SecureCatalogImpl sc = new SecureCatalogImpl(catalog, manager);
// 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(AcegiSecurityException e) {
//
}
try {
sc.getCoverageByName("nurc:arcgrid");
fail("Should have failed with a security exception");
} catch(AcegiSecurityException e) {
//
}
try {
sc.getResourceByName("topp:states", FeatureTypeInfo.class);
fail("Should have failed with a security exception");
} catch(AcegiSecurityException e) {
//
}
try {
sc.getResourceByName("nurc:arcgrid", CoverageInfo.class);
fail("Should have failed with a security exception");
} catch(AcegiSecurityException e) {
//
}
try {
sc.getWorkspaceByName("topp");
fail("Should have failed with a security exception");
} catch(AcegiSecurityException e) {
//
}
try {
sc.getDataStoreByName("states");
fail("Should have failed with a security exception");
} catch(AcegiSecurityException e) {
//
}
try {
sc.getDataStoreByName("roads");
fail("Should have failed with a security exception");
} catch(AcegiSecurityException e) {
//
}
try {
sc.getCoverageStoreByName("arcGrid");
fail("Should have failed with a security exception");
} catch(AcegiSecurityException e) {
//
}
// 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
assertEquals(0, sc.getFeatureTypes().size());