public final class SslContextFactory extends Object
TlsConfiguration
container object, much better validation and property matching can
occur. The public
methods are designed for easy use, while the protected
methods provide more
granular (but less common) access to intermediate objects if required.Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
logger |
Constructor and Description |
---|
SslContextFactory() |
Modifier and Type | Method and Description |
---|---|
static SSLContext |
createSslContext(TlsConfiguration tlsConfiguration)
Create and initialize a
SSLContext from the provided TLS configuration. |
static SSLContext |
createSslContext(TlsConfiguration tlsConfiguration,
TrustManager[] trustManagers)
Create and initialize a
SSLContext from the provided TLS configuration and Trust Managers. |
static SSLSocketFactory |
createSSLSocketFactory(TlsConfiguration tlsConfiguration)
Convenience method to return the
SSLSocketFactory from the created SSLContext |
protected static KeyManager[] |
getKeyManagers(TlsConfiguration tlsConfiguration)
Returns an array of
KeyManager s for the provided configuration. |
static TrustManager[] |
getTrustManagers(TlsConfiguration tlsConfiguration)
Returns an array of
TrustManager implementations based on the provided truststore configurations. |
static X509TrustManager |
getX509TrustManager(TlsConfiguration tlsConfiguration)
Returns a configured
X509TrustManager for the provided configuration. |
private static SSLContext |
initializeSSLContext(TlsConfiguration tlsConfiguration,
KeyManager[] keyManagers,
TrustManager[] trustManagers) |
public static SSLContext createSslContext(TlsConfiguration tlsConfiguration) throws TlsException
SSLContext
from the provided TLS configuration.tlsConfiguration
- the TLS configuration container objectSSLContext
initialized from TLS Configuration or null when TLS Configuration is emptyTlsException
- if there is a problem configuring the SSLContextpublic static SSLContext createSslContext(TlsConfiguration tlsConfiguration, TrustManager[] trustManagers) throws TlsException
SSLContext
from the provided TLS configuration and Trust Managers.tlsConfiguration
- the TLS configuration container objecttrustManagers
- Trust Managers can be null to use platform default Trust ManagersSSLContext
initialized from TLS Configuration or null when TLS Configuration is emptyTlsException
- if there is a problem configuring the SSLContextpublic static X509TrustManager getX509TrustManager(TlsConfiguration tlsConfiguration) throws TlsException
X509TrustManager
for the provided configuration. Useful for
constructing HTTP clients which require their own trust management rather than an
SSLContext
. Filters and removes any trust managers that are not
X509TrustManager
implementations, and returns the first
X.509 trust manager.tlsConfiguration
- the TLS configuration container objectnull
)TlsException
- if there is a problem reading the truststore to create the trust managerspublic static SSLSocketFactory createSSLSocketFactory(TlsConfiguration tlsConfiguration) throws TlsException
SSLSocketFactory
from the created SSLContext
tlsConfiguration
- the TLS configuration container objectnull
)TlsException
- if there is a problem creating the SSLContext or SSLSocketFactoryprotected static KeyManager[] getKeyManagers(TlsConfiguration tlsConfiguration) throws TlsException
KeyManager
s for the provided configuration. Useful for constructing
HTTP clients which require their own key management rather than an SSLContext
. The result can be
null
or empty. If an empty configuration is provided, null
is returned. However, if a partially-populated
but invalid configuration is provided, a TlsException
is thrown.tlsConfiguration
- the TLS configuration container object with keystore propertiesnull
)TlsException
- if there is a problem reading the keystore to create the key managerspublic static TrustManager[] getTrustManagers(TlsConfiguration tlsConfiguration) throws TlsException
TrustManager
implementations based on the provided truststore configurations. The result can be
null
or empty. If an empty configuration is provided, null
is returned. However, if a partially-populated
but invalid configuration is provided, a TlsException
is thrown.
Most callers do not need the full array and can use getX509TrustManager(TlsConfiguration)
directly.
tlsConfiguration
- the TLS configuration container object with truststore propertiesTlsException
- if there is a problem reading from the truststoreprivate static SSLContext initializeSSLContext(TlsConfiguration tlsConfiguration, KeyManager[] keyManagers, TrustManager[] trustManagers) throws TlsException
TlsException
Copyright © 2021 Apache NiFi Project. All rights reserved.