Package org.apache.nifi.security.util
Class SslContextFactory
java.lang.Object
org.apache.nifi.security.util.SslContextFactory
A factory for creating SSL contexts using the application's security properties. By requiring callers to bundle
the properties in a
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.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SSLContextcreateSslContext(TlsConfiguration tlsConfiguration) Create and initialize aSSLContextfrom the provided TLS configuration.static SSLContextcreateSslContext(TlsConfiguration tlsConfiguration, TrustManager[] trustManagers) Create and initialize aSSLContextfrom the provided TLS configuration and Trust Managers.static SSLSocketFactorycreateSSLSocketFactory(TlsConfiguration tlsConfiguration) Convenience method to return theSSLSocketFactoryfrom the createdSSLContextprotected static KeyManager[]getKeyManagers(TlsConfiguration tlsConfiguration) Returns an array ofKeyManagers for the provided configuration.static TrustManager[]getTrustManagers(TlsConfiguration tlsConfiguration) Returns an array ofTrustManagerimplementations based on the provided truststore configurations.static X509TrustManagergetX509TrustManager(TlsConfiguration tlsConfiguration) Returns a configuredX509TrustManagerfor the provided configuration.private static SSLContextinitializeSSLContext(TlsConfiguration tlsConfiguration, KeyManager[] keyManagers, TrustManager[] trustManagers)
-
Field Details
-
logger
private static final org.slf4j.Logger logger
-
-
Constructor Details
-
SslContextFactory
public SslContextFactory()
-
-
Method Details
-
createSslContext
Create and initialize aSSLContextfrom the provided TLS configuration.- Parameters:
tlsConfiguration- the TLS configuration container object- Returns:
SSLContextinitialized from TLS Configuration or null when TLS Configuration is empty- Throws:
TlsException- if there is a problem configuring the SSLContext
-
createSslContext
public static SSLContext createSslContext(TlsConfiguration tlsConfiguration, TrustManager[] trustManagers) throws TlsException Create and initialize aSSLContextfrom the provided TLS configuration and Trust Managers.- Parameters:
tlsConfiguration- the TLS configuration container objecttrustManagers- Trust Managers can be null to use platform default Trust Managers- Returns:
SSLContextinitialized from TLS Configuration or null when TLS Configuration is empty- Throws:
TlsException- if there is a problem configuring the SSLContext
-
getX509TrustManager
public static X509TrustManager getX509TrustManager(TlsConfiguration tlsConfiguration) throws TlsException Returns a configuredX509TrustManagerfor the provided configuration. Useful for constructing HTTP clients which require their own trust management rather than anSSLContext. Filters and removes any trust managers that are notX509TrustManagerimplementations, and returns the first X.509 trust manager.- Parameters:
tlsConfiguration- the TLS configuration container object- Returns:
- an X.509 TrustManager (can be
null) - Throws:
TlsException- if there is a problem reading the truststore to create the trust managers
-
createSSLSocketFactory
public static SSLSocketFactory createSSLSocketFactory(TlsConfiguration tlsConfiguration) throws TlsException Convenience method to return theSSLSocketFactoryfrom the createdSSLContext- Parameters:
tlsConfiguration- the TLS configuration container object- Returns:
- the configured SSLSocketFactory (can be
null) - Throws:
TlsException- if there is a problem creating the SSLContext or SSLSocketFactory
-
getKeyManagers
Returns an array ofKeyManagers for the provided configuration. Useful for constructing HTTP clients which require their own key management rather than anSSLContext. The result can benullor empty. If an empty configuration is provided,nullis returned. However, if a partially-populated but invalid configuration is provided, aTlsExceptionis thrown.- Parameters:
tlsConfiguration- the TLS configuration container object with keystore properties- Returns:
- an array of KeyManagers (can be
null) - Throws:
TlsException- if there is a problem reading the keystore to create the key managers
-
getTrustManagers
public static TrustManager[] getTrustManagers(TlsConfiguration tlsConfiguration) throws TlsException Returns an array ofTrustManagerimplementations based on the provided truststore configurations. The result can benullor empty. If an empty configuration is provided,nullis returned. However, if a partially-populated but invalid configuration is provided, aTlsExceptionis thrown.- Parameters:
tlsConfiguration- the TLS configuration container object with truststore properties- Returns:
- the loaded trust managers
- Throws:
TlsException- if there is a problem reading from the truststore
-
initializeSSLContext
private static SSLContext initializeSSLContext(TlsConfiguration tlsConfiguration, KeyManager[] keyManagers, TrustManager[] trustManagers) throws TlsException - Throws:
TlsException
-