Search in sources :

Example 1 with AccessControlPolicy

use of software.amazon.awssdk.services.s3.model.AccessControlPolicy in project aws-doc-sdk-examples by awsdocs.

the class SetAcl method setBucketAcl.

// snippet-start:[s3.java2.set_acl.main]
public static void setBucketAcl(S3Client s3, String bucketName, String id) {
    try {
        Grant ownerGrant = Grant.builder().grantee(builder -> {
            builder.id(id).type(Type.CANONICAL_USER);
        }).permission(Permission.FULL_CONTROL).build();
        List<Grant> grantList2 = new ArrayList<>();
        grantList2.add(ownerGrant);
        AccessControlPolicy acl = AccessControlPolicy.builder().owner(builder -> builder.id(id)).grants(grantList2).build();
        PutBucketAclRequest putAclReq = PutBucketAclRequest.builder().bucket(bucketName).accessControlPolicy(acl).build();
        s3.putBucketAcl(putAclReq);
    } catch (S3Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : Grant(software.amazon.awssdk.services.s3.model.Grant) AccessControlPolicy(software.amazon.awssdk.services.s3.model.AccessControlPolicy) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) PutBucketAclRequest(software.amazon.awssdk.services.s3.model.PutBucketAclRequest) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 AccessControlPolicy (software.amazon.awssdk.services.s3.model.AccessControlPolicy)1 Grant (software.amazon.awssdk.services.s3.model.Grant)1 PutBucketAclRequest (software.amazon.awssdk.services.s3.model.PutBucketAclRequest)1 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)1