|
14 | 14 |
|
15 | 15 | /** |
16 | 16 | * Pipeline policy that uses an {@link AzureSasCredential} to set the shared access signature for a request. |
17 | | - * <p> |
18 | | - * Requests sent with this pipeline policy are required to use {@code HTTPS}. If the request isn't using {@code HTTPS} |
19 | | - * an exception will be thrown to prevent leaking the shared access signature. |
20 | 17 | */ |
21 | 18 | public final class AzureSasCredentialPolicy implements HttpPipelinePolicy { |
22 | 19 | private final AzureSasCredential credential; |
| 20 | + private final boolean requireHttps; |
23 | 21 |
|
24 | 22 | /** |
25 | 23 | * Creates a policy that uses the passed {@link AzureSasCredential} to append sas to query string. |
| 24 | + * <p> |
| 25 | + * Requests sent with this pipeline policy are required to use {@code HTTPS}. |
| 26 | + * If the request isn't using {@code HTTPS} |
| 27 | + * an exception will be thrown to prevent leaking the shared access signature. |
26 | 28 | * |
27 | 29 | * @param credential The {@link AzureSasCredential} containing the shared access signature to use. |
28 | 30 | * @throws NullPointerException If {@code credential} is {@code null}. |
29 | 31 | */ |
30 | 32 | public AzureSasCredentialPolicy(AzureSasCredential credential) { |
31 | | - Objects.requireNonNull(credential, "'credential' cannot be null."); |
| 33 | + this(credential, true); |
| 34 | + } |
32 | 35 |
|
| 36 | + /** |
| 37 | + * Creates a policy that uses the passed {@link AzureSasCredential} to append sas to query string. |
| 38 | + * |
| 39 | + * @param credential The {@link AzureSasCredential} containing the shared access signature to use. |
| 40 | + * @param requireHttps A flag indicating whether {@code HTTPS} is required. |
| 41 | + * @throws NullPointerException If {@code credential} is {@code null}. |
| 42 | + */ |
| 43 | + public AzureSasCredentialPolicy(AzureSasCredential credential, boolean requireHttps) { |
| 44 | + Objects.requireNonNull(credential, "'credential' cannot be null."); |
33 | 45 | this.credential = credential; |
| 46 | + this.requireHttps = requireHttps; |
34 | 47 | } |
35 | 48 |
|
36 | 49 | @Override |
37 | 50 | public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { |
38 | 51 | HttpRequest httpRequest = context.getHttpRequest(); |
39 | | - if ("http".equals(httpRequest.getUrl().getProtocol())) { |
| 52 | + if (requireHttps && "http".equals(httpRequest.getUrl().getProtocol())) { |
40 | 53 | return Mono.error(new IllegalStateException( |
41 | 54 | "Shared access signature credentials require HTTPS to prevent leaking the shared access signature.")); |
42 | 55 | } |
|
0 commit comments