@@ -75,9 +75,28 @@ public static CloudFrontUtilities create() {
75
75
* This is a convenience which creates an instance of the {@link CannedSignerRequest.Builder} avoiding the need to
76
76
* create one manually via {@link CannedSignerRequest#builder()}
77
77
*
78
- * @param request A {@link Consumer} that will call methods on {@link CannedSignerRequest.Builder} to create a request.
78
+ * @param request
79
+ * A {@link Consumer} that will call methods on {@link CannedSignerRequest.Builder} to create a request.
79
80
* @return A signed URL that will permit access to a specific distribution
80
81
* and S3 object.
82
+ *
83
+ * <p><b>Example Usage</b>
84
+ * <p>
85
+ * {@snippet :
86
+ * //Generates signed URL String with canned policy, valid for 7 days
87
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
88
+ *
89
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
90
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
91
+ * String keyPairId = "myKeyPairId";
92
+ * PrivateKey privateKey = myPrivateKey;
93
+ *
94
+ * SignedUrl signedUrl = utilities.getSignedUrlWithCannedPolicy(r -> r.resourceUrl(resourceUrl)
95
+ * .privateKey(privateKey)
96
+ * .keyPairId(keyPairId)
97
+ * .expirationDate(expirationDate));
98
+ * String url = signedUrl.url();
99
+ * }
81
100
*/
82
101
public SignedUrl getSignedUrlWithCannedPolicy (Consumer <CannedSignerRequest .Builder > request ) {
83
102
return getSignedUrlWithCannedPolicy (CannedSignerRequest .builder ().applyMutation (request ).build ());
@@ -95,6 +114,27 @@ public SignedUrl getSignedUrlWithCannedPolicy(Consumer<CannedSignerRequest.Build
95
114
* resourceUrl, privateKey, keyPairId, expirationDate
96
115
* @return A signed URL that will permit access to a specific distribution
97
116
* and S3 object.
117
+ *
118
+ * <p><b>Example Usage</b>
119
+ * <p>
120
+ * {@snippet :
121
+ * //Generates signed URL String with canned policy, valid for 7 days
122
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
123
+ *
124
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
125
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
126
+ * String keyPairId = "myKeyPairId";
127
+ * Path keyFile = myKeyFile;
128
+ *
129
+ * CannedSignerRequest cannedRequest = CannedSignerRequest.builder()
130
+ * .resourceUrl(resourceUrl)
131
+ * .privateKey(keyFile)
132
+ * .keyPairId(keyPairId)
133
+ * .expirationDate(expirationDate)
134
+ * .build();
135
+ * SignedUrl signedUrl = utilities.getSignedUrlWithCannedPolicy(cannedRequest);
136
+ * String url = signedUrl.url();
137
+ * }
98
138
*/
99
139
public SignedUrl getSignedUrlWithCannedPolicy (CannedSignerRequest request ) {
100
140
try {
@@ -106,10 +146,10 @@ public SignedUrl getSignedUrlWithCannedPolicy(CannedSignerRequest request) {
106
146
String protocol = uri .getScheme ();
107
147
String domain = uri .getHost ();
108
148
String encodedPath = uri .getPath ()
109
- + (request .resourceUrl ().indexOf ('?' ) >= 0 ? "&" : "?" )
110
- + "Expires=" + request .expirationDate ().getEpochSecond ()
111
- + "&Signature=" + urlSafeSignature
112
- + "&Key-Pair-Id=" + request .keyPairId ();
149
+ + (request .resourceUrl ().indexOf ('?' ) >= 0 ? "&" : "?" )
150
+ + "Expires=" + request .expirationDate ().getEpochSecond ()
151
+ + "&Signature=" + urlSafeSignature
152
+ + "&Key-Pair-Id=" + request .keyPairId ();
113
153
return DefaultSignedUrl .builder ().protocol (protocol ).domain (domain ).encodedPath (encodedPath )
114
154
.url (protocol + "://" + domain + encodedPath ).build ();
115
155
} catch (InvalidKeyException e ) {
@@ -130,9 +170,33 @@ public SignedUrl getSignedUrlWithCannedPolicy(CannedSignerRequest request) {
130
170
* This is a convenience which creates an instance of the {@link CustomSignerRequest.Builder} avoiding the need to
131
171
* create one manually via {@link CustomSignerRequest#builder()}
132
172
*
133
- * @param request A {@link Consumer} that will call methods on {@link CustomSignerRequest.Builder} to create a request.
173
+ * @param request
174
+ * A {@link Consumer} that will call methods on {@link CustomSignerRequest.Builder} to create a request.
134
175
* @return A signed URL that will permit access to distribution and S3
135
176
* objects as specified in the policy document.
177
+ *
178
+ * <p><b>Example Usage</b>
179
+ * <p>
180
+ * {@snippet :
181
+ * //Generates signed URL String with custom policy, with an access window that begins in 2 days and ends in 7 days,
182
+ * //for a specified IP range
183
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
184
+ *
185
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
186
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
187
+ * String keyPairId = "myKeyPairId";
188
+ * PrivateKey privateKey = myPrivateKey;
189
+ * Instant activeDate = Instant.now().plus(Duration.ofDays(2));
190
+ * String ipRange = "192.168.0.1/24";
191
+ *
192
+ * SignedUrl signedUrl = utilities.getSignedUrlWithCustomPolicy(r -> r.resourceUrl(resourceUrl)
193
+ * .privateKey(privateKey)
194
+ * .keyPairId(keyPairId)
195
+ * .expirationDate(expirationDate)
196
+ * .activeDate(activeDate)
197
+ * .ipRange(ipRange));
198
+ * String url = signedUrl.url();
199
+ * }
136
200
*/
137
201
public SignedUrl getSignedUrlWithCustomPolicy (Consumer <CustomSignerRequest .Builder > request ) {
138
202
return getSignedUrlWithCustomPolicy (CustomSignerRequest .builder ().applyMutation (request ).build ());
@@ -152,6 +216,32 @@ public SignedUrl getSignedUrlWithCustomPolicy(Consumer<CustomSignerRequest.Build
152
216
* resourceUrl, privateKey, keyPairId, expirationDate, activeDate (optional), ipRange (optional)
153
217
* @return A signed URL that will permit access to distribution and S3
154
218
* objects as specified in the policy document.
219
+ *
220
+ * <p><b>Example Usage</b>
221
+ * <p>
222
+ * {@snippet :
223
+ * //Generates signed URL String with custom policy, with an access window that begins in 2 days and ends in 7 days,
224
+ * //for a specified IP range
225
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
226
+ *
227
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
228
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
229
+ * String keyPairId = "myKeyPairId";
230
+ * Path keyFile = myKeyFile;
231
+ * Instant activeDate = Instant.now().plus(Duration.ofDays(2));
232
+ * String ipRange = "192.168.0.1/24";
233
+ *
234
+ * CustomSignerRequest customRequest = CustomSignerRequest.builder()
235
+ * .resourceUrl(resourceUrl)
236
+ * .privateKey(keyFile)
237
+ * .keyPairId(keyPairId)
238
+ * .expirationDate(expirationDate)
239
+ * .activeDate(activeDate)
240
+ * .ipRange(ipRange)
241
+ * .build();
242
+ * SignedUrl signedUrl = utilities.getSignedUrlWithCustomPolicy(customRequest);
243
+ * String url = signedUrl.url();
244
+ * }
155
245
*/
156
246
public SignedUrl getSignedUrlWithCustomPolicy (CustomSignerRequest request ) {
157
247
try {
@@ -165,10 +255,10 @@ public SignedUrl getSignedUrlWithCustomPolicy(CustomSignerRequest request) {
165
255
String protocol = uri .getScheme ();
166
256
String domain = uri .getHost ();
167
257
String encodedPath = uri .getPath ()
168
- + (request .resourceUrl ().indexOf ('?' ) >= 0 ? "&" : "?" )
169
- + "Policy=" + urlSafePolicy
170
- + "&Signature=" + urlSafeSignature
171
- + "&Key-Pair-Id=" + request .keyPairId ();
258
+ + (request .resourceUrl ().indexOf ('?' ) >= 0 ? "&" : "?" )
259
+ + "Policy=" + urlSafePolicy
260
+ + "&Signature=" + urlSafeSignature
261
+ + "&Key-Pair-Id=" + request .keyPairId ();
172
262
return DefaultSignedUrl .builder ().protocol (protocol ).domain (domain ).encodedPath (encodedPath )
173
263
.url (protocol + "://" + domain + encodedPath ).build ();
174
264
} catch (InvalidKeyException e ) {
@@ -188,8 +278,30 @@ public SignedUrl getSignedUrlWithCustomPolicy(CustomSignerRequest request) {
188
278
* This is a convenience which creates an instance of the {@link CannedSignerRequest.Builder} avoiding the need to
189
279
* create one manually via {@link CannedSignerRequest#builder()}
190
280
*
191
- * @param request A {@link Consumer} that will call methods on {@link CannedSignerRequest.Builder} to create a request.
281
+ * @param request
282
+ * A {@link Consumer} that will call methods on {@link CannedSignerRequest.Builder} to create a request.
192
283
* @return The signed cookies with canned policy.
284
+ *
285
+ * <p><b>Example Usage</b>
286
+ * <p>
287
+ * {@snippet :
288
+ * //Generates signed Cookie for canned policy, valid for 7 days
289
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
290
+ *
291
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
292
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
293
+ * String keyPairId = "myKeyPairId";
294
+ * PrivateKey privateKey = myPrivateKey;
295
+ *
296
+ * CookiesForCannedPolicy cookies = utilities.getSignedCookiesForCannedPolicy(r -> r.resourceUrl(resourceUrl)
297
+ * .privateKey(privateKey)
298
+ * .keyPairId(keyPairId)
299
+ * .expirationDate(expirationDate));
300
+ * // Generates Set-Cookie header values to send to the viewer to allow access
301
+ * String signatureHeaderValue = cookies.signatureHeaderValue();
302
+ * String keyPairIdHeaderValue = cookies.keyPairIdHeaderValue();
303
+ * String expiresHeaderValue = cookies.expiresHeaderValue();
304
+ * }
193
305
*/
194
306
public CookiesForCannedPolicy getCookiesForCannedPolicy (Consumer <CannedSignerRequest .Builder > request ) {
195
307
return getCookiesForCannedPolicy (CannedSignerRequest .builder ().applyMutation (request ).build ());
@@ -207,6 +319,30 @@ public CookiesForCannedPolicy getCookiesForCannedPolicy(Consumer<CannedSignerReq
207
319
* A {@link CannedSignerRequest} configured with the following values:
208
320
* resourceUrl, privateKey, keyPairId, expirationDate
209
321
* @return The signed cookies with canned policy.
322
+ *
323
+ * <p><b>Example Usage</b>
324
+ * <p>
325
+ * {@snippet :
326
+ * //Generates signed Cookie for canned policy, valid for 7 days
327
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
328
+ *
329
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
330
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
331
+ * String keyPairId = "myKeyPairId";
332
+ * Path keyFile = myKeyFile;
333
+ *
334
+ * CannedSignerRequest cannedRequest = CannedSignerRequest.builder()
335
+ * .resourceUrl(resourceUrl)
336
+ * .privateKey(keyFile)
337
+ * .keyPairId(keyPairId)
338
+ * .expirationDate(expirationDate)
339
+ * .build();
340
+ * CookiesForCannedPolicy cookies = utilities.getCookiesForCannedPolicy(cannedRequest);
341
+ * // Generates Set-Cookie header values to send to the viewer to allow access
342
+ * String signatureHeaderValue = cookies.signatureHeaderValue();
343
+ * String keyPairIdHeaderValue = cookies.keyPairIdHeaderValue();
344
+ * String expiresHeaderValue = cookies.expiresHeaderValue();
345
+ * }
210
346
*/
211
347
public CookiesForCannedPolicy getCookiesForCannedPolicy (CannedSignerRequest request ) {
212
348
try {
@@ -234,8 +370,35 @@ public CookiesForCannedPolicy getCookiesForCannedPolicy(CannedSignerRequest requ
234
370
* This is a convenience which creates an instance of the {@link CustomSignerRequest.Builder} avoiding the need to
235
371
* create one manually via {@link CustomSignerRequest#builder()}
236
372
*
237
- * @param request A {@link Consumer} that will call methods on {@link CustomSignerRequest.Builder} to create a request.
373
+ * @param request
374
+ * A {@link Consumer} that will call methods on {@link CustomSignerRequest.Builder} to create a request.
238
375
* @return The signed cookies with custom policy.
376
+ *
377
+ * <p><b>Example Usage</b>
378
+ * <p>
379
+ * {@snippet :
380
+ * //Generates signed Cookie for custom policy, with an access window that begins in 2 days and ends in 7 days,
381
+ * //for a specified IP range
382
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
383
+ *
384
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
385
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
386
+ * String keyPairId = "myKeyPairId";
387
+ * PrivateKey privateKey = myPrivateKey;
388
+ * Instant activeDate = Instant.now().plus(Duration.ofDays(2));
389
+ * String ipRange = "192.168.0.1/24";
390
+ *
391
+ * CookiesForCustomPolicy cookies = utilities.getCookiesForCustomPolicy(r -> r.resourceUrl(resourceUrl)
392
+ * .privateKey(privateKey)
393
+ * .keyPairId(keyPairId)
394
+ * .expirationDate(expirationDate)
395
+ * .activeDate(activeDate)
396
+ * .ipRange(ipRange));
397
+ * // Generates Set-Cookie header values to send to the viewer to allow access
398
+ * String signatureHeaderValue = cookies.signatureHeaderValue();
399
+ * String keyPairIdHeaderValue = cookies.keyPairIdHeaderValue();
400
+ * String policyHeaderValue = cookies.policyHeaderValue();
401
+ * }
239
402
*/
240
403
public CookiesForCustomPolicy getCookiesForCustomPolicy (Consumer <CustomSignerRequest .Builder > request ) {
241
404
return getCookiesForCustomPolicy (CustomSignerRequest .builder ().applyMutation (request ).build ());
@@ -251,6 +414,35 @@ public CookiesForCustomPolicy getCookiesForCustomPolicy(Consumer<CustomSignerReq
251
414
* A {@link CustomSignerRequest} configured with the following values:
252
415
* resourceUrl, privateKey, keyPairId, expirationDate, activeDate (optional), ipRange (optional)
253
416
* @return The signed cookies with custom policy.
417
+ *
418
+ * <p><b>Example Usage</b>
419
+ * <p>
420
+ * {@snippet :
421
+ * //Generates signed Cookie for custom policy, with an access window that begins in 2 days and ends in 7 days,
422
+ * //for a specified IP range
423
+ * CloudFrontUtilities utilities = CloudFrontUtilities.create();
424
+ *
425
+ * Instant expirationDate = Instant.now().plus(Duration.ofDays(7));
426
+ * String resourceUrl = "https://d111111abcdef8.cloudfront.net/s3ObjectKey";
427
+ * String keyPairId = "myKeyPairId";
428
+ * Path keyFile = myKeyFile;
429
+ * Instant activeDate = Instant.now().plus(Duration.ofDays(2));
430
+ * String ipRange = "192.168.0.1/24";
431
+ *
432
+ * CustomSignerRequest customRequest = CustomSignerRequest.builder()
433
+ * .resourceUrl(resourceUrl)
434
+ * .privateKey(keyFile)
435
+ * .keyPairId(keyFile)
436
+ * .expirationDate(expirationDate)
437
+ * .activeDate(activeDate)
438
+ * .ipRange(ipRange)
439
+ * .build();
440
+ * CookiesForCustomPolicy cookies = utilities.getCookiesForCustomPolicy(customRequest);
441
+ * // Generates Set-Cookie header values to send to the viewer to allow access
442
+ * String signatureHeaderValue = cookies.signatureHeaderValue();
443
+ * String keyPairIdHeaderValue = cookies.keyPairIdHeaderValue();
444
+ * String policyHeaderValue = cookies.policyHeaderValue();
445
+ * }
254
446
*/
255
447
public CookiesForCustomPolicy getCookiesForCustomPolicy (CustomSignerRequest request ) {
256
448
try {
0 commit comments