use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class VfsScriptServiceTest method urlError.
@Test
public void urlError() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
VfsManager manager = this.mocker.getInstance(VfsManager.class);
when(manager.getURL(reference)).thenThrow(new VfsException("error"));
assertNull(this.mocker.getComponentUnderTest().url(new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt")));
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class DefaultVfsPathFactory method create.
@Override
public Path create(URI uri) throws VfsException {
try {
VfsResourceReference reference = this.vfsResourceReferenceConverter.convert(VfsResourceReference.class, uri.toString());
this.permissionChecker.checkPermission(reference);
URI trueVFSURI = this.trueVfsResourceReferenceSerializer.serialize(reference);
return new TPath(trueVFSURI);
} catch (Exception e) {
throw new VfsException(String.format("Failed to create Path instance for [%s]", uri.toString()), e);
}
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class URIVfsResourceReferenceSerializer method serialize.
@Override
public URI serialize(VfsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
URI resultURI;
try {
ResourceReferenceSerializer<VfsResourceReference, URI> serializer = this.componentManagerProvider.get().getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), String.format("truevfs/%s", reference.getURI().getScheme()));
resultURI = serializer.serialize(reference);
} catch (ComponentLookupException e) {
// No serializer exist, we just don't perform any conversion!
resultURI = reference.toURI();
}
return resultURI;
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class PathConverter method convertToType.
@Override
protected Path convertToType(Type targetType, Object value) {
if (value == null) {
return null;
}
Path path;
try {
VfsResourceReference reference = new VfsResourceReference(new URI(value.toString()));
// Verify that the user has the permission for the specified VFS scheme. We need to do this at this level
// since it's possible to do the check in the driver itself since TrueVFS controls whether the driver is
// called or not and does caching,
// see https://java.net/projects/truezip/lists/users/archive/2015-12/message/8
// Since this convert has to be called to use the VFS API from Velocity, we're safe that this will prevent
// any Velocity script to execute a VFS call if the user is not allowed.
//
// Note: Even though the user needs View access to the attachment, we cannot check this right now because
// of the caching issue. However we consider that if the user has Programming Rights, he can do anything he
// wants and thus it's safe that he can access the attachment.
this.permissionChecker.checkPermission(reference);
URI trueVfsURI = this.trueVfsResourceReferenceSerializer.serialize(reference);
path = new TPath(trueVfsURI);
} catch (Exception e) {
throw new ConversionException(String.format("Failed to convert [%s] to a Path object", value), e);
}
return path;
}
use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.
the class CascadingVfsPermissionCheckerTest method checkPermissionWhenReservedScheme.
@Test
public void checkPermissionWhenReservedScheme() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("cascading:whatever"), "whatever");
try {
this.mocker.getComponentUnderTest().checkPermission(reference);
fail("Should have raised exception");
} catch (VfsException expected) {
assertEquals("[cascading] is a reserved VFS URI scheme and cannot be used.", expected.getMessage());
}
}
Aggregations