Class ConfigurableSSLService

java.lang.Object
net.solarnetwork.service.support.ConfigurableSSLService
All Implemented Interfaces:
SSLService

public class ConfigurableSSLService extends Object implements SSLService
Basic implementation of SSLService that allows configuring a keystore and truststore to use for the SSLSocketFactory returned by getSSLSocketFactory().
Version:
2.0
Author:
matt
  • Field Details

    • DEFAULT_KEY_STORE_PATH

      public static final String DEFAULT_KEY_STORE_PATH
      The default value for the keyStorePath property.
      See Also:
    • DEFAULT_TRUST_STORE_PATH

      public static final String DEFAULT_TRUST_STORE_PATH
      The default value for the trustStorePath property.
      See Also:
    • DEFAULT_PASSWORD

      public static final String DEFAULT_PASSWORD
      The default password used for all configurable password properties.
      See Also:
    • log

      protected final org.slf4j.Logger log
      A class-level logger to use.
  • Constructor Details

    • ConfigurableSSLService

      public ConfigurableSSLService()
  • Method Details

    • loadKeyStore

      public static final KeyStore loadKeyStore(String type, InputStream in, String password)
      Load a keystore from an InputStream.
      Parameters:
      type - The keystore type, e.g. KeyStore.getDefaultType().
      in - The stream to load from.
      password - The keystore password to use.
      Returns:
      The keystore.
      Throws:
      CertificateException - if any error occurs
    • saveKeyStore

      public static final void saveKeyStore(KeyStore keyStore, String password, OutputStream out)
      Serialize a KeyStore to an output stream.
      Parameters:
      keyStore - The keystore to serialize.
      password - The password to use.
      out - The stream to write to.
      Throws:
      CertificateException - if any error occurs
    • loadKeyStore

      protected KeyStore loadKeyStore()
    • loadTrustStore

      protected KeyStore loadTrustStore()
    • resetSocketFactory

      protected void resetSocketFactory()
      Clear any cached SSLSocketFactory so that a subsequent call to getSSLSocketFactory() returns a new instance.
    • getTrustManagerFactory

      public TrustManagerFactory getTrustManagerFactory()
      Description copied from interface: SSLService
      Get a trust manager factory, configured appropriately for the application.

      This method may return a singleton object.

      Specified by:
      getTrustManagerFactory in interface SSLService
      Returns:
      the factory
    • getKeyManagerFactory

      public KeyManagerFactory getKeyManagerFactory()
      Description copied from interface: SSLService
      Get a key manager factory, configured appropriately for the application.

      This method may return a singleton object.

      Specified by:
      getKeyManagerFactory in interface SSLService
      Returns:
      the factory
    • getSSLSocketFactory

      public SSLSocketFactory getSSLSocketFactory()
      Description copied from interface: SSLService
      Get a SSL socket factory, configured appropriately for the application.

      This method may return a singleton object.

      Specified by:
      getSSLSocketFactory in interface SSLService
      Returns:
      the factory
    • getKeyStorePath

      public String getKeyStorePath()
      Get the path to the keystore.
      Returns:
      the keyStorePath
    • setKeyStorePath

      public void setKeyStorePath(String keyStorePath)
      Set the path to the keystore.
      Parameters:
      keyStorePath - the keyStorePath to set
    • getTrustStorePath

      public String getTrustStorePath()
      Get the path to the truststore.
      Returns:
      the trustStorePath
    • setTrustStorePath

      public void setTrustStorePath(String trustStorePath)
      Set the path to the truststore.
      Parameters:
      trustStorePath - the trustStorePath to set
    • getTrustStorePassword

      protected String getTrustStorePassword()
      Get the truststore password.
      Returns:
      the trustStorePassword
    • setTrustStorePassword

      public void setTrustStorePassword(String trustStorePassword)
      Set the truststore password.
      Parameters:
      trustStorePassword - the trustStorePassword to set
    • getJreTrustStorePassword

      protected String getJreTrustStorePassword()
      Get the JRE truststore password.
      Returns:
      the jreTrustStorePassword
    • setJreTrustStorePassword

      public void setJreTrustStorePassword(String jreTrustStorePassword)
      Set the JRE truststore password.
      Parameters:
      jreTrustStorePassword - the jreTrustStorePassword to set
    • getKeyStorePassword

      protected String getKeyStorePassword()
      Get the keystore password.
      Returns:
      The keystore password.
    • setKeyStorePassword

      public void setKeyStorePassword(String keyStorePassword)
      Set the keystore password.
      Parameters:
      keyStorePassword - the keyStorePassword to set