Class PluginInstaller
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.idp.installer.plugin.impl.PluginInstaller
- All Implemented Interfaces:
AutoCloseable,Component,DestructableComponent,InitializableComponent
The class where the heavy lifting of managing a plugin happens.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe callback before we install a key into the TrustStore.private IdPPluginThe plugin's story about itself.private PathDistDir.private PathThe actual distribution.private PathWhere we have downloaded.private final org.apache.hc.client5.http.classic.HttpClientWhat to use to download things.private PathWhere we are installing to.The absolute paths of what was installed - this is setup byloadCopiedFiles().private URLClassLoaderThe "plugins" classpath loader.private StringThe version from the contents file, or null if it isn't loaded.private URLClassLoaderThe "plugin under construction" classpath loader.private static final org.slf4j.LoggerClass logger.private final Map<Module.ModuleResource,Module.ResourceResult> Module Changes.private ModuleContextThe Module Context.private static final StringProperty Prefix for install files .private static final StringProperty Name for whether paths are relative.private static final StringProperty Name for version.private StringWhat we are dealing with.private PathPluginss webapp.private PathPluginss webapp.private booleanDo we rebuild?private HttpClientSecurityParametersThe securityParams for the module context.private StringWhere to get the keys from if not defaulted.private PathWhere we have unpacked into.If overridden these are the urls to us for update (rather than what the plugin asks for.private PathDumping space for renamed files. -
Constructor Summary
ConstructorsConstructorDescriptionPluginInstaller(org.apache.hc.client5.http.classic.HttpClient client) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCapture module changes.private voidcheckRequiredModules(Set<String> loadedModules) Police that required modules for plugin installation are enabled.private voidcheckSignature(Path base, String fileName) Check the signature of the plugin.voidclose()private voidcloseSilently(AutoCloseable what) close, ignoring errors.protected voidprivate voiddoReportOperation(Module.ModuleResource resource, Module.ResourceResult result) Report on a resource result.private voidMethod to download a zip file to the {downloadDirectory.private voidEmit module changes.private IdPPluginCheck for non null and then if so return thedescription.private URLClassLoaderGenerate aURLClassLoaderwhich looks at the installing WEB-INF.private PathGet a null safe idpHome.protected static InstallableComponentVersionReturn a version we can use in a test proof manner.What files were installed to webapp for this plugin?getInstalledPlugin(String name) Find theIdPPluginwith the provided Id.Return a list of the installed plugins.private URLClassLoaderGenerate aURLClassLoaderwhich looks at the installed WEB-INF/lib in addition to the dist webapp and bin/lib directories.What modules (on the installed plugins Classpath) are currently loaded?private ModuleContextCheck for initialized and if so return themoduleContext.private PathCheck for initialized and if so return thepluginsWebapp.private org.apache.commons.compress.archivers.ArchiveInputStream<?>getStreamFor(Path fullName, boolean isZip) Create the correctArchiveInputStreamfor the input.return the version that the contents page thinks is installed.private PathinferInstalledIdpHome(Properties props) Infer where the properties were installed to.private voidinstallNew(RollbackPluginInstall rollBack) Copy the webapp folder from the distribution to the per plugin location inside dist.voidinstallPlugin(URL baseURL, String fileName, boolean checkVersion) Install the plugin from the provided URL.voidinstallPlugin(Path base, String fileName, boolean checkVersion) Install the plugin from a local path.booleanDo we rebuild the war?private booleandoes the file name end in .zip?private voidLoad the contents for this plugin from the properties file used during installation.private voidreEnableModules(Set<String> loadedModules) Re-enabled the listed modules iff then are implemented by the plugin we just installed.private voidsaveCopiedFiles(List<Path> copiedFiles) Stream the copy list to a property file and empty it.voidsetAcceptKey(Predicate<String> what) Set the acceptKey predicate.voidsetIdpHome(Path home) Set IdP Home.voidSet the Module Context security parameters.voidsetPluginId(String id) Set the plugin id.voidsetRebuildWar(boolean what) Set whether we rebuild the war.voidsetTrustore(String loc) Set the truststore.voidsetUpdateOverrideURLs(List<URL> urls) Set the override URLS.private voidGet hold of theIdPPluginfor this plugin.private voidLook into the distribution and suck out the plugin id.voidRemove the jars for this plugin and rebuild the war.private voiduninstallOld(RollbackPluginInstall rollback) Uninstall the old version of the plugin.private voidMethod to unpack a zip or tgz file into out {unpackDirectory.Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized
-
Field Details
-
LOG
@Nonnull private static final org.slf4j.Logger LOGClass logger. -
PLUGIN_VERSION_PROPERTY
Property Name for version.- See Also:
-
PLUGIN_FILE_PROPERTY_PREFIX
Property Prefix for install files .- See Also:
-
PLUGIN_RELATIVE_PATHS_PROPERTY
Property Name for whether paths are relative.- See Also:
-
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
@Nonnull private final org.apache.hc.client5.http.classic.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
The absolute paths of 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. -
moduleChanges
Module Changes. -
installedPluginsLoader
The "plugins" classpath loader. AutoClosed. -
installingPluginLoader
The "plugin under construction" classpath loader. AutoClosed. -
securityParams
The securityParams for the module context. -
rebuildWar
private boolean rebuildWarDo we rebuild?
-
-
Constructor Details
-
PluginInstaller
public PluginInstaller(@Nonnull org.apache.hc.client5.http.classic.HttpClient client) Constructor.- Parameters:
client- - the HttpClient to use
-
-
Method Details
-
setIdpHome
Set IdP Home.- Parameters:
home- Where we are working from
-
getIdpHome
Get a null safe idpHome.- Returns:
- idpHome
-
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.
-
setUpdateOverrideURLs
Set the override URLS.- Parameters:
urls- The updateOverrideURLs to set.
-
setModuleContextSecurityParams
Set the Module Context security parameters.- Parameters:
params- what to set.
-
setRebuildWar
public void setRebuildWar(boolean what) Set whether we rebuild the war.- Parameters:
what- - whether we will or not
-
isRebuildWar
public boolean isRebuildWar()Do we rebuild the war?- Returns:
- true if we are going to.
-
installPlugin
public void installPlugin(@Nonnull URL baseURL, @Nonnull @NotEmpty String fileName, boolean checkVersion) throws org.apache.tools.ant.BuildException Install 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.BuildException Install 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 theIdPPluginfor 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 absolute paths 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.
-
getModuleContext
Check for initialized and if so return themoduleContext.- Returns:
- the
moduleContext.
-
getPluginsWebapp
Check for initialized and if so return thepluginsWebapp.- Returns:
- the
moduleContext.
-
getDescription
Check for non null and then if so return thedescription.- Returns:
- the
description
-
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(@Nonnull Set<String> loadedModules) throws org.apache.tools.ant.BuildException Police 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
private void installNew(@Nonnull RollbackPluginInstall rollBack) throws org.apache.tools.ant.BuildException 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(@Nonnull RollbackPluginInstall rollback) throws org.apache.tools.ant.BuildException Uninstall the old version of the plugin.- Parameters:
rollback- Rollback Context- Throws:
org.apache.tools.ant.BuildException- on IO or module errors
-
saveCopiedFiles
private void saveCopiedFiles(@Nonnull List<Path> copiedFiles) throws org.apache.tools.ant.BuildException 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
-
inferInstalledIdpHome
Infer where the properties were installed to.- Parameters:
props- The property files- Returns:
- the idpHome it was installed to or null if no files installed
-
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
private void download(@Nonnull URL baseURL, @Nonnull String fileName) throws org.apache.tools.ant.BuildException 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.
-
captureChanges
Capture module changes.- Parameters:
changes- what has changed
-
emitModuleChanges
private void emitModuleChanges()Emit module changes. -
doReportOperation
private void doReportOperation(@Nonnull Module.ModuleResource resource, @Nonnull Module.ResourceResult result) Report on a resource result.- Parameters:
resource- resourceresult- result of operation
-
unpack
private void unpack(@Nonnull Path base, @Nonnull String fileName) throws org.apache.tools.ant.BuildException 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
@Nonnull private org.apache.commons.compress.archivers.ArchiveInputStream<?> getStreamFor(@Nonnull Path fullName, boolean isZip) throws IOException Create the correctArchiveInputStreamfor 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
private void checkSignature(@Nonnull Path base, @Nonnull String fileName) throws org.apache.tools.ant.BuildException 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:
doInitializein classAbstractInitializableComponent- Throws:
ComponentInitializationException
-
getInstalledPluginsLoader
@Nonnull private URLClassLoader getInstalledPluginsLoader() throws org.apache.tools.ant.BuildExceptionGenerate aURLClassLoaderwhich 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)- Returns:
- an appropriate loader
- Throws:
org.apache.tools.ant.BuildException- if a directory traversal fails.
-
getDistributionLoader
Generate aURLClassLoaderwhich 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 theIdPPluginwith the provided Id.- Parameters:
name- what to find- Returns:
- the
IdPPluginor null if not found.
-
closeSilently
close, ignoring errors.- Parameters:
what- what to close
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getIdPVersion
Return a version we can use in a test proof manner.- Returns:
- the IdP version or a fixed value
-