fix: implement s3 bucket ownership controls (#456)

This commit is contained in:
TiM authored and GitHub committed 2026-04-15 01:08:57 -05:00
1 parent c030af9a0d
commit ca0395a9e0
4 files changed
+130

No files matched your search

@@ -167,6 +167,10 @@ public class S3Controller {
s3Service.putPublicAccessBlock(bucket, new String(body, StandardCharsets.UTF_8));
return Response.ok().build();
}
if (hasQueryParam(uriInfo, "ownershipControls")) {
s3Service.putBucketOwnershipControls(bucket, new String(body, StandardCharsets.UTF_8));
return Response.ok().build();
}
String locationConstraint = null;
if (body != null && body.length > 0) {
@@ -226,6 +230,10 @@ public class S3Controller {
s3Service.deletePublicAccessBlock(bucket);
return Response.noContent().build();
}
if (hasQueryParam(uriInfo, "ownershipControls")) {
s3Service.deleteBucketOwnershipControls(bucket);
return Response.noContent().build();
}
s3Service.deleteBucket(bucket);
return Response.noContent().build();
} catch (AwsException e) {
@@ -286,6 +294,9 @@ public class S3Controller {
if (hasQueryParam(uriInfo, "publicAccessBlock")) {
return Response.ok(s3Service.getPublicAccessBlock(bucket)).build();
}
if (hasQueryParam(uriInfo, "ownershipControls")) {
return Response.ok(s3Service.getBucketOwnershipControls(bucket)).build();
}
int max = (maxKeys != null && maxKeys > 0) ? maxKeys : 1000;
S3Service.ListObjectsResult result = s3Service.listObjectsWithPrefixes(
@@ -1343,6 +1343,30 @@ public class S3Service {
bucketStore.put(bucketName, bucket);
}
public String getBucketOwnershipControls(String bucketName) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
if (bucket.getOwnershipControlsConfiguration() == null) {
throw new AwsException("OwnershipControlsNotFoundError",
"The bucket ownership controls were not found.", 404);
}
return bucket.getOwnershipControlsConfiguration();
}
public void putBucketOwnershipControls(String bucketName, String ownershipControlsXml) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
bucket.setOwnershipControlsConfiguration(ownershipControlsXml);
bucketStore.put(bucketName, bucket);
}
public void deleteBucketOwnershipControls(String bucketName) {
Bucket bucket = bucketStore.get(bucketName)
.orElseThrow(() -> new AwsException("NoSuchBucket", "The specified bucket does not exist.", 404));
bucket.setOwnershipControlsConfiguration(null);
bucketStore.put(bucketName, bucket);
}
public void restoreObject(String bucketName, String key, String versionId, String restoreXml) {
// Validation only - stub implementation
getObject(bucketName, key, versionId);
@@ -24,6 +24,7 @@ public class Bucket {
private String acl; // XML representation or JSON stub
private String encryptionConfiguration; // XML string
private String publicAccessBlockConfiguration; // XML string
private String ownershipControlsConfiguration; // XML string
private String region;
public Bucket() {
@@ -82,6 +83,11 @@ public class Bucket {
this.publicAccessBlockConfiguration = publicAccessBlockConfiguration;
}
public String getOwnershipControlsConfiguration() { return ownershipControlsConfiguration; }
public void setOwnershipControlsConfiguration(String ownershipControlsConfiguration) {
this.ownershipControlsConfiguration = ownershipControlsConfiguration;
}
public String getRegion() { return region; }
public void setRegion(String region) { this.region = region; }
}