public final class CryptographyClientBuilder extends Object
cryptography async client
and cryptography sync client
,
by calling buildAsyncClient
and buildClient
respectively
It constructs an instance of the desired client.
The minimal configuration options required by cryptographyClientBuilder
to
build CryptographyAsyncClient
are (jsonWebKey
or jsonWebKey identifier
) and
credential
).
CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .keyIdentifier("<YOUR-KEY-ID>") .credential(new DefaultAzureCredentialBuilder().build()) .buildAsyncClient();
The log detail level
, multiple custom policies
and custom
http client
can be optionally configured in the CryptographyClientBuilder
.
CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .keyIdentifier("<Your-Key-ID>") .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .addPolicy(new KeyVaultCredentialPolicy(new DefaultAzureCredentialBuilder().build())) .httpClient(HttpClient.createDefault()) .buildAsyncClient();
Alternatively, custom http pipeline
with custom HttpPipelinePolicy
policies
can be specified. It provides finer control over the construction of CryptographyAsyncClient
and CryptographyClient
HttpPipeline pipeline = new HttpPipelineBuilder() .policies(new KeyVaultCredentialPolicy(new DefaultAzureCredentialBuilder().build()), new RetryPolicy()) .build(); CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .pipeline(pipeline) .keyIdentifier("<YOUR-KEY-ID") .buildAsyncClient();
The minimal configuration options required by cryptographyClientBuilder
to
build CryptographyClient
are jsonWebKey
ot jsonWebKey identifier
) and
credential
).
CryptographyClient cryptographyClient = new CryptographyClientBuilder() .keyIdentifier("<YOUR-KEY-IDENTIFIER>") .credential(new DefaultAzureCredentialBuilder().build()) .buildClient();
CryptographyAsyncClient
,
CryptographyClient
Constructor and Description |
---|
CryptographyClientBuilder()
The constructor with defaults.
|
Modifier and Type | Method and Description |
---|---|
CryptographyClientBuilder |
addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed after the client required policies.
|
CryptographyAsyncClient |
buildAsyncClient()
Creates a
CryptographyAsyncClient based on options set in the builder. |
CryptographyClient |
buildClient()
Creates a
CryptographyClient based on options set in the builder. |
CryptographyClientBuilder |
configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service client.
|
CryptographyClientBuilder |
credential(com.azure.core.credential.TokenCredential credential)
Sets the credential to use when authenticating HTTP requests.
|
CryptographyClientBuilder |
httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending and receiving requests to and from the service.
|
CryptographyClientBuilder |
httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.
|
CryptographyClientBuilder |
keyIdentifier(String keyId)
Sets the identifier of the jsonWebKey from Azure Key Vault to be used for cryptography operations.
|
CryptographyClientBuilder |
pipeline(com.azure.core.http.HttpPipeline pipeline)
Sets the HTTP pipeline to use for the service client.
|
CryptographyClientBuilder |
retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets the
RetryPolicy that is used when each request is sent. |
CryptographyClientBuilder |
serviceVersion(CryptographyServiceVersion version)
Sets the
CryptographyServiceVersion that is used when making API requests. |
public CryptographyClientBuilder()
public CryptographyClient buildClient()
CryptographyClient
based on options set in the builder.
Every time buildClient()
is called, a new instance of CryptographyClient
is created.
If pipeline
is set, then the pipeline
and
(jsonWebKey identifier
are used to create the client
. All other builder settings are ignored. If
pipeline
is not set, then
(jsonWebKey vault credential
and
(jsonWebKey identifier
are required to build the
client
.
CryptographyClient
with the options set from the builder.IllegalStateException
- If CryptographyClientBuilder.credential(TokenCredential)
or
either of (CryptographyClientBuilder.keyIdentifier(String)
have not been set.public CryptographyAsyncClient buildAsyncClient()
CryptographyAsyncClient
based on options set in the builder. Every time
CryptographyClientBuilder.buildAsyncClient()
is called, a new instance of CryptographyAsyncClient
is created.
If pipeline
is set, then the pipeline
and
(jsonWebKey identifier
) are used to create the async client
. All other builder settings are ignored. If pipeline
is not set,
then (jsonWebKey vault credential
and (jsonWebKey identifier
are required to build the async client
.
CryptographyAsyncClient
with the options set from the builder.IllegalStateException
- If CryptographyClientBuilder.credential(TokenCredential)
or (CryptographyClientBuilder.keyIdentifier(String)
have not been set.public CryptographyClientBuilder keyIdentifier(String keyId)
If jsonWebKey
is provided then that takes precedence over key identifier and gets used for
cryptography operations.
keyId
- The jsonWebKey identifier representing the jsonWebKey stored in jsonWebKey vault.public CryptographyClientBuilder credential(com.azure.core.credential.TokenCredential credential)
credential
- The credential to use for authenticating HTTP requests.NullPointerException
- if credential
is null
.public CryptographyClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
If logLevel is not provided, default value of HttpLogDetailLevel.NONE
is set.
logOptions
- The logging configuration to use when sending and receiving HTTP requests/responses.public CryptographyClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
policy
- The policy
to be added.NullPointerException
- if policy
is null
.public CryptographyClientBuilder httpClient(com.azure.core.http.HttpClient client)
client
- The HTTP client to use for requests.NullPointerException
- If client
is null
.public CryptographyClientBuilder pipeline(com.azure.core.http.HttpPipeline pipeline)
pipeline
is set, all other settings are ignored, aside from jsonWebKey identifier
or jsonWebKey to build the clients.pipeline
- The HTTP pipeline to use for sending service requests and receiving responses.public CryptographyClientBuilder configuration(com.azure.core.util.Configuration configuration)
global
configuration store
, use Configuration.NONE
to bypass using configuration settings during construction.configuration
- The configuration store used topublic CryptographyClientBuilder serviceVersion(CryptographyServiceVersion version)
CryptographyServiceVersion
that is used when making API requests.
If a service version is not provided, the service version that will be used will be the latest known service version based on the version of the client library being used. If no service version is specified, updating to a newer version the client library will have the result of potentially moving to a newer service version.
version
- CryptographyServiceVersion
of the service to be used when making requests.public CryptographyClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
RetryPolicy
that is used when each request is sent.
The default retry policy will be used in the pipeline, if not provided.retryPolicy
- user's retry policy applied to each request.NullPointerException
- if the specified retryPolicy
is null.Copyright © 2020 Microsoft Corporation. All rights reserved.