Skip to content

Commit

Permalink
fix: shared file access (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Gadalov authored Jan 18, 2024
1 parent e18f27e commit 825aa61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public abstract class AccessControlBaseController {
* @param filePath url encoded file path
*/
public Future<?> handle(String bucket, String filePath) {
ResourceType type = ResourceType.FILE;
String urlDecodedBucket = UrlUtil.decodePath(bucket);
String decryptedBucket = proxy.getEncryptionService().decrypt(urlDecodedBucket);
boolean hasReadAccess = isSharedWithMe(bucket, filePath);
boolean hasReadAccess = isSharedWithMe(type, bucket, filePath);
boolean hasWriteAccess = hasWriteAccess(filePath, decryptedBucket);
boolean hasAccess = checkFullAccess ? hasWriteAccess : hasReadAccess || hasWriteAccess;

Expand All @@ -37,7 +38,7 @@ public Future<?> handle(String bucket, String filePath) {

ResourceDescription resource;
try {
resource = ResourceDescription.fromEncoded(ResourceType.FILE, urlDecodedBucket, decryptedBucket, filePath);
resource = ResourceDescription.fromEncoded(type, urlDecodedBucket, decryptedBucket, filePath);
} catch (Exception ex) {
String errorMessage = ex.getMessage() != null ? ex.getMessage() : DEFAULT_RESOURCE_ERROR_MESSAGE.formatted(filePath);
return context.respond(HttpStatus.BAD_REQUEST, errorMessage);
Expand All @@ -48,8 +49,8 @@ public Future<?> handle(String bucket, String filePath) {

protected abstract Future<?> handle(ResourceDescription resource);

protected boolean isSharedWithMe(String bucket, String filePath) {
String url = bucket + BlobStorageUtil.PATH_SEPARATOR + filePath;
protected boolean isSharedWithMe(ResourceType type, String bucket, String filePath) {
String url = type.getGroup() + BlobStorageUtil.PATH_SEPARATOR + bucket + BlobStorageUtil.PATH_SEPARATOR + filePath;
return context.getApiKeyData().getAttachedFiles().contains(url);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/epam/aidial/core/FileApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public void testDownloadSharedFile(Vertx vertx, VertxTestContext context) {
apiKeyData1.setOriginalKey(projectApiKeyData.getOriginalKey());
// set deployment ID for proxyKey1
apiKeyData1.setSourceDeployment("EPM-RTC-GPT");
apiKeyData1.setAttachedFiles(Set.of("7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/folder1/file.txt"));
apiKeyData1.setAttachedFiles(Set.of("files/7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/folder1/file.txt"));
apiKeyStore.assignApiKey(apiKeyData1);

String apiKey1 = apiKeyData1.getPerRequestKey();
Expand Down

0 comments on commit 825aa61

Please sign in to comment.