use of net.java.truevfs.access.TPath 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 net.java.truevfs.access.TPath 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 net.java.truevfs.access.TPath in project xwiki-platform by xwiki.
the class VfsResourceReferenceHandler method handle.
@Override
public void handle(ResourceReference resourceReference, ResourceReferenceHandlerChain chain) throws ResourceReferenceHandlerException {
// This code only handles VFS Resource References.
VfsResourceReference vfsResourceReference = (VfsResourceReference) resourceReference;
try {
// Verify that the user has the permission for the specified VFS scheme and for the VFS URI
this.permissionChecker.checkPermission(vfsResourceReference);
// Extract the asked resource from inside the zip and return its content for display.
// We need to convert the VFS Resource Reference into a hierarchical URI supported by TrueVFS
URI trueVFSURI = convertResourceReference(vfsResourceReference);
// We use TrueVFS. This line will automatically use the VFS Driver that matches the scheme passed in the URI
Path path = new TPath(trueVFSURI);
try (InputStream in = Files.newInputStream(path)) {
List<String> pathSegments = vfsResourceReference.getPathSegments();
serveResource(pathSegments.get(pathSegments.size() - 1), in);
}
} catch (Exception e) {
throw new ResourceReferenceHandlerException(String.format("Failed to extract resource [%s]", vfsResourceReference), e);
}
// Be a good citizen, continue the chain, in case some lower-priority Handler has something to do for this
// Resource Reference.
chain.handleNext(vfsResourceReference);
}
Aggregations