com.amazonaws.services.s3.model.BucketPolicy Java Examples

The following examples show how to use com.amazonaws.services.s3.model.BucketPolicy. 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 6 votes vote down vote up
@Override
public boolean backupExistingConfigForResource(final String resourceId, final String resourceType,
        Map<String, Object> clientMap, Map<String, String> ruleParams,Map<String, String> issue) throws AutoFixException {
    LOGGER.debug(String.format("backing up the config for %s" , resourceId));
    AmazonS3 client = (AmazonS3) clientMap.get("client");
    Gson gson = new Gson();
    AccessControlList bucketAcl = client.getBucketAcl(resourceId);
    List<Grant> grants = bucketAcl.getGrantsAsList();
    String oldConfig = gson.toJson(grants);
    backupOldConfig(resourceId, BUCKET_ACL, oldConfig);
    BucketPolicy bucketPolicy = client.getBucketPolicy(resourceId);
    if (!Strings.isNullOrEmpty(bucketPolicy.getPolicyText())) {
        backupOldConfig(resourceId, BUCKET_POLICY, bucketPolicy.getPolicyText());
    }
    LOGGER.debug("backup complete for " + resourceId);
    return true;
}
 
Example #2
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 #3
Source File: S3PacbotUtils.java    From pacbot with Apache License 2.0 5 votes vote down vote up
private static JsonArray getPolicyArray(AmazonS3Client awsS3Client,String s3BucketName) {
	JsonParser jsonParser = new JsonParser();
	JsonArray policyJsonArray = new JsonArray();
	BucketPolicy bucketPolicy = awsS3Client.getBucketPolicy(s3BucketName);

	
	if (!com.amazonaws.util.StringUtils.isNullOrEmpty(bucketPolicy.getPolicyText())) {
		JsonObject resultJson = (JsonObject) jsonParser.parse(bucketPolicy.getPolicyText());
		policyJsonArray = resultJson.get("Statement").getAsJsonArray();
	}
	return policyJsonArray;
}
 
Example #4
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!");
}
 
Example #5
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public BucketPolicy getBucketPolicy(String bucketName) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
Example #6
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public BucketPolicy getBucketPolicy(GetBucketPolicyRequest getBucketPlcReq) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
Example #7
Source File: AmazonS3Mock.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public BucketPolicy getBucketPolicy(String bucketName) throws AmazonClientException, AmazonServiceException {
  // TODO Auto-generated method stub
  return null;
}
 
Example #8
Source File: AmazonS3Mock.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public BucketPolicy getBucketPolicy(GetBucketPolicyRequest getBucketPolicyRequest) throws AmazonClientException,
    AmazonServiceException {
  // TODO Auto-generated method stub
  return null;
}