Package tigase.io

## Class CertificateContainer

- java.lang.Object
- - tigase.io.CertificateContainer

- All Implemented Interfaces:
    `RepositoryChangeListenerIfc<CertificateItem>`, `CertificateContainerIfc`, `Initializable`, `RegistrarBean`, `UnregisterAware`

      @Bean(name="certificate-container",
            parent=Kernel.class,
            active=true,
            exportable=true)
      public class CertificateContainer
      extends java.lang.Object
      implements CertificateContainerIfc, Initializable, UnregisterAware, RegistrarBean, RepositoryChangeListenerIfc<CertificateItem>

  Class used to keep SSL certificates loaded in memory. To get instance use getter from TLSUtil class.
  Created by andrzej on 29.02.2016.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `CertificateContainer.CertificateChange` | Event indicating certificate change that will be distributed in the cluster.
    `class` | `CertificateContainer.CertificateChanged` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static java.lang.String` | `PER_DOMAIN_CERTIFICATE_KEY` |
    `static java.lang.String` | `SNI_DISABLE_KEY` |

    - ### Fields inherited from interface tigase.io.CertificateContainerIfc

      `CERTIFICATE_CONTAINER_CLASS_KEY, CERTIFICATE_CONTAINER_CLASS_VAL`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CertificateContainer()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addCertificates​(java.util.Map<java.lang.String,​java.lang.String> params)` | Method `addCertificates` allows to add more certificates at run time after the container has bee already initialized.
    `void` | `beforeUnregister()` | Method called before bean unregister.
    `void` | `certificateChange​(CertificateContainer.CertificateChange event)` |
    `javax.net.ssl.KeyManager[]` | `createCertificate​(java.lang.String alias)` | Method `createCertificate` allows to generate self-signed certificate for passed domain name.s
    `CertificateEntry` | `getCertificateEntry​(java.lang.String hostname)` |
    `java.lang.String` | `getDefCertAlias()` | Method to retrieve default alias of certificate to use when domain is `null`
    `javax.net.ssl.KeyManager[]` | `getKeyManagers​(java.lang.String hostname)` | Method returns array of `KeyManager` with certificate for domain or `null` if there is no certificate for domain
    `javax.net.ssl.TrustManager[]` | `getTrustManagers()` |
    `java.security.KeyStore` | `getTrustStore()` |
    `void` | `init​(java.util.Map<java.lang.String,​java.lang.Object> params)` | Method used to pass parameters to initialize instance of class
    `void` | `initialize()` | Method will be called, when bean will be created, configured and ready to use.
    `void` | `itemAdded​(CertificateItem item)` |
    `void` | `itemRemoved​(CertificateItem item)` |
    `void` | `itemUpdated​(CertificateItem item)` |
    `void` | `register​(Kernel kernel)` | Method called when bean is being registered allowing developer to programatically register other beans.
    `void` | `setRepository​(CertificateRepository repository)` |
    `void` | `unregister​(Kernel kernel)` | Method called while bean is being unregistered.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### PER_DOMAIN_CERTIFICATE_KEY

          public static final java.lang.String PER_DOMAIN_CERTIFICATE_KEY

      See Also:
        Constant Field Values

    - #### SNI_DISABLE_KEY

          public static final java.lang.String SNI_DISABLE_KEY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CertificateContainer

          public CertificateContainer()

  - ### Method Detail

    - #### setRepository

          public void setRepository​(CertificateRepository repository)

    - #### addCertificates

          public void addCertificates​(java.util.Map<java.lang.String,​java.lang.String> params)
                               throws java.security.cert.CertificateParsingException

      Description copied from interface: `CertificateContainerIfc`
      Method `addCertificates` allows to add more certificates at run time after the container has bee already initialized. This is to avoid server restart if there are certificates updates or new certificates for new virtual domain. The method should add new certificates or replace existing one if there is already a certificate for a domain.
      Specified by:
        `addCertificates` in interface `CertificateContainerIfc`
      Parameters:
        `params` - a `Map` value with configuration parameters.
      Throws:
        `java.security.cert.CertificateParsingException`

    - #### createCertificate

          public javax.net.ssl.KeyManager[] createCertificate​(java.lang.String alias)
                                                       throws java.security.NoSuchAlgorithmException,
                                                              java.security.cert.CertificateException,
                                                              java.security.SignatureException,
                                                              java.security.NoSuchProviderException,
                                                              java.security.InvalidKeyException,
                                                              java.io.IOException,
                                                              java.security.UnrecoverableKeyException,
                                                              java.security.KeyStoreException

      Description copied from interface: `CertificateContainerIfc`
      Method `createCertificate` allows to generate self-signed certificate for passed domain name.s
      Specified by:
        `createCertificate` in interface `CertificateContainerIfc`
      Parameters:
        `alias` - domain for which certificate should be generated
      Returns:
        an array of `KeyManager` containing generated certificate
      Throws:
        `java.security.NoSuchAlgorithmException`
        `java.security.cert.CertificateException`
        `java.security.SignatureException`
        `java.security.NoSuchProviderException`
        `java.security.InvalidKeyException`
        `java.io.IOException`
        `java.security.UnrecoverableKeyException`
        `java.security.KeyStoreException`

    - #### getDefCertAlias

          public java.lang.String getDefCertAlias()

      Description copied from interface: `CertificateContainerIfc`
      Method to retrieve default alias of certificate to use when domain is `null`
      Specified by:
        `getDefCertAlias` in interface `CertificateContainerIfc`
      Returns:
        default alias

    - #### getCertificateEntry

          public CertificateEntry getCertificateEntry​(java.lang.String hostname)

      Specified by:
        `getCertificateEntry` in interface `CertificateContainerIfc`

    - #### getKeyManagers

          public javax.net.ssl.KeyManager[] getKeyManagers​(java.lang.String hostname)

      Description copied from interface: `CertificateContainerIfc`
      Method returns array of `KeyManager` with certificate for domain or `null` if there is no certificate for domain
      Specified by:
        `getKeyManagers` in interface `CertificateContainerIfc`

    - #### getTrustManagers

          public javax.net.ssl.TrustManager[] getTrustManagers()

      Specified by:
        `getTrustManagers` in interface `CertificateContainerIfc`

    - #### getTrustStore

          public java.security.KeyStore getTrustStore()

      Specified by:
        `getTrustStore` in interface `CertificateContainerIfc`

    - #### init

          public void init​(java.util.Map<java.lang.String,​java.lang.Object> params)

      Description copied from interface: `CertificateContainerIfc`
      Method used to pass parameters to initialize instance of class
      Specified by:
        `init` in interface `CertificateContainerIfc`

    - #### itemAdded

          public void itemAdded​(CertificateItem item)

      Specified by:
        `itemAdded` in interface `RepositoryChangeListenerIfc<CertificateItem>`

    - #### itemUpdated

          public void itemUpdated​(CertificateItem item)

      Specified by:
        `itemUpdated` in interface `RepositoryChangeListenerIfc<CertificateItem>`

    - #### itemRemoved

          public void itemRemoved​(CertificateItem item)

      Specified by:
        `itemRemoved` in interface `RepositoryChangeListenerIfc<CertificateItem>`

    - #### initialize

          public void initialize()

      Description copied from interface: `Initializable`
      Method will be called, when bean will be created, configured and ready to use.
      Specified by:
        `initialize` in interface `Initializable`

    - #### beforeUnregister

          public void beforeUnregister()

      Description copied from interface: `UnregisterAware`
      Method called before bean unregister.
      Specified by:
        `beforeUnregister` in interface `UnregisterAware`

    - #### certificateChange

          @HandleEvent
          public void certificateChange​(CertificateContainer.CertificateChange event)

    - #### register

          public void register​(Kernel kernel)

      Description copied from interface: `RegistrarBean`
      Method called when bean is being registered allowing developer to programatically register other beans.
      Specified by:
        `register` in interface `RegistrarBean`
      Parameters:
        `kernel` - - instance from local scope

    - #### unregister

          public void unregister​(Kernel kernel)

      Description copied from interface: `RegistrarBean`
      Method called while bean is being unregistered.
      Specified by:
        `unregister` in interface `RegistrarBean`
      Parameters:
        `kernel` - - instance from local scope