Search in sources :

Example 6 with Grant

use of software.amazon.awssdk.services.s3.model.Grant in project alluxio by Alluxio.

the class S3AUtils method translateBucketAcl.

/**
 * Translates S3 bucket ACL to Alluxio owner mode.
 *
 * @param acl the acl of S3 bucket
 * @param userId the S3 user id of the Alluxio owner
 * @return the translated posix mode in short format
 */
public static short translateBucketAcl(AccessControlList acl, String userId) {
    short mode = (short) 0;
    for (Grant grant : acl.getGrantsAsList()) {
        Permission perm = grant.getPermission();
        Grantee grantee = grant.getGrantee();
        if (perm.equals(Permission.Read)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the bucket is readable by the user, add r and x to the owner mode.
                mode |= (short) 0500;
            }
        } else if (perm.equals(Permission.Write)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the bucket is writable by the user, +w to the owner mode.
                mode |= (short) 0200;
            }
        } else if (perm.equals(Permission.FullControl)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the user has full control to the bucket, +rwx to the owner mode.
                mode |= (short) 0700;
            }
        }
    }
    return mode;
}
Also used : Grant(com.amazonaws.services.s3.model.Grant) GroupGrantee(com.amazonaws.services.s3.model.GroupGrantee) Grantee(com.amazonaws.services.s3.model.Grantee) Permission(com.amazonaws.services.s3.model.Permission)

Example 7 with Grant

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

the class GetAcl method getBucketAcl.

public static void getBucketAcl(String bucket_name) {
    System.out.println("Retrieving ACL for bucket: " + bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    try {
        AccessControlList acl = s3.getBucketAcl(bucket_name);
        List<Grant> grants = acl.getGrantsAsList();
        for (Grant grant : grants) {
            System.out.format("  %s: %s\n", grant.getGrantee().getIdentifier(), grant.getPermission().toString());
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) AmazonS3(com.amazonaws.services.s3.AmazonS3) Grant(com.amazonaws.services.s3.model.Grant) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 8 with Grant

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

the class GetAcl method getObjectAcl.

public static void getObjectAcl(String bucket_name, String object_key) {
    System.out.println("Retrieving ACL for object: " + object_key);
    System.out.println("                in bucket: " + bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    try {
        AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
        List<Grant> grants = acl.getGrantsAsList();
        for (Grant grant : grants) {
            System.out.format("  %s: %s\n", grant.getGrantee().getIdentifier(), grant.getPermission().toString());
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) AmazonS3(com.amazonaws.services.s3.AmazonS3) Grant(com.amazonaws.services.s3.model.Grant) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 9 with Grant

use of software.amazon.awssdk.services.s3.model.Grant in project druid by druid-io.

the class S3TaskLogsTest method testTaskLogsPushWithAclEnabled.

@Test
public void testTaskLogsPushWithAclEnabled() throws Exception {
    String ownerId = "test_owner";
    String ownerDisplayName = "test_owner";
    List<Grant> grantList = testPushInternal(false, ownerId, ownerDisplayName);
    Assert.assertNotNull("Grant list should not be null", grantList);
    Assert.assertEquals("Grant list size should be equal to 1", 1, grantList.size());
    Grant grant = grantList.get(0);
    Assert.assertEquals("The Grantee identifier should be test_owner", "test_owner", grant.getGrantee().getIdentifier());
    Assert.assertEquals("The Grant should have full control permission", Permission.FullControl, grant.getPermission());
}
Also used : Grant(com.amazonaws.services.s3.model.Grant) Test(org.junit.Test)

Example 10 with Grant

use of software.amazon.awssdk.services.s3.model.Grant in project druid by druid-io.

the class S3Utils method grantFullControlToBucketOwner.

static AccessControlList grantFullControlToBucketOwner(ServerSideEncryptingAmazonS3 s3Client, String bucket) {
    final AccessControlList acl = s3Client.getBucketAcl(bucket);
    acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl));
    return acl;
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) Grant(com.amazonaws.services.s3.model.Grant) CanonicalGrantee(com.amazonaws.services.s3.model.CanonicalGrantee)

Aggregations

Grant (com.amazonaws.services.s3.model.Grant)6 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)4 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 CanonicalGrantee (com.amazonaws.services.s3.model.CanonicalGrantee)2 S3Client (software.amazon.awssdk.services.s3.S3Client)2 Grant (software.amazon.awssdk.services.s3.model.Grant)2 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)2 DatasetProvider (com.amazonaws.personalize.client.datasets.DatasetProvider)1 MovieLensDatasetProvider (com.amazonaws.personalize.client.datasets.MovieLensDatasetProvider)1 CampaignManager (com.amazonaws.personalize.client.resource.CampaignManager)1 EventTrackerManager (com.amazonaws.personalize.client.resource.EventTrackerManager)1 Grantee (com.amazonaws.services.s3.model.Grantee)1 GroupGrantee (com.amazonaws.services.s3.model.GroupGrantee)1 Owner (com.amazonaws.services.s3.model.Owner)1 Permission (com.amazonaws.services.s3.model.Permission)1 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 DataSegment (org.apache.druid.timeline.DataSegment)1