use of org.xwiki.vfs.VfsPermissionChecker in project xwiki-platform by xwiki.
the class PathConverterTest method convertWhenNoPermission.
@Test
public void convertWhenNoPermission() throws Exception {
ResourceReferenceSerializer<VfsResourceReference, URI> serializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), "truevfs");
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:Sandbox.WebHome@my.zip"), "a/b/c");
when(serializer.serialize(reference)).thenReturn(URI.create("attach://xwiki:Sandbox.WebHome/my.zip/a/b/c"));
VfsPermissionChecker permissionChecker = this.mocker.getInstance(VfsPermissionChecker.class, "cascading");
doThrow(new VfsException("unauthorized")).when(permissionChecker).checkPermission(reference);
try {
this.mocker.getComponentUnderTest().convert(new DefaultParameterizedType(null, Path.class), "attach:Sandbox.WebHome@my.zip/a/b/c");
fail("Should have thrown an exception here");
} catch (ConversionException expected) {
assertEquals("Failed to convert [attach:Sandbox.WebHome@my.zip/a/b/c] to a Path object", expected.getMessage());
assertEquals("VfsException: unauthorized", ExceptionUtils.getRootCauseMessage(expected));
}
}
use of org.xwiki.vfs.VfsPermissionChecker in project xwiki-platform by xwiki.
the class VfsResourceReferenceHandlerTest method handleWhenNoGenericPermissionForScheme.
@Test
public void handleWhenNoGenericPermissionForScheme() throws Exception {
setUp("customscheme", "wiki3", "space3", "page3", "test.zip", Arrays.asList("test.txt"));
// Don't allow permission for "customscheme"
VfsPermissionChecker checker = this.mocker.getInstance(VfsPermissionChecker.class, "cascading");
doThrow(new VfsException("no permission")).when(checker).checkPermission(this.reference);
try {
this.mocker.getComponentUnderTest().handle(this.reference, mock(ResourceReferenceHandlerChain.class));
fail("Should have thrown exception here");
} catch (ResourceReferenceHandlerException expected) {
assertEquals("VfsException: no permission", ExceptionUtils.getRootCauseMessage(expected));
}
}
use of org.xwiki.vfs.VfsPermissionChecker in project xwiki-platform by xwiki.
the class CascadingVfsPermissionChecker method checkPermission.
@Override
public void checkPermission(VfsResourceReference resourceReference) throws VfsException {
// Prevent using a VFS scheme that correspond to the hint of this component
String scheme = resourceReference.getURI().getScheme();
if (HINT.equals(scheme)) {
throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT));
}
// Look for a scheme-specific permission checker
VfsPermissionChecker resolvedChecker;
ComponentManager componentManager = this.componentManagerProvider.get();
try {
resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme);
} catch (ComponentLookupException e) {
// Use the Generic permission checker
try {
resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class);
} catch (ComponentLookupException ee) {
throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee);
}
}
resolvedChecker.checkPermission(resourceReference);
}
Aggregations