Class SSLContextConfigurator


  • public class SSLContextConfigurator
    extends java.lang.Object
    Utility class, which helps to configure SSLContext.
    Author:
    Alexey Stashok, Hubert Iwaniuk, Bruno Harbulot
    • Field Detail

      • TRUST_STORE_PROVIDER

        public static final java.lang.String TRUST_STORE_PROVIDER
        See Also:
        Constant Field Values
      • KEY_STORE_PROVIDER

        public static final java.lang.String KEY_STORE_PROVIDER
        See Also:
        Constant Field Values
      • TRUST_STORE_FILE

        public static final java.lang.String TRUST_STORE_FILE
        See Also:
        Constant Field Values
      • TRUST_STORE_PASSWORD

        public static final java.lang.String TRUST_STORE_PASSWORD
        See Also:
        Constant Field Values
      • KEY_STORE_PASSWORD

        public static final java.lang.String KEY_STORE_PASSWORD
        See Also:
        Constant Field Values
      • TRUST_STORE_TYPE

        public static final java.lang.String TRUST_STORE_TYPE
        See Also:
        Constant Field Values
      • KEY_FACTORY_MANAGER_ALGORITHM

        public static final java.lang.String KEY_FACTORY_MANAGER_ALGORITHM
        See Also:
        Constant Field Values
      • TRUST_FACTORY_MANAGER_ALGORITHM

        public static final java.lang.String TRUST_FACTORY_MANAGER_ALGORITHM
        See Also:
        Constant Field Values
    • Constructor Detail

      • SSLContextConfigurator

        public SSLContextConfigurator()
        Default constructor. Reads configuration properties from System.getProperties(). Calls SSLContextConfigurator(boolean) with true.
      • SSLContextConfigurator

        public SSLContextConfigurator​(boolean readSystemProperties)
        Constructor that allows you creating empty configuration.
        Parameters:
        readSystemProperties - If true populates configuration from System.getProperties(), else you have empty configuration.
    • Method Detail

      • setTrustStoreProvider

        public void setTrustStoreProvider​(java.lang.String trustStoreProvider)
        Sets the trust store provider name.
        Parameters:
        trustStoreProvider - Trust store provider to set.
      • setKeyStoreProvider

        public void setKeyStoreProvider​(java.lang.String keyStoreProvider)
        Sets the key store provider name.
        Parameters:
        keyStoreProvider - Key store provider to set.
      • setTrustStoreType

        public void setTrustStoreType​(java.lang.String trustStoreType)
        Type of trust store.
        Parameters:
        trustStoreType - Type of trust store to set.
      • setKeyStoreType

        public void setKeyStoreType​(java.lang.String keyStoreType)
        Type of key store.
        Parameters:
        keyStoreType - Type of key store to set.
      • setTrustStorePass

        public void setTrustStorePass​(java.lang.String trustStorePass)
        Password of trust store.
        Parameters:
        trustStorePass - Password of trust store to set.
      • setKeyStorePass

        public void setKeyStorePass​(java.lang.String keyStorePass)
        Password of key store.
        Parameters:
        keyStorePass - Password of key store to set.
      • setKeyStorePass

        public void setKeyStorePass​(char[] keyStorePass)
        Password of key store.
        Parameters:
        keyStorePass - Password of key store to set.
      • setKeyPass

        public void setKeyPass​(java.lang.String keyPass)
        Password of the key in the key store.
        Parameters:
        keyPass - Password of key to set.
      • setKeyPass

        public void setKeyPass​(char[] keyPass)
        Password of the key in the key store.
        Parameters:
        keyPass - Password of key to set.
      • setTrustStoreFile

        public void setTrustStoreFile​(java.lang.String trustStoreFile)
        Sets trust store file name, also makes sure that if other trust store configuration parameters are not set to set them to default values. Method resets trust store bytes if any have been set before via setTrustStoreBytes(byte[]).
        Parameters:
        trustStoreFile - File name of trust store.
      • setTrustStoreBytes

        public void setTrustStoreBytes​(byte[] trustStoreBytes)
        Sets trust store payload as byte array. Method resets trust store file if any has been set before via setTrustStoreFile(java.lang.String).
        Parameters:
        trustStoreBytes - trust store payload.
      • setKeyStoreFile

        public void setKeyStoreFile​(java.lang.String keyStoreFile)
        Sets key store file name, also makes sure that if other key store configuration parameters are not set to set them to default values. Method resets key store bytes if any have been set before via setKeyStoreBytes(byte[]).
        Parameters:
        keyStoreFile - File name of key store.
      • setKeyStoreBytes

        public void setKeyStoreBytes​(byte[] keyStoreBytes)
        Sets key store payload as byte array. Method resets key store file if any has been set before via setKeyStoreFile(java.lang.String).
        Parameters:
        keyStoreBytes - key store payload.
      • setTrustManagerFactoryAlgorithm

        public void setTrustManagerFactoryAlgorithm​(java.lang.String trustManagerFactoryAlgorithm)
        Sets the trust manager factory algorithm.
        Parameters:
        trustManagerFactoryAlgorithm - the trust manager factory algorithm.
      • setKeyManagerFactoryAlgorithm

        public void setKeyManagerFactoryAlgorithm​(java.lang.String keyManagerFactoryAlgorithm)
        Sets the key manager factory algorithm.
        Parameters:
        keyManagerFactoryAlgorithm - the key manager factory algorithm.
      • setSecurityProtocol

        public void setSecurityProtocol​(java.lang.String securityProtocol)
        Sets the SSLContext protocol. The default value is TLS if this is null.
        Parameters:
        securityProtocol - Protocol for SSLContext.getProtocol().
      • validateConfiguration

        @Deprecated
        public boolean validateConfiguration​(boolean needsKeyStore)
        Deprecated.
        Validates SSLContextConfigurator configuration.
        Parameters:
        needsKeyStore - forces failure if no keystore is specified.
        Returns:
        true if configuration is valid, else false.
      • createSSLContext

        @Deprecated
        public javax.net.ssl.SSLContext createSSLContext()
        Deprecated.
        Create a new SSLContext. Note that if there are any problems with the key or trust stores, that no exception will be thrown.
        Returns:
        a new SSLContext
      • createSSLContext

        public javax.net.ssl.SSLContext createSSLContext​(boolean throwException)
        Create a new SSLContext. If the SSLContext cannot be created for whatever reason, a SSLContextConfigurator.GenericStoreException will be raised containing the root cause of the failure.
        Parameters:
        throwException - true if an exception should be raised upon failure.
        Returns:
        a new SSLContext
        Throws:
        SSLContextConfigurator.GenericStoreException - throwException is true and the SSLContext cannot be created
        Since:
        2.3.28
      • retrieve

        public void retrieve​(java.util.Properties props)