Example usage for com.amazonaws.services.s3.model CORSRule setAllowedOrigins

List of usage examples for com.amazonaws.services.s3.model CORSRule setAllowedOrigins

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model CORSRule setAllowedOrigins.

Prototype

public void setAllowedOrigins(String... allowedOrigins) 

Source Link

Document

Convenience array style method for #setAllowedOrigins(List)

Usage

From source file:com.eucalyptus.cloudformation.resources.standard.actions.AWSS3BucketResourceAction.java

License:Open Source License

private BucketCrossOriginConfiguration convertCrossOriginConfiguration(S3CorsConfiguration corsConfiguration) {
    BucketCrossOriginConfiguration bucketCrossOriginConfiguration = new BucketCrossOriginConfiguration();
    if (corsConfiguration.getCorsRule() != null) {
        List<CORSRule> rules = Lists.newArrayList();
        for (S3CorsConfigurationRule s3CorsConfigurationRule : corsConfiguration.getCorsRule()) {
            CORSRule rule = new CORSRule();
            rule.setAllowedHeaders(s3CorsConfigurationRule.getAllowedHeaders());
            if (s3CorsConfigurationRule.getAllowedMethods() != null) {
                List<CORSRule.AllowedMethods> allowedMethods = Lists.newArrayList();
                for (String allowedMethodStr : s3CorsConfigurationRule.getAllowedMethods()) {
                    allowedMethods.add(CORSRule.AllowedMethods.valueOf(allowedMethodStr));
                }//from   w ww .j a v  a  2  s .co m
                rule.setAllowedMethods(allowedMethods);
            }
            rule.setAllowedOrigins(s3CorsConfigurationRule.getAllowedOrigins());
            rule.setExposedHeaders(s3CorsConfigurationRule.getExposedHeaders());
            rule.setId(s3CorsConfigurationRule.getId());
            rule.setMaxAgeSeconds(s3CorsConfigurationRule.getMaxAge());
            rules.add(rule);
        }
        bucketCrossOriginConfiguration.setRules(rules);
    }
    return bucketCrossOriginConfiguration;
}

From source file:org.duracloud.s3task.streaminghls.EnableHlsTaskRunner.java

License:Apache License

private void setCorsPolicy(String bucketName, List<String> allowedOrigins, String dcHost) {
    // If list is null or empty, add a default value
    if (null == allowedOrigins || allowedOrigins.isEmpty()) {
        allowedOrigins = new ArrayList<>();
        allowedOrigins.add("https://*");
    } else { // If list is not empty, append DuraCloud host to allow streaming via DurAdmin
        allowedOrigins.add("https://" + dcHost);
    }//  w w  w.j  av a 2s  .c  o m

    List<CORSRule> corsRules = new ArrayList<>();

    for (String allowedOrigin : allowedOrigins) {
        CORSRule corsRule = new CORSRule();
        corsRule.setAllowedOrigins(allowedOrigin);
        corsRule.setAllowedMethods(CORSRule.AllowedMethods.GET, CORSRule.AllowedMethods.HEAD);
        corsRule.setMaxAgeSeconds(3000);
        corsRule.setAllowedHeaders("*");
        corsRules.add(corsRule);
    }

    BucketCrossOriginConfiguration corsConfig = new BucketCrossOriginConfiguration().withRules(corsRules);

    s3Client.setBucketCrossOriginConfiguration(bucketName, corsConfig);
}