use of org.xwiki.vfs.VfsException in project xwiki-platform by xwiki.
the class CascadingVfsPermissionCheckerTest method checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed.
@Test
public void checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("customscheme:whatever"), "whatever");
AuthorizationManager authorizationManager = this.mocker.registerMockComponent(AuthorizationManager.class);
when(authorizationManager.hasAccess(Right.PROGRAM, this.contextUser, null)).thenReturn(false);
try {
this.mocker.getComponentUnderTest().checkPermission(reference);
fail("Should have raised exception");
} catch (VfsException expected) {
assertEquals("Current logged-in user ([" + this.contextUser + "]) needs to have Programming Rights to use the [customscheme] VFS", expected.getMessage());
}
}
use of org.xwiki.vfs.VfsException in project xwiki-platform by xwiki.
the class DefaultVfsManagerTest method getURLerror.
@Test
public void getURLerror() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, ExtendedURL.class));
when(serializer.serialize(reference)).thenThrow(new SerializeResourceReferenceException("error"));
try {
this.mocker.getComponentUnderTest().getURL(reference);
fail("Should have thrown an exception");
} catch (VfsException expected) {
assertEquals("Failed to compute URL for [uri = [attach:xwiki:space.page@attachment], " + "path = [path1/path2/test.txt], parameters = []]", expected.getMessage());
}
}
use of org.xwiki.vfs.VfsException 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