com.amazonaws.services.s3.model.BucketPolicy#getPolicyText ( )源码实例Demo

下面列出了com.amazonaws.services.s3.model.BucketPolicy#getPolicyText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pacbot   文件: S3GlobalAccessAutoFix.java
/**
 * 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);
    }
}
 
源代码2 项目: aws-doc-sdk-examples   文件: GetBucketPolicy.java
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!");
}