mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 12:45:35 +00:00
Bug 4894: secured getFile method with in FileStorageResource for
AmazonS3FileStorageServiceImpl and LocalFileStorageServiceImpl.
This commit is contained in:
+7
-1
@@ -43,6 +43,10 @@ public class FileStorageResource extends AbstractSailingServerResource {
|
||||
public Response getFile(@QueryParam("uri") String uri) {
|
||||
Response response;
|
||||
try {
|
||||
|
||||
getService().getFileStorageManagementService().getActiveFileStorageService()
|
||||
.doPermissionCheckForGetFile(new URI(uri));
|
||||
|
||||
InputStream inputStream = new URL(uri).openStream();
|
||||
ResponseBuilder responseBuilder = Response.ok().entity(inputStream);
|
||||
if (uri.toLowerCase().endsWith(".jpg")) {
|
||||
@@ -51,8 +55,10 @@ public class FileStorageResource extends AbstractSailingServerResource {
|
||||
responseBuilder.header("Content-Type", "image/png");
|
||||
}
|
||||
response = responseBuilder.build();
|
||||
} catch (IOException ioe) {
|
||||
} catch (IOException | URISyntaxException ioe) {
|
||||
response = Response.status(Status.BAD_REQUEST).entity(ioe.getMessage()).build();
|
||||
} catch (UnauthorizedException e) {
|
||||
response = Response.status(Status.UNAUTHORIZED).entity(e.getMessage()).build();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -55,4 +55,7 @@ public interface FileStorageService extends IsManagedByCache<FileStorageServiceR
|
||||
* Test whether properties are valid, e.g. by trying to log in using access credentials provided as properties.
|
||||
*/
|
||||
void testProperties() throws InvalidPropertiesException, IOException;
|
||||
|
||||
/** Check required permissions for getfile. */
|
||||
void doPermissionCheckForGetFile(URI uri) throws UnauthorizedException;
|
||||
}
|
||||
|
||||
+11
-1
@@ -120,12 +120,13 @@ public class AmazonS3FileStorageServiceImpl extends BaseFileStorageServiceImpl i
|
||||
@Override
|
||||
public void removeFile(URI uri) throws InvalidPropertiesException, OperationFailedException, UnauthorizedException {
|
||||
String key = uri.getPath().substring(uri.getPath().lastIndexOf("/")+1);
|
||||
AmazonS3Client s3Client = createS3Client();
|
||||
|
||||
SecurityUtils.getSubject().checkPermission(
|
||||
SecuredDomainType.FILE_STORAGE.getStringPermissionForTypeRelativeIdentifier(DefaultActions.DELETE,
|
||||
new TypeRelativeObjectIdentifier(key)));
|
||||
|
||||
AmazonS3Client s3Client = createS3Client();
|
||||
|
||||
try {
|
||||
s3Client.deleteObject(new DeleteObjectRequest(bucketName.getValue(), key));
|
||||
} catch (AmazonClientException e) {
|
||||
@@ -158,4 +159,13 @@ public class AmazonS3FileStorageServiceImpl extends BaseFileStorageServiceImpl i
|
||||
bucketName, "bucket does not exist"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doPermissionCheckForGetFile(URI uri) throws UnauthorizedException {
|
||||
String key = uri.getPath().substring(uri.getPath().lastIndexOf("/") + 1);
|
||||
|
||||
SecurityUtils.getSubject().checkPermission(
|
||||
SecuredDomainType.FILE_STORAGE.getStringPermissionForTypeRelativeIdentifier(DefaultActions.DELETE,
|
||||
new TypeRelativeObjectIdentifier(key)));
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -183,4 +183,14 @@ public class LocalFileStorageServiceImpl extends BaseFileStorageServiceImpl impl
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doPermissionCheckForGetFile(URI uri) throws UnauthorizedException {
|
||||
String filePath = uri.getPath();
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
|
||||
final String pathToFile = localPath.getValue() + "/" + fileName;
|
||||
SecurityUtils.getSubject().checkPermission(
|
||||
SecuredDomainType.FILE_STORAGE.getStringPermissionForTypeRelativeIdentifier(DefaultActions.READ,
|
||||
new TypeRelativeObjectIdentifier(pathToFile)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user