Search in sources :

Example 16 with AccessControlList

use of com.amazonaws.services.s3.model.AccessControlList 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 17 with AccessControlList

use of com.amazonaws.services.s3.model.AccessControlList in project aws-doc-sdk-examples by awsdocs.

the class SetAcl method setBucketAcl.

public static void setBucketAcl(String bucket_name, String email, String access) {
    System.out.format("Setting %s access for %s\n", access, email);
    System.out.println("on bucket: " + bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    try {
        // get the current ACL
        AccessControlList acl = s3.getBucketAcl(bucket_name);
        // set access for the grantee
        EmailAddressGrantee grantee = new EmailAddressGrantee(email);
        Permission permission = Permission.valueOf(access);
        acl.grantPermission(grantee, permission);
        s3.setBucketAcl(bucket_name, acl);
    } 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) EmailAddressGrantee(com.amazonaws.services.s3.model.EmailAddressGrantee) Permission(com.amazonaws.services.s3.model.Permission) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 18 with AccessControlList

use of com.amazonaws.services.s3.model.AccessControlList in project aws-doc-sdk-examples by awsdocs.

the class SetAcl method setObjectAcl.

public static void setObjectAcl(String bucket_name, String object_key, String email, String access) {
    System.out.format("Setting %s access for %s\n", access, email);
    System.out.println("for object: " + object_key);
    System.out.println(" in bucket: " + bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    try {
        // get the current ACL
        AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
        // set access for the grantee
        EmailAddressGrantee grantee = new EmailAddressGrantee(email);
        Permission permission = Permission.valueOf(access);
        acl.grantPermission(grantee, permission);
        s3.setObjectAcl(bucket_name, object_key, acl);
    } 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) EmailAddressGrantee(com.amazonaws.services.s3.model.EmailAddressGrantee) Permission(com.amazonaws.services.s3.model.Permission) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 19 with AccessControlList

use of com.amazonaws.services.s3.model.AccessControlList in project hippo by NHS-digital-website.

the class S3SdkConnector method unpublishResource.

@Override
public void unpublishResource(String objectPath) {
    reportAction("Making S3 resource not-public: {}", objectPath);
    AccessControlList acl = s3.getObjectAcl(bucketName, objectPath);
    acl.revokeAllPermissions(GroupGrantee.AllUsers);
    s3.setObjectAcl(bucketName, objectPath, acl);
    reportAction("S3 Resource is no longer public: {}", objectPath);
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList)

Example 20 with AccessControlList

use of com.amazonaws.services.s3.model.AccessControlList in project hippo by NHS-digital-website.

the class S3SdkConnector method publishResource.

@Override
public void publishResource(String objectPath) {
    reportAction("Making S3 resource public: {}", objectPath);
    AccessControlList acl = s3.getObjectAcl(bucketName, objectPath);
    acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
    s3.setObjectAcl(bucketName, objectPath, acl);
    reportAction("S3 resource is now public: {}", objectPath);
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList)

Aggregations

AccessControlList (com.amazonaws.services.s3.model.AccessControlList)25 Owner (com.amazonaws.services.s3.model.Owner)8 AmazonServiceException (com.amazonaws.AmazonServiceException)6 AmazonS3 (com.amazonaws.services.s3.AmazonS3)6 CannedAccessControlList (com.amazonaws.services.s3.model.CannedAccessControlList)5 CanonicalGrantee (com.amazonaws.services.s3.model.CanonicalGrantee)5 Grant (com.amazonaws.services.s3.model.Grant)5 File (java.io.File)5 Test (org.junit.Test)5 EmailAddressGrantee (com.amazonaws.services.s3.model.EmailAddressGrantee)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)4 Permission (com.amazonaws.services.s3.model.Permission)3 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 AlluxioURI (alluxio.AlluxioURI)2 ConfigurationRule (alluxio.ConfigurationRule)2 PropertyKey (alluxio.conf.PropertyKey)2 ObjectUnderFileSystem (alluxio.underfs.ObjectUnderFileSystem)2