Search in sources :

Example 1 with GetObjectAclResponse

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

the class GetAcl method getBucketACL.

// snippet-start:[s3.java2.get_acl.main]
public static String getBucketACL(S3Client s3, String objectKey, String bucketName) {
    try {
        GetObjectAclRequest aclReq = GetObjectAclRequest.builder().bucket(bucketName).key(objectKey).build();
        GetObjectAclResponse aclRes = s3.getObjectAcl(aclReq);
        List<Grant> grants = aclRes.grants();
        String grantee = "";
        for (Grant grant : grants) {
            System.out.format("  %s: %s\n", grant.grantee().id(), grant.permission());
            grantee = grant.grantee().id();
        }
        return grantee;
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : Grant(software.amazon.awssdk.services.s3.model.Grant) GetObjectAclRequest(software.amazon.awssdk.services.s3.model.GetObjectAclRequest) GetObjectAclResponse(software.amazon.awssdk.services.s3.model.GetObjectAclResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception)

Aggregations

GetObjectAclRequest (software.amazon.awssdk.services.s3.model.GetObjectAclRequest)1 GetObjectAclResponse (software.amazon.awssdk.services.s3.model.GetObjectAclResponse)1 Grant (software.amazon.awssdk.services.s3.model.Grant)1 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)1