Class CryptographyClientBuilder
- All Implemented Interfaces:
ConfigurationTrait<CryptographyClientBuilder>
,HttpTrait<CryptographyClientBuilder>
,TokenCredentialTrait<CryptographyClientBuilder>
CryptographyAsyncClient
and CryptographyClient
, by calling
buildAsyncClient()
and buildClient()
respectively
It constructs an instance of the desired client.
The minimal configuration options required by cryptographyClientBuilder
to build
a CryptographyAsyncClient
or a CryptographyClient
are a credential
and either
a JSON Web Key
or a Azure Key Vault key identifier
.
To ensure correct behavior when performing operations such as Decrypt
, Unwrap
and
Verify
, it is recommended to use a CryptographyAsyncClient
or CryptographyClient
created
for the specific key version that was used for the corresponding inverse operation: Encrypt
,
Wrap
, or Sign
, respectively.
CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .keyIdentifier("<your-key-id>") .credential(new DefaultAzureCredentialBuilder().build()) .buildAsyncClient();
JsonWebKey jsonWebKey = new JsonWebKey().setId("SampleJsonWebKey"); CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .jsonWebKey(jsonWebKey) .buildAsyncClient();
The log detail level
, multiple custom policies
and a 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, a 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
or
Azure Key Vault key identifier
and credential
.
CryptographyClient cryptographyClient = new CryptographyClientBuilder() .keyIdentifier("<your-key-id>") .credential(new DefaultAzureCredentialBuilder().build()) .buildClient();
JsonWebKey jsonWebKey = new JsonWebKey().setId("SampleJsonWebKey"); CryptographyClient cryptographyClient = new CryptographyClientBuilder() .jsonWebKey(jsonWebKey) .buildClient();
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddPolicy
(HttpPipelinePolicy policy) Adds apipeline policy
to apply on each request sent.Creates aCryptographyAsyncClient
based on options set in the builder.Creates aCryptographyClient
based on options set in the builder.clientOptions
(ClientOptions clientOptions) Allows for setting common properties such as application ID, headers, proxy configuration, etc.configuration
(Configuration configuration) Sets the configuration store that is used during construction of the service client.credential
(TokenCredential credential) Sets theTokenCredential
used to authorize requests sent to the service.httpClient
(HttpClient client) Sets theHttpClient
to use for sending and receiving requests to and from the service.httpLogOptions
(HttpLogOptions logOptions) Sets thelogging configuration
to use when sending and receiving requests to and from the service.jsonWebKey
(JsonWebKey jsonWebKey) Sets theJsonWebKey
to be used for local cryptography operations.keyIdentifier
(String keyId) Sets the Azure Key Vault key identifier of the JSON Web Key to be used for cryptography operations.pipeline
(HttpPipeline pipeline) Sets theHttpPipeline
to use for the service client.retryOptions
(RetryOptions retryOptions) Sets theRetryOptions
for all the requests made through the client.retryPolicy
(RetryPolicy retryPolicy) Sets theRetryPolicy
that is used when each request is sent.serviceVersion
(CryptographyServiceVersion version) Sets theCryptographyServiceVersion
that is used when making API requests.
-
Constructor Details
-
CryptographyClientBuilder
public CryptographyClientBuilder()The constructor with defaults.
-
-
Method Details
-
buildClient
Creates aCryptographyClient
based on options set in the builder. Every timebuildClient()
is called, a new instance ofCryptographyClient
is created.If
jsonWebKey
is set, then all other builder settings are ignored.If
pipeline
is set, then thepipeline
andjsonWebKey identifier
are used to create theclient
. All other builder settings are ignored. Ifpipeline
is not set, then anAzure Key Vault credential
andJSON Web Key identifier
are required to build theclient
.- Returns:
- A
CryptographyClient
with the options set from the builder. - Throws:
IllegalStateException
- Ifcredential(TokenCredential)
isnull
orkeyIdentifier(String)
is empty ornull
.IllegalStateException
- If bothretryOptions(RetryOptions)
andretryPolicy(RetryPolicy)
have been set.
-
buildAsyncClient
Creates aCryptographyAsyncClient
based on options set in the builder. Every timebuildAsyncClient()
is called, a new instance ofCryptographyAsyncClient
is created.If
jsonWebKey
is set, then all other builder settings are ignored.If
pipeline
is set, then thepipeline
andjsonWebKey identifier
) are used to create theasync client
. All other builder settings are ignored. Ifpipeline
is not set, then anAzure Key Vault credential
andJSON Web Key identifier
are required to build theasync client
.- Returns:
- A
CryptographyAsyncClient
with the options set from the builder. - Throws:
IllegalStateException
- Ifcredential(TokenCredential)
isnull
orkeyIdentifier(String)
is empty ornull
.IllegalStateException
- If bothretryOptions(RetryOptions)
andretryPolicy(RetryPolicy)
have been set.
-
keyIdentifier
Sets the Azure Key Vault key identifier of the JSON Web Key to be used for cryptography operations.To ensure correct behavior when performing operations such as
Decrypt
,Unwrap
andVerify
, it is recommended to use aCryptographyAsyncClient
orCryptographyClient
created for the specific key version that was used for the corresponding inverse operation:Encrypt
Wrap
, orSign
, respectively.- Parameters:
keyId
- The Azure Key Vault key identifier of the JSON Web Key stored in the key vault.- Returns:
- The updated
CryptographyClientBuilder
object. - Throws:
NullPointerException
- IfkeyId
isnull
.
-
credential
Sets theTokenCredential
used to authorize requests sent to the service. Refer to the Azure SDK for Java identity and authentication documentation for more details on proper usage of theTokenCredential
type.- Specified by:
credential
in interfaceTokenCredentialTrait<CryptographyClientBuilder>
- Parameters:
credential
-TokenCredential
used to authorize requests sent to the service.- Returns:
- The updated
CryptographyClientBuilder
object. - Throws:
NullPointerException
- Ifcredential
isnull
.
-
jsonWebKey
Sets theJsonWebKey
to be used for local cryptography operations.If
jsonWebKey
is provided, then all other builder settings are ignored.- Parameters:
jsonWebKey
- The JSON Web Key to be used for local cryptography operations.- Returns:
- The updated
CryptographyClientBuilder
object. - Throws:
NullPointerException
- IfjsonWebKey
isnull
.
-
httpLogOptions
Sets thelogging configuration
to use when sending and receiving requests to and from the service. If alogLevel
is not provided, default value ofHttpLogDetailLevel.NONE
is set.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipeline
is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipeline
is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if anHttpPipeline
is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
httpLogOptions
in interfaceHttpTrait<CryptographyClientBuilder>
- Parameters:
logOptions
- Thelogging configuration
to use when sending and receiving requests to and from the service.- Returns:
- The updated
CryptographyClientBuilder
object.
-
addPolicy
Adds apipeline policy
to apply on each request sent.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipeline
is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipeline
is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if anHttpPipeline
is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
addPolicy
in interfaceHttpTrait<CryptographyClientBuilder>
- Parameters:
policy
- Apipeline policy
.- Returns:
- The updated
CryptographyClientBuilder
object. - Throws:
NullPointerException
- Ifpolicy
isnull
.
-
httpClient
Sets theHttpClient
to use for sending and receiving requests to and from the service.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipeline
is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipeline
is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if anHttpPipeline
is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
httpClient
in interfaceHttpTrait<CryptographyClientBuilder>
- Parameters:
client
- TheHttpClient
to use for requests.- Returns:
- The updated
CryptographyClientBuilder
object.
-
pipeline
Sets theHttpPipeline
to use for the service client.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipeline
is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipeline
is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if anHttpPipeline
is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.The
JSON Web Key identifier
is not ignored whenpipeline
is set.- Specified by:
pipeline
in interfaceHttpTrait<CryptographyClientBuilder>
- Parameters:
pipeline
-HttpPipeline
to use for sending service requests and receiving responses.- Returns:
- The updated
CryptographyClientBuilder
object.
-
configuration
Sets the configuration store that is used during construction of the service client. The default configuration store is a clone of theglobal configuration store
, useConfiguration.NONE
to bypass using configuration settings during construction.- Specified by:
configuration
in interfaceConfigurationTrait<CryptographyClientBuilder>
- Parameters:
configuration
- The configuration store used to get configuration details.- Returns:
- The updated
CryptographyClientBuilder
object.
-
serviceVersion
Sets theCryptographyServiceVersion
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.
- Parameters:
version
-CryptographyServiceVersion
of the service to be used when making requests.- Returns:
- The updated
CryptographyClientBuilder
object.
-
retryPolicy
Sets theRetryPolicy
that is used when each request is sent. The default retry policy will be used in the pipeline, if not provided. Setting this is mutually exclusive with usingretryOptions(RetryOptions)
.- Parameters:
retryPolicy
- User'sRetryPolicy
applied to each request.- Returns:
- The updated
CryptographyClientBuilder
object.
-
retryOptions
Sets theRetryOptions
for all the requests made through the client.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipeline
is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipeline
is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if anHttpPipeline
is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.Setting this is mutually exclusive with using
retryPolicy(RetryPolicy)
.- Specified by:
retryOptions
in interfaceHttpTrait<CryptographyClientBuilder>
- Parameters:
retryOptions
- TheRetryOptions
to use for all the requests made through the client.- Returns:
- The updated
CryptographyClientBuilder
object.
-
clientOptions
Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is recommended that this method be called with an instance of theHttpClientOptions
class (a subclass of theClientOptions
base class). The HttpClientOptions subclass provides more configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait interface.Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a
HttpPipeline
is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If noHttpPipeline
is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if anHttpPipeline
is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.- Specified by:
clientOptions
in interfaceHttpTrait<CryptographyClientBuilder>
- Parameters:
clientOptions
- A configured instance ofHttpClientOptions
.- Returns:
- The updated
CryptographyClientBuilder
object. - See Also:
-