Skip to content

Commit

Permalink
handle virtual directories with ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 4, 2023
1 parent 9ee1da6 commit f8ddc98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Wed Oct 04 10:51:11 CEST 2023
build.number=17
#Wed Oct 04 17:36:33 CEST 2023
build.number=18
44 changes: 21 additions & 23 deletions source/java/src/org/lucee/extension/resource/s3/S3.java
Original file line number Diff line number Diff line change
Expand Up @@ -2073,46 +2073,39 @@ public void setAccessControlList(String bucketName, String objectName, Object ob
}

public Array getAccessControlList(String bucketName, String objectName) throws S3Exception {
AccessControlList acl = getACL(bucketName, objectName);
AccessControlList acl = getACL(null, bucketName, objectName);
return AccessControlListUtil.toArray(acl.getGrantsAsList());
}

private AccessControlList getACL(String bucketName, String objectName) throws S3Exception {
private AccessControlList getACL(AmazonS3Client client, String bucketName, String objectName) throws S3Exception {
bucketName = improveBucketName(bucketName);
objectName = improveObjectName(objectName);

String key = toKey(bucketName, objectName);

ValidUntilElement<AccessControlList> vuacl = accessControlLists.get(key);
if (vuacl != null && vuacl.validUntil > System.currentTimeMillis()) return vuacl.element;
boolean externalClient = true;
if (client == null) {
client = getAmazonS3(bucketName, null);
externalClient = false;
}

AmazonS3Client client = getAmazonS3(bucketName, null);
try {
if (Util.isEmpty(objectName)) return client.getBucketAcl(bucketName);
return client.getObjectAcl(bucketName, objectName);
}
catch (AmazonServiceException se) {
if (se.getErrorCode().equals("NoSuchKey")) { // we know at this point objectname is not empty, so we do not have to check that
try {
return client.getObjectAcl(bucketName, oppositeObjectName(objectName));
}
catch (AmazonServiceException ise) {
throw toS3Exception(ise);
}
}
throw toS3Exception(se);
}
finally {
client.release();
}
}

private AccessControlList getACL(AmazonS3 s, String bucketName, String objectName) throws S3Exception {
bucketName = improveBucketName(bucketName);
objectName = improveObjectName(objectName);

String key = toKey(bucketName, objectName);
ValidUntilElement<AccessControlList> vuacl = accessControlLists.get(key);
if (vuacl != null && vuacl.validUntil > System.currentTimeMillis()) return vuacl.element;

try {
if (Util.isEmpty(objectName)) return s.getBucketAcl(bucketName);
return s.getObjectAcl(bucketName, objectName);
}
catch (AmazonServiceException se) {
throw toS3Exception(se);
if (!externalClient) client.release();
}
}

Expand Down Expand Up @@ -2417,6 +2410,11 @@ public static String improveObjectName(String objectName, boolean directory) {
return objectName;
}

private static String oppositeObjectName(String objectName) {
if (objectName.endsWith("/")) return improveObjectName(objectName, false);
return improveObjectName(objectName, true);
}

public static String improveLocation(String location) {
if (location == null) return location;
location = location.toLowerCase().trim();
Expand Down

0 comments on commit f8ddc98

Please sign in to comment.