Class PluginInstaller

All Implemented Interfaces:
AutoCloseable, Component, DestructableComponent, InitializableComponent

public final class PluginInstaller extends AbstractInitializableComponent implements AutoCloseable
The class where the heavy lifting of managing a plugin happens.
  • Field Details

    • LOG

      @Nonnull private static final org.slf4j.Logger LOG
      Class logger.

      private static final String PLUGIN_VERSION_PROPERTY
      Property Name for version.
      See Also:

      private static final String PLUGIN_FILE_PROPERTY_PREFIX
      Property Prefix for install files .
      See Also:

      private static final String PLUGIN_RELATIVE_PATHS_PROPERTY
      Property Name for whether paths are relative.
      See Also:
    • idpHome

      @NonnullAfterInit private Path idpHome
      Where we are installing to.
    • pluginId

      private String pluginId
      What we are dealing with.
    • unpackDirectory

      private Path unpackDirectory
      Where we have unpacked into.
    • downloadDirectory

      private Path downloadDirectory
      Where we have downloaded.
    • description

      private IdPPlugin description
      The plugin's story about itself.
    • acceptKey

      @Nonnull private Predicate<String> acceptKey
      The callback before we install a key into the TrustStore.
    • distribution

      private Path distribution
      The actual distribution.
    • truststore

      private String truststore
      Where to get the keys from if not defaulted.
    • httpClient

      private org.apache.http.client.HttpClient httpClient
      What to use to download things.
    • updateOverrideURLs

      @Nonnull private List<URL> updateOverrideURLs
      If overridden these are the urls to us for update (rather than what the plugin asks for.
    • workspacePath

      @NonnullAfterInit private Path workspacePath
      Dumping space for renamed files.
    • distPath

      @NonnullAfterInit private Path distPath
    • pluginsWebapp

      @NonnullAfterInit private Path pluginsWebapp
      Pluginss webapp.
    • pluginsContents

      @NonnullAfterInit private Path pluginsContents
      Pluginss webapp.
    • installedContents

      @Nullable private List<Path> installedContents
      The absolute paths of what was installed - this is setup by loadCopiedFiles().
    • installedVersionFromContents

      @Nullable private String installedVersionFromContents
      The version from the contents file, or null if it isn't loaded.
    • moduleContext

      @NonnullAfterInit private ModuleContext moduleContext
      The Module Context.
    • moduleChanges

      Module Changes.
    • installedPluginsLoader

      private URLClassLoader installedPluginsLoader
      The "plugins" classpath loader. AutoClosed.
    • installingPluginLoader

      private URLClassLoader installingPluginLoader
      The "plugin under construction" classpath loader. AutoClosed.
    • securityParams

      private HttpClientSecurityParameters securityParams
      The securityParams for the module context.
    • rebuildWar

      private boolean rebuildWar
      Do we rebuild?
  • Constructor Details

    • PluginInstaller

      public PluginInstaller()
  • Method Details

    • setIdpHome

      public void setIdpHome(@Nonnull Path home)
      Set IdP Home.
      home - Where we are working from
    • setPluginId

      public void setPluginId(@Nonnull @NotEmpty String id)
      Set the plugin id.
      id - what to set.
    • setTrustore

      public void setTrustore(@Nullable String loc)
      Set the truststore.
      loc - what set.
    • setAcceptKey

      public void setAcceptKey(@Nonnull Predicate<String> what)
      Set the acceptKey predicate.
      what - what to set.
    • setHttpClient

      public void setHttpClient(@Nonnull org.apache.http.client.HttpClient what)
      Set the httpClient.
      what - what to set.
    • setUpdateOverrideURLs

      public void setUpdateOverrideURLs(@Nonnull List<URL> urls)
      Set the override URLS.
      urls - The updateOverrideURLs to set.
    • setModuleContextSecurityParams

      public void setModuleContextSecurityParams(@Nullable HttpClientSecurityParameters params)
      Set the Module Context security parameters.
      params - what to set.
    • setRebuildWar

      public void setRebuildWar(boolean what)
      Set whether we rebuild the war.
      what - - whether we will or not
    • isRebuildWar

      public boolean isRebuildWar()
      Do we rebuild the war?
      true if we are going to.
    • installPlugin

      public void installPlugin(@Nonnull URL baseURL, @Nonnull @NotEmpty String fileName, boolean checkVersion) throws
      Install the plugin from the provided URL. Involves downloading the file and then doing a installPlugin(Path, String, boolean).
      baseURL - where we get the files from
      fileName - the name
      checkVersion - do we want to check vs the IdP Version?
      Throws: - if badness is detected.
    • installPlugin

      public void installPlugin(@Nonnull Path base, @Nonnull @NotEmpty String fileName, boolean checkVersion) throws
      Install the plugin from a local path.
      • Check signature
      • Unpack to temp folder
      • Install from the folder
      base - the directory where the files are
      fileName - the name
      checkVersion - do we want to check vs the IdP Version?
      Throws: - if badness is detected.
    • uninstall

      public void uninstall() throws
      Remove the jars for this plugin and rebuild the war.
      Throws: - if badness occurs.
    • setupDescriptionFromDistribution

      private void setupDescriptionFromDistribution() throws
      Get hold of the IdPPlugin for this plugin.
      Throws: - if badness is happens.
    • getInstalledContents

      @Nonnull public List<Path> getInstalledContents()
      What files were installed to webapp for this plugin?
      a list of the absolute paths of the installed contents, may be empty if nothing is installed or the plugin didn't install anything.
    • getVersionFromContents

      @Nullable public String getVersionFromContents()
      return the version that the contents page thinks is installed.
      the version, or null if it is not found.
    • getLoadedModules

      private Set<String> getLoadedModules() throws
      What modules (on the installed plugins Classpath) are currently loaded?
      a set of the names of the currently enabled Modules.
      Throws: - on loading a module
    • checkRequiredModules

      private void checkRequiredModules(Set<String> loadedModules) throws
      Police that required modules for plugin installation are enabled.
      loadedModules - the modules we know to be enabled
      Throws: - if any required modules are missing or disabled
    • reEnableModules

      private void reEnableModules(Set<String> loadedModules) throws
      Re-enabled the listed modules iff then are implemented by the plugin we just installed.
      loadedModules - the modules to enable
      Throws: - on errors finding or enabling the modules
    • installNew

      private void installNew(RollbackPluginInstall rollBack) throws
      Copy the webapp folder from the distribution to the per plugin location inside dist.
      rollBack - Roll Back Context
      Throws: - if badness is detected.
    • uninstallOld

      private void uninstallOld(RollbackPluginInstall rollback) throws
      Uninstall the old version of the plugin.
      rollback - Rollback Context
      Throws: - on IO or module errors
    • saveCopiedFiles

      private void saveCopiedFiles(List<Path> copiedFiles) throws
      Stream the copy list to a property file and empty it.
      copiedFiles - The copied files
      Throws: - If we hit an IO exception
    • inferInstalledIdpHome

      private Path inferInstalledIdpHome(Properties props)
      Infer where the properties were installed to.
      props - The property files
      the idpHome it was installed to or null if no files installed
    • loadCopiedFiles

      private void loadCopiedFiles() throws
      Load the contents for this plugin from the properties file used during installation.
      Throws: - if the load fails
    • download

      private void download(URL baseURL, String fileName) throws
      Method to download a zip file to the {downloadDirectory.
      baseURL - Where the zip/tgz and signature file is
      fileName - the name.
      Throws: - if badness is detected.
    • buildHttpClient

      private void buildHttpClient()
      Build the Http Client if it doesn't exist.
    • captureChanges

      private void captureChanges(Map<IdPModule.ModuleResource,IdPModule.ResourceResult> changes)
      Capture module changes.
      changes - what has changed
    • emitModuleChanges

      private void emitModuleChanges()
      Emit module changes.
    • doReportOperation

      private void doReportOperation(@Nonnull IdPModule.ModuleResource resource, @Nonnull IdPModule.ResourceResult result)
      Report on a resource result.
      resource - resource
      result - result of operation
    • download

      private void download(Resource baseResource, String fileName) throws IOException
      Download helper method.
      baseResource - where to go for the file
      fileName - the file name
      IOException - as required
    • unpack

      private void unpack(Path base, String fileName) throws
      Method to unpack a zip or tgz file into out {unpackDirectory.
      base - Where the zip/tgz file is
      fileName - the name.
      Throws: - if badness is detected.
    • isZip

      private boolean isZip(String fileName) throws
      does the file name end in .zip?
      fileName - the name to consider
      true if it ends with .zip
      Throws: - if the name is too short
    • getStreamFor

      private org.apache.commons.compress.archivers.ArchiveInputStream getStreamFor(Path fullName, boolean isZip) throws IOException
      Create the correct ArchiveInputStream for the input.
      fullName - the path of the zip file to unpack.
      isZip - if true then this is a zip file, otherwise a tgz file
      the the appropriate ArchiveInputStream
      IOException - if we trip over an unpack
    • setupPluginId

      private void setupPluginId() throws
      Look into the distribution and suck out the plugin id.
      Throws: - if badness is detected.
    • checkSignature

      private void checkSignature(Path base, String fileName) throws
      Check the signature of the plugin.
      base - Where the zip/tgz file is
      fileName - the name.
      Throws: - if badness is detected.
    • doInitialize

      protected void doInitialize() throws ComponentInitializationException
      doInitialize in class AbstractInitializableComponent
    • getInstalledPluginsLoader

      private URLClassLoader getInstalledPluginsLoader() throws
      Generate a URLClassLoader which looks at the installed WEB-INF/lib in addition to the dist webapp and bin/lib directories. As a side effect, it also copies the libs (since they may well be overwritten)
      an appropriate loader
      Throws: - if a directory traversal fails.
    • getDistributionLoader

      private URLClassLoader getDistributionLoader() throws
      Generate a URLClassLoader which looks at the installing WEB-INF.
      an appropriate loader
      Throws: - if a directory traversal fails.
    • getInstalledPlugins

      public List<IdPPlugin> getInstalledPlugins() throws
      Return a list of the installed plugins.
      All the plugins.
      Throws: - if loafing the classpath fails.
    • getInstalledPlugin

      @Nullable public IdPPlugin getInstalledPlugin(@Nonnull String name)
      Find the IdPPlugin with the provided Id.
      name - what to find
      the IdPPlugin or null if not found.
    • closeSilently

      private void closeSilently(AutoCloseable what)
      close, ignoring errors.
      what - what to close
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getIdPVersion

      protected static PluginVersion getIdPVersion()
      Return a version we can use in a test proof manner.
      the IdP version or a fixed value