-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Maksim_Hadalau <[email protected]>
- Loading branch information
1 parent
b061ecb
commit 11f209a
Showing
27 changed files
with
948 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.epam.aidial.core.config; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class Encryption { | ||
String password; | ||
String salt; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/epam/aidial/core/controller/AccessControlBaseController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.epam.aidial.core.controller; | ||
|
||
import com.epam.aidial.core.Proxy; | ||
import com.epam.aidial.core.ProxyContext; | ||
import com.epam.aidial.core.storage.BlobStorageUtil; | ||
import com.epam.aidial.core.storage.ResourceDescription; | ||
import com.epam.aidial.core.storage.ResourceType; | ||
import com.epam.aidial.core.util.HttpStatus; | ||
import io.vertx.core.Future; | ||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public abstract class AccessControlBaseController { | ||
|
||
final Proxy proxy; | ||
final ProxyContext context; | ||
|
||
|
||
public Future<?> handle(String bucket, String filePath) { | ||
String expectedUserBucket = BlobStorageUtil.buildUserBucket(context); | ||
String decryptedBucket = proxy.getEncryptionService().decrypt(bucket); | ||
|
||
if (!expectedUserBucket.equals(decryptedBucket)) { | ||
return context.respond(HttpStatus.FORBIDDEN, "You don't have an access to the bucket " + bucket); | ||
} | ||
|
||
ResourceDescription resource; | ||
try { | ||
resource = ResourceDescription.from(ResourceType.FILE, bucket, decryptedBucket, filePath); | ||
} catch (Exception ex) { | ||
return context.respond(HttpStatus.BAD_REQUEST, "Invalid file url provided"); | ||
} | ||
|
||
return handle(resource); | ||
} | ||
|
||
protected abstract Future<?> handle(ResourceDescription resource); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/epam/aidial/core/controller/BucketController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.epam.aidial.core.controller; | ||
|
||
import com.epam.aidial.core.Proxy; | ||
import com.epam.aidial.core.ProxyContext; | ||
import com.epam.aidial.core.data.Bucket; | ||
import com.epam.aidial.core.security.EncryptionService; | ||
import com.epam.aidial.core.storage.BlobStorageUtil; | ||
import com.epam.aidial.core.util.HttpStatus; | ||
import io.vertx.core.Future; | ||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class BucketController { | ||
|
||
private final Proxy proxy; | ||
private final ProxyContext context; | ||
|
||
public Future<?> getBucket() { | ||
EncryptionService encryptionService = proxy.getEncryptionService(); | ||
String bucketLocation = BlobStorageUtil.buildUserBucket(context); | ||
String encryptedBucket = encryptionService.encrypt(bucketLocation); | ||
|
||
return context.respond(HttpStatus.OK, new Bucket(encryptedBucket)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.