Amazon CloudFront 预签名从版本 1 更改为版本 2 - Amazon SDK for Java 2.x
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon CloudFront 预签名从版本 1 更改为版本 2

本主题详细介绍了 Amazon CloudFront 从版本 1 (v1) 到版本 2 (v2) 的变化。

高级别更改

更改 v1 v2

Maven 依赖项

<dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-bom</artifactId> <version>1.12.5871</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>cloudfront</artifactId> </dependency> </dependencies>
<dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.27.212</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>cloudfront</artifactId> </dependency> </dependencies>
软件包名称 com.amazonaws.services.cloudfront software.amazon.awssdk.services.cloudfront
类名

CloudFrontUrlSigner

CloudFrontCookieSigner

CloudFrontUtilities

SignedUrl

CannedSignerRequest

CustomSignerRequest

1 最新版本2 最新版本

API改变

行为 v1 v2
创建预设请求 参数直接传递给API。
CannedSignerRequest cannedRequest = CannedSignerRequest.builder() .resourceUrl(resourceUrl) .privateKey(privateKey) .keyPairId(keyPairId) .expirationDate(expirationDate) .build();
生成自定义请求 参数直接传递给API。
CustomSignerRequest customRequest = CustomSignerRequest.builder() .resourceUrl(resourceUrl) .privateKey(keyFile) .keyPairId(keyPairId) .expirationDate(expirationDate) .activeDate(activeDate) .ipRange(ipRange) .build();
生成签名URL(罐装)
String signedUrl = CloudFrontUrlSigner.getSignedURLWithCannedPolicy( resourceUrl, keyPairId, privateKey, expirationDate);
CloudFrontUtilities cloudFrontUtilities = CloudFrontUtilities.create(); SignedUrl signedUrl = cloudFrontUtilities.getSignedUrlWithCannedPolicy(cannedRequest); String url = signedUrl.url();
生成签名的 cookie(自定义)
CookiesForCustomPolicy cookies = CloudFrontCookieSigner.getCookiesForCustomPolicy( resourceUrl, privateKey, keyPairId, expirationDate, activeDate, ipRange);
CloudFrontUtilities cloudFrontUtilities = CloudFrontUtilities.create(); CookiesForCustomPolicy cookies = cloudFrontUtilities.getCookiesForCustomPolicy(customRequest);

v2 中重构的 cookie 标头

在 Java v1 中,Java 以 cookie 标头的Map.Entry<String, String>形式SDK提供。

Map.Entry<String, String> signatureMap = cookies.getSignature(); String signatureKey = signatureMap.getKey(); // "CloudFront-Signature" String signatureValue = signatureMap.getValue(); // "[SIGNATURE_VALUE]"

Java v2 将整个标头作为一个单独String的标题SDK提供。

String signatureHeaderValue = cookies.signatureHeaderValue(); // "CloudFront-Signature=[SIGNATURE_VALUE]"