|
|
@@ -371,49 +371,4 @@ public class CommonTest {
|
|
|
System.out.println(claims.getSubject());
|
|
|
System.out.println(claims.getExpiration());
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
- public void setOSSCORS() {
|
|
|
- // Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
- String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
|
|
|
-// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号
|
|
|
- String accessKeyId = "LTAI5tCtRs8DXBLBsn49qRZX";
|
|
|
- String accessKeySecret = "86uC18LZsfB9JU04BK7ImVXfOytEkG";
|
|
|
- String bucketName = "9space-2021";
|
|
|
-
|
|
|
-// 创建OSSClient实例。
|
|
|
- OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
|
|
-
|
|
|
- SetBucketCORSRequest request = new SetBucketCORSRequest(bucketName);
|
|
|
-
|
|
|
-// 跨域资源共享规则的容器,每个存储空间最多允许10条规则。
|
|
|
- ArrayList<SetBucketCORSRequest.CORSRule> putCorsRules = new ArrayList<>();
|
|
|
-
|
|
|
- SetBucketCORSRequest.CORSRule corRule = new SetBucketCORSRequest.CORSRule();
|
|
|
-
|
|
|
- ArrayList<String> allowedOrigin = new ArrayList<String>();
|
|
|
-// 指定允许跨域请求的来源。
|
|
|
- allowedOrigin.add("*");
|
|
|
-
|
|
|
- ArrayList<String> allowedMethod = new ArrayList<String>();
|
|
|
- allowedMethod.add("PUT");
|
|
|
- allowedMethod.add("GET");
|
|
|
- allowedMethod.add("POST");
|
|
|
- allowedMethod.add("HEAD");
|
|
|
-
|
|
|
-
|
|
|
-// 指定允许用户从应用程序中访问的响应头。
|
|
|
-// AllowedOrigins和AllowedMethods最多支持一个星号(*)通配符。星号(*)表示允许所有的域来源或者操作。
|
|
|
- corRule.setAllowedMethods(allowedMethod);
|
|
|
- corRule.setAllowedOrigins(allowedOrigin);
|
|
|
-
|
|
|
-// 最多允许10条规则。
|
|
|
- putCorsRules.add(corRule);
|
|
|
-// 已存在的规则将被覆盖。
|
|
|
- request.setCorsRules(putCorsRules);
|
|
|
- client.setBucketCORS(request);
|
|
|
-
|
|
|
-// 关闭OSSClient。
|
|
|
- client.shutdown();
|
|
|
- }
|
|
|
}
|