List of usage examples for com.amazonaws.services.s3 AmazonS3 getBucketAcl
public AccessControlList getBucketAcl(GetBucketAclRequest getBucketAclRequest) throws SdkClientException, AmazonServiceException;
From source file:aws.example.s3.GetAcl.java
License:Open Source License
public static void getBucketAcl(String bucket_name) { System.out.println("Retrieving ACL for bucket: " + bucket_name); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try {// ww w .j a va 2 s. c o m 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); } }
From source file:aws.example.s3.SetAcl.java
License:Open Source License
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.defaultClient(); try {/*from ww w . jav a 2 s . c om*/ // 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); } }
From source file:cloudExplorer.Acl.java
License:Open Source License
void setAccess(String id, int what, String access_key, String secret_key, String endpoint, String bucket) { try {/* ww w . ja va2 s. c om*/ Collection<Grant> grantCollection = new ArrayList<Grant>(); AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); AccessControlList bucketAcl = s3Client.getBucketAcl(bucket); Grant grant = null; if (what == 0) { grant = new Grant(new CanonicalGrantee(id), Permission.Read); grantCollection.add(grant); } if (what == 1) { grant = new Grant(new CanonicalGrantee(id), Permission.FullControl); grantCollection.add(grant); } if (what == 3) { bucketAcl.getGrants().clear(); } bucketAcl.getGrants().addAll(grantCollection); s3Client.setBucketAcl(bucket, bucketAcl); } catch (AmazonServiceException ase) { NewJFrame.jTextArea1.append("\n\nError: " + ase.getErrorMessage()); } }
From source file:com.epam.dlab.automation.cloud.aws.AmazonHelper.java
License:Apache License
public static void printBucketGrants(String bucketName) { LOGGER.info("Print grants for bucket {} on Amazon: ", bucketName); if (ConfigPropertyValue.isRunModeLocal()) { LOGGER.info(" action skipped for run in local mode"); return;//from w w w . j a v a 2 s . c o m } AWSCredentials credentials = getCredentials(); AmazonS3 s3 = new AmazonS3Client(credentials); s3.setRegion(getRegion()); AccessControlList acl = s3.getBucketAcl(bucketName); for (Grant grant : acl.getGrants()) { LOGGER.info(grant); } }
From source file:io.druid.storage.s3.S3Utils.java
License:Apache License
static AccessControlList grantFullControlToBucketOwner(AmazonS3 s3Client, String bucket) { final AccessControlList acl = s3Client.getBucketAcl(bucket); acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl)); return acl;/*from w w w . j ava2 s.co m*/ }