Example usage for com.amazonaws.services.s3 AmazonS3 setBucketAcl

List of usage examples for com.amazonaws.services.s3 AmazonS3 setBucketAcl

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3 setBucketAcl.

Prototype

public void setBucketAcl(String bucketName, CannedAccessControlList acl)
        throws SdkClientException, AmazonServiceException;

Source Link

Document

Sets the CannedAccessControlList for the specified Amazon S3 bucket using one of the pre-configured CannedAccessControlLists.

Usage

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  . j av a2 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 {/*from   ww  w  .j  ava2s. c o m*/

        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:cloudExplorer.Acl.java

License:Open Source License

void setBUCKETwebsite(String object, String access_key, String secret_key, String endpoint, String bucket) {
    try {//  ww w  .j  a v  a  2 s .  c  o  m
        AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
        AmazonS3 s3Client = new AmazonS3Client(credentials,
                new ClientConfiguration().withSignerOverride("S3SignerType"));
        s3Client.setEndpoint(endpoint);
        BucketWebsiteConfiguration bucketWebsiteConfiguration = s3Client.getBucketWebsiteConfiguration(bucket);
        s3Client.setBucketAcl(bucket, CannedAccessControlList.PublicRead);
        s3Client.setBucketWebsiteConfiguration(bucket,
                new BucketWebsiteConfiguration("index.html", "error.html"));
    } catch (Exception setACLpublic) {
        mainFrame.jTextArea1.append("\nException occurred in ACL");
    }
}

From source file:org.alanwilliamson.amazon.s3.SetBucketAcl.java

License:Open Source License

public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {

    AmazonKey amazonKey = getAmazonKey(_session, argStruct);
    AmazonS3 s3Client = getAmazonS3(amazonKey);
    String bucket = getNamedStringParam(argStruct, "bucket", null);

    CannedAccessControlList acl = amazonKey.getAmazonCannedAcl(getNamedStringParam(argStruct, "acl", null));

    try {/*  w w w  .  ja  va2  s.com*/
        s3Client.setBucketAcl(bucket, acl);
    } catch (Exception e) {
        throwException(_session, "AmazonS3: " + e.getMessage());
    }

    return cfBooleanData.TRUE;
}