Interface SelfSignedCertificate
When a test class is annotated with
@SelfSignedCert, the extension generates
self-signed certificates for both server and client. This type can be injected into test fields annotated with
@SslCert or into test method parameters by type.
Usage
@SelfSignedCert
@RestBootstrap(MyResource.class)
public class SslTest {
@SslCert
private SelfSignedCertificate certificate;
@Test
public void testSsl() {
SSLContext clientCtx = certificate.clientSslContext();
// use the client SSL context to configure a non-Jakarta REST client
}
}
When combined with @RestBootstrap, the server is
automatically started with HTTPS and injected Client instances are configured
with the client SSLContext. In that case, direct access to this type is often not needed.
This type is primarily useful when configuring non-Jakarta REST HTTP clients, when direct access to keystore files is
required, or when using @SelfSignedCert standalone
without @RestBootstrap.
For custom SSL configuration (e.g., using your own certificates), use a
ConfigurationProvider for the server and a RestClientBuilderProvider for the client instead.
- Since:
- 1.0
- Author:
- James R. Perkins
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the clientKeyStorecontaining the client's private key and certificate.Returns the path to the client keystore file containing the client's private key and certificate.Returns theSSLContextconfigured for the client.Returns the clienttruststorecontaining the server's certificate.Returns the path to the client truststore file containing the server's certificate.Returns the password used for all keystore and truststore files.Returns the keystore type used for all generated keystore and truststore files.Returns the serverKeyStorecontaining the server's private key and certificate.Returns the path to the server keystore file containing the server's private key and certificate.Returns theSSLContextconfigured for the server.Returns the servertruststorecontaining the client's certificate.Returns the path to the server truststore file containing the client's certificate.
-
Method Details
-
clientSslContext
SSLContext clientSslContext()Returns theSSLContextconfigured for the client.This context is automatically applied to injected
Clientinstances when@SelfSignedCertis present on the test class alongside@RestBootstrapand no customRestClientBuilderProvideris specified via@RestClientConfig. When a custom provider is used, it is responsible for configuring the client SSL context itself, typically via@SslCertfield injection.- Returns:
- the client SSL context
-
clientKeyStore
-
clientKeyStorePath
Path clientKeyStorePath()Returns the path to the client keystore file containing the client's private key and certificate.- Returns:
- the path to the client keystore file
-
clientTrustStore
KeyStore clientTrustStore()Returns the clienttruststorecontaining the server's certificate.This can be used directly with APIs that accept a
KeyStore, such asClientBuilder.trustStore().- Returns:
- the client truststore
-
clientTrustStorePath
Path clientTrustStorePath()Returns the path to the client truststore file containing the server's certificate.- Returns:
- the path to the client truststore file
-
serverSslContext
SSLContext serverSslContext()Returns theSSLContextconfigured for the server.This context is automatically applied to the
SeBootstrap Configurationwhen@SelfSignedCertis present on the test class alongside@RestBootstrapand no customConfigurationProvideris specified viaconfigFactory. When a custom provider is used, it is responsible for configuring the server SSL context itself, typically via@SslCertfield injection.- Returns:
- the server SSL context
-
serverKeyStore
-
serverKeyStorePath
Path serverKeyStorePath()Returns the path to the server keystore file containing the server's private key and certificate.- Returns:
- the path to the server keystore file
-
serverTrustStore
KeyStore serverTrustStore()Returns the servertruststorecontaining the client's certificate.This can be used directly with APIs that accept a
KeyStore, such asClientBuilder.trustStore().- Returns:
- the server truststore
-
serverTrustStorePath
Path serverTrustStorePath()Returns the path to the server truststore file containing the client's certificate.- Returns:
- the path to the server truststore file
-
keyStorePassword
String keyStorePassword()Returns the password used for all keystore and truststore files.- Returns:
- the keystore password
-
keyStoreType
String keyStoreType()Returns the keystore type used for all generated keystore and truststore files.- Returns:
- the keystore type (e.g.,
"PKCS12")
-