Class PluginInstaller
java.lang.Object
net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
net.shibboleth.idp.installer.plugin.impl.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 Summary
Fields Modifier and Type Field Description private Predicate<String>
acceptKey
The callback before we install a key into the TrustStore.private IdPPlugin
description
The plugin's story about itself.private Path
distPath
DistDir.private Path
distribution
The actual distribution.private Path
downloadDirectory
Where we have downloaded.private org.apache.http.client.HttpClient
httpClient
What to use to download things.private Path
idpHome
Where we are installing to.private List<String>
installedContents
What was installed - this is setup byloadCopiedFiles()
.private URLClassLoader
installedPluginsLoader
The "plugins" classpath loader.private String
installedVersionFromContents
The version from the contents file, or null if it isn't loaded.private URLClassLoader
installingPluginLoader
The "plugin under construction" classpath loader.private static org.slf4j.Logger
LOG
Class logger.private ModuleContext
moduleContext
The Module Context.private String
pluginId
What we are dealing with.private Path
pluginsContents
Pluginss webapp.private Path
pluginsWebapp
Pluginss webapp.private HttpClientSecurityParameters
securityParams
The securiotyParams for the module context.private String
truststore
Where to get the keys from if not defaulted.private Path
unpackDirectory
Where we have unpacked into.private List<URL>
updateOverrideURLs
If overridden these are the urls to us for update (rather than what the plugin asks for.private Path
workspacePath
Dumping space for renamed files. -
Constructor Summary
Constructors Constructor Description PluginInstaller()
-
Method Summary
Modifier and Type Method Description private void
buildHttpClient()
Build the Http Client if it doesn't exist.private void
checkRequiredModules(Set<String> loadedModules)
Police that required modules for plugin installation are enabled.private void
checkSignature(Path base, String fileName)
Check the signature of the plugin.void
close()
private void
closeSilently(AutoCloseable what)
close, ignoring errors.protected void
doInitialize()
private void
download(URL baseURL, String fileName)
Method to download a zip file to the {downloadDirectory
.private void
download(Resource baseResource, String fileName)
Download helper method.private URLClassLoader
getDistributionLoader()
Generate aURLClassLoader
which looks at the installing WEB-INF.List<String>
getInstalledContents()
What files were installed to webapp for this plugin?IdPPlugin
getInstalledPlugin(String name)
Find theIdPPlugin
with the provided Id.List<IdPPlugin>
getInstalledPlugins()
Return a list of the installed plugins.private URLClassLoader
getInstalledPluginsLoader()
Generate aURLClassLoader
which looks at the installed WEB-INF/lib in addition to the dist webapp and bin/lib directories.private Set<String>
getLoadedModules()
What modules (on the installed plugins Classpath) are currently loaded?private org.apache.commons.compress.archivers.ArchiveInputStream
getStreamFor(Path fullName, boolean isZip)
Create the correctArchiveInputStream
for the input.String
getVersionFromContents()
return the version that the contents page thinks is installed.private void
installNew(RollbackPluginInstall rollBack)
Copy the webapp folder from the distribution to the per plugin location inside dist.void
installPlugin(URL baseURL, String fileName, boolean checkVersion)
Install the plugin from the provided URL.void
installPlugin(Path base, String fileName, boolean checkVersion)
Install the plugin from a local path.private boolean
isZip(String fileName)
does the file name end in .zip?private void
loadCopiedFiles()
Load the contents for this plugin from the properties file used during installation.private void
reEnableModules(Set<String> loadedModules)
Re-enabled the listed modules iff then are implemented by the plugin we just installed.private void
saveCopiedFiles(List<Path> copiedFiles)
Stream the copy list to a property file and empty it.void
setAcceptKey(Predicate<String> what)
Set the acceptKey predicate.void
setHttpClient(org.apache.http.client.HttpClient what)
Set the httpClient.void
setIdpHome(Path home)
Set IdP Home.void
setModuleContextSecurityParams(HttpClientSecurityParameters params)
Set the Module Context security parameters.void
setPluginId(String id)
Set the plugin id.void
setTrustore(String loc)
Set the truststore.void
setUpdateOverrideURLs(List<URL> urls)
Set the override URLS.private void
setupDescriptionFromDistribution()
Get hold of theIdPPlugin
for this plugin.private void
setupPluginId()
Look into the distribution and suck out the plugin id.void
uninstall()
Remove the jars for this plugin and rebuild the war.private void
uninstallOld(RollbackPluginInstall rollback)
Uninstall the old version of the plugin.private void
unpack(Path base, String fileName)
Method to unpack a zip or tgz file into out {unpackDirectory
.Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
-
Field Details
-
LOG
@Nonnull private static final org.slf4j.Logger LOGClass logger. -
idpHome
Where we are installing to. -
pluginId
What we are dealing with. -
unpackDirectory
Where we have unpacked into. -
downloadDirectory
Where we have downloaded. -
description
The plugin's story about itself. -
acceptKey
The callback before we install a key into the TrustStore. -
distribution
The actual distribution. -
truststore
Where to get the keys from if not defaulted. -
httpClient
private org.apache.http.client.HttpClient httpClientWhat to use to download things. -
updateOverrideURLs
If overridden these are the urls to us for update (rather than what the plugin asks for. -
workspacePath
Dumping space for renamed files. -
distPath
DistDir. -
pluginsWebapp
Pluginss webapp. -
pluginsContents
Pluginss webapp. -
installedContents
What was installed - this is setup byloadCopiedFiles()
. -
installedVersionFromContents
The version from the contents file, or null if it isn't loaded. -
moduleContext
The Module Context. -
installedPluginsLoader
The "plugins" classpath loader. AutoClosed. -
installingPluginLoader
The "plugin under construction" classpath loader. AutoClosed. -
securityParams
The securiotyParams for the module context.
-
-
Constructor Details
-
PluginInstaller
public PluginInstaller()
-
-
Method Details
-
setIdpHome
Set IdP Home.- Parameters:
home
- Where we are working from
-
setPluginId
Set the plugin id.- Parameters:
id
- what to set.
-
setTrustore
Set the truststore.- Parameters:
loc
- what set.
-
setAcceptKey
Set the acceptKey predicate.- Parameters:
what
- what to set.
-
setHttpClient
public void setHttpClient(@Nonnull org.apache.http.client.HttpClient what)Set the httpClient.- Parameters:
what
- what to set.
-
setUpdateOverrideURLs
Set the override URLS.- Parameters:
urls
- The updateOverrideURLs to set.
-
setModuleContextSecurityParams
Set the Module Context security parameters.- Parameters:
params
- what to set.
-
installPlugin
public void installPlugin(@Nonnull URL baseURL, @Nonnull @NotEmpty String fileName, boolean checkVersion) throws org.apache.tools.ant.BuildExceptionInstall the plugin from the provided URL. Involves downloading the file and then doing ainstallPlugin(Path, String, boolean)
.- Parameters:
baseURL
- where we get the files fromfileName
- the namecheckVersion
- do we want to check vs the IdP Version?- Throws:
org.apache.tools.ant.BuildException
- if badness is detected.
-
installPlugin
public void installPlugin(@Nonnull Path base, @Nonnull @NotEmpty String fileName, boolean checkVersion) throws org.apache.tools.ant.BuildExceptionInstall the plugin from a local path.- Check signature
- Unpack to temp folder
- Install from the folder
- Parameters:
base
- the directory where the files arefileName
- the namecheckVersion
- do we want to check vs the IdP Version?- Throws:
org.apache.tools.ant.BuildException
- if badness is detected.
-
uninstall
public void uninstall() throws org.apache.tools.ant.BuildExceptionRemove the jars for this plugin and rebuild the war.- Throws:
org.apache.tools.ant.BuildException
- if badness occurs.
-
setupDescriptionFromDistribution
private void setupDescriptionFromDistribution() throws org.apache.tools.ant.BuildExceptionGet hold of theIdPPlugin
for this plugin.- Throws:
org.apache.tools.ant.BuildException
- if badness is happens.
-
getInstalledContents
What files were installed to webapp for this plugin?- Returns:
- a list of the installed contents, may be empty if nothing is installed or the plugin didn't install anything.
-
getVersionFromContents
return the version that the contents page thinks is installed.- Returns:
- the version, or null if it is not found.
-
getLoadedModules
What modules (on the installed plugins Classpath) are currently loaded?- Returns:
- a set of the names of the currently enabled Modules.
- Throws:
org.apache.tools.ant.BuildException
- on loading a module
-
checkRequiredModules
private void checkRequiredModules(Set<String> loadedModules) throws org.apache.tools.ant.BuildExceptionPolice that required modules for plugin installation are enabled.- Parameters:
loadedModules
- the modules we know to be enabled- Throws:
org.apache.tools.ant.BuildException
- if any required modules are missing or disabled
-
reEnableModules
Re-enabled the listed modules iff then are implemented by the plugin we just installed.- Parameters:
loadedModules
- the modules to enable- Throws:
org.apache.tools.ant.BuildException
- on errors finding or enabling the modules
-
installNew
Copy the webapp folder from the distribution to the per plugin location inside dist.- Parameters:
rollBack
- Roll Back Context- Throws:
org.apache.tools.ant.BuildException
- if badness is detected.
-
uninstallOld
private void uninstallOld(RollbackPluginInstall rollback) throws org.apache.tools.ant.BuildExceptionUninstall the old version of the plugin.- Parameters:
rollback
- Rollback Context- Throws:
org.apache.tools.ant.BuildException
- on IO or module errors
-
saveCopiedFiles
Stream the copy list to a property file and empty it.- Parameters:
copiedFiles
- The copied files- Throws:
org.apache.tools.ant.BuildException
- If we hit an IO exception
-
loadCopiedFiles
private void loadCopiedFiles() throws org.apache.tools.ant.BuildExceptionLoad the contents for this plugin from the properties file used during installation.- Throws:
org.apache.tools.ant.BuildException
- if the load fails
-
download
Method to download a zip file to the {downloadDirectory
.- Parameters:
baseURL
- Where the zip/tgz and signature file isfileName
- the name.- Throws:
org.apache.tools.ant.BuildException
- if badness is detected.
-
buildHttpClient
private void buildHttpClient()Build the Http Client if it doesn't exist. -
download
Download helper method.- Parameters:
baseResource
- where to go for the filefileName
- the file name- Throws:
IOException
- as required
-
unpack
Method to unpack a zip or tgz file into out {unpackDirectory
.- Parameters:
base
- Where the zip/tgz file isfileName
- the name.- Throws:
org.apache.tools.ant.BuildException
- if badness is detected.
-
isZip
does the file name end in .zip?- Parameters:
fileName
- the name to consider- Returns:
- true if it ends with .zip
- Throws:
org.apache.tools.ant.BuildException
- if the name is too short
-
getStreamFor
private org.apache.commons.compress.archivers.ArchiveInputStream getStreamFor(Path fullName, boolean isZip) throws IOExceptionCreate the correctArchiveInputStream
for the input.- Parameters:
fullName
- the path of the zip file to unpack.isZip
- if true then this is a zip file, otherwise a tgz file- Returns:
- the the appropriate
ArchiveInputStream
- Throws:
IOException
- if we trip over an unpack
-
setupPluginId
private void setupPluginId() throws org.apache.tools.ant.BuildExceptionLook into the distribution and suck out the plugin id.- Throws:
org.apache.tools.ant.BuildException
- if badness is detected.
-
checkSignature
Check the signature of the plugin.- Parameters:
base
- Where the zip/tgz file isfileName
- the name.- Throws:
org.apache.tools.ant.BuildException
- if badness is detected.
-
doInitialize
- Overrides:
doInitialize
in classAbstractInitializableComponent
- Throws:
ComponentInitializationException
-
getInstalledPluginsLoader
Generate aURLClassLoader
which looks at the installed WEB-INF/lib in addition to the dist webapp and bin/lib directories.- Returns:
- an appropriate loader
- Throws:
org.apache.tools.ant.BuildException
- if a directory traversal fails.
-
getDistributionLoader
Generate aURLClassLoader
which looks at the installing WEB-INF.- Returns:
- an appropriate loader
- Throws:
org.apache.tools.ant.BuildException
- if a directory traversal fails.
-
getInstalledPlugins
Return a list of the installed plugins.- Returns:
- All the plugins.
- Throws:
org.apache.tools.ant.BuildException
- if loafing the classpath fails.
-
getInstalledPlugin
Find theIdPPlugin
with the provided Id.- Parameters:
name
- what to find- Returns:
- the
IdPPlugin
or null if not found.
-
closeSilently
close, ignoring errors.- Parameters:
what
- what to close
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-