Java Code Examples for com.amazonaws.services.s3.model.BucketPolicy#getPolicyText()

The following examples show how to use com.amazonaws.services.s3.model.BucketPolicy#getPolicyText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3GlobalAccessAutoFix.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Revoke public bucket policy.
 *
 * @param awsS3Client the aws S 3 client
 * @param s3BucketName the s 3 bucket name
 */
private void revokePublicBucketPolicy(AmazonS3Client awsS3Client, String s3BucketName) {
    BucketPolicy bucketPolicy = awsS3Client.getBucketPolicy(s3BucketName);
    if (bucketPolicy.getPolicyText() != null && !bucketPolicy.getPolicyText().equals(PacmanSdkConstants.EMPTY)) {
        awsS3Client.deleteBucketPolicy(s3BucketName);
    }
}
 
Example 2
Source File: GetBucketPolicy.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    GetBucketPolicy <bucket>\n\n" +
            "Where:\n" +
            "    bucket - the bucket to get the policy from.\n\n" +
            "Example:\n" +
            "    GetBucketPolicy testbucket\n\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String bucket_name = args[0];
    String policy_text = null;

    System.out.format("Getting policy for bucket: \"%s\"\n\n", bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    try {
        BucketPolicy bucket_policy = s3.getBucketPolicy(bucket_name);
        policy_text = bucket_policy.getPolicyText();
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }

    if (policy_text == null) {
        System.out.println("The specified bucket has no bucket policy.");
    } else {
        System.out.println("Returned policy:");
        System.out.println("----");
        System.out.println(policy_text);
        System.out.println("----\n");
    }

    System.out.println("Done!");
}