[java-identity-provider] 02/02: Plugin Installer improvements
Codeberg
noreply at shibboleth.net
Fri Nov 27 16:23:06 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
https://codeberg.org/Shibboleth/java-identity-provider/commit/2800a7c6126582c4f65ccfdccb4c79ef67e80b76
commit 2800a7c6126582c4f65ccfdccb4c79ef67e80b76
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Nov 16 20:03:15 2026 +0000
Plugin Installer improvements
---
.../idp/installer/plugin/impl/PluginInstaller.java | 119 ++++++++++++++++++---
.../installer/plugin/impl/PluginInstallerCLI.java | 8 +-
.../idp/installer/plugin/impl/PluginCLITest.java | 22 ++++
3 files changed, 129 insertions(+), 20 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
index 8d42a40c8..d235a54ed 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
@@ -177,6 +177,9 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
/** Do we rebuild? */
private boolean rebuildWar = true;
+ /** If not null we check that the plugin version is as expected. */
+ @Nonnull private InstallableComponentVersion checkAgainstVersion;
+
/**
* Constructor.
* @param client - the HttpClient to use
@@ -257,11 +260,28 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
* @param fileName the name
* @param checkVersion do we want to check vs the IdP Version?
* @throws BuildException if badness is detected.
+ * @deprecated use the version with derivedVersion
*/
public void installPlugin(@Nonnull final URL baseURL,
@Nonnull @NotEmpty final String fileName,
final boolean checkVersion) throws BuildException {
+ installPlugin(baseURL, fileName, checkVersion, null);
+ }
+
+ /** Install the plugin from the provided URL. Involves downloading
+ * the file and then doing a {@link #installPlugin(Path, String, boolean)}.
+ * @param baseURL where we get the files from
+ * @param fileName the name
+ * @param checkVersion do we want to check vs the IdP Version?
+ * @param derivedVersion if supplied check that the plugin identifies itself with this id
+ * @throws BuildException if badness is detected.
+ */
+ public void installPlugin(@Nonnull final URL baseURL,
+ @Nonnull @NotEmpty final String fileName,
+ final boolean checkVersion,
+ @Nullable final InstallableComponentVersion derivedVersion) throws BuildException {
download(baseURL, fileName);
+ checkAgainstVersion = derivedVersion;
assert downloadDirectory != null;
installPlugin(downloadDirectory, fileName, checkVersion);
}
@@ -287,9 +307,10 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
throw new BuildException("Could not find signature for distribution");
}
- unpack(base, fileName);
+ unpackBootstrap(base, fileName);
setupPluginId();
checkSignature(base, fileName);
+ unpack(base, fileName);
setupDescriptionFromDistribution();
//
// the above line guarantees a non null description
@@ -413,6 +434,17 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
LOG.debug("Found Service announcing itself as {}", plugin.getPluginId() );
if (pluginId.equals(plugin.getPluginId())) {
description = plugin;
+ if (checkAgainstVersion != null) {
+ final InstallableComponentVersion pluginVersion =
+ new InstallableComponentVersion(plugin.getMajorVersion(),
+ plugin.getMinorVersion(),
+ plugin.getPatchVersion());
+ if (!pluginVersion.equals(checkAgainstVersion)) {
+ LOG.error("Version mismatch inside downloaded plugin expected {}, got {}",
+ checkAgainstVersion, pluginVersion);
+ throw new BuildException("Corrupt distribution");
+ }
+ }
return;
}
LOG.trace("Did not match {}", pluginId);
@@ -619,7 +651,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
}
final Path fromPackage = distribution.resolve(pack.getSourceName());
assert fromPackage != null;
- unpack(to, fromPackage, isZip(pack.getSourceName()), pack.isStripTopLevelDir());
+ unpack(to, fromPackage, isZip(pack.getSourceName()), pack.isStripTopLevelDir(), false);
} catch (final IOException e) {
LOG.error("Unable to handle package : {} ", pack.getDestinationName(), e);
throw new BuildException(e);
@@ -866,25 +898,22 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
}
}
- /** Helper Method for unpacking the distribution.
+ /** Helper Method for unpacking the bootstrap part of the distribution.
* Populates {@link #unpackDirectory} and{@link #distribution}
* @param base Where the zip/tgz file is
* @param fileName the name.
* @throws BuildException if badness is detected.
*/
- private void unpack(@Nonnull final Path base, @Nonnull final String fileName) throws BuildException {
+ private void unpackBootstrap(@Nonnull final Path base, @Nonnull final String fileName) throws BuildException {
final Path fullName = base.resolve(fileName);
assert fullName!=null;
+ final boolean isZip = isZip(fileName);
Constraint.isNull(unpackDirectory, "cannot unpack multiple times");
try {
final Path upDir = unpackDirectory = Files.createTempDirectory("plugin-installer-unpack");
assert upDir != null;
- final boolean isZip = isZip(fileName);
- if (isZip) {
- DeprecationSupport.warnOnce(ObjectType.CLI_OPTION, "zip Plugin Distributions", null, "tar.gz distribution");
- }
- unpack(upDir, fullName, isZip, false);
+ unpack(upDir, fullName, isZip, false, false);
try (final DirectoryStream<Path> unpackDirStream = Files.newDirectoryStream(upDir)) {
final Iterator<Path> contents = unpackDirStream.iterator();
if (!contents.hasNext()) {
@@ -901,17 +930,42 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
}
} catch (final IOException e) {
throw new BuildException(e);
+ }
+ }
+
+ /** Helper Method for unpacking the distribution.
+ * Populates {@link #unpackDirectory} and{@link #distribution}
+ * @param base Where the zip/tgz file is
+ * @param fileName the name.
+ * @throws BuildException if badness is detected.
+ */
+ private void unpack(@Nonnull final Path base, @Nonnull final String fileName) throws BuildException {
+ final Path fullName = base.resolve(fileName);
+ assert fullName!=null;
+
+ final Path upDir = unpackDirectory;
+ assert upDir != null;
+ final boolean isZip = isZip(fileName);
+ if (isZip) {
+ DeprecationSupport.warnOnce(ObjectType.CLI_OPTION, "zip Plugin Distributions", null, "tar.gz distribution");
}
+ unpack(upDir, fullName, isZip, false, false);
}
-
+
/** Method to unpack a zip or tgz file into our {{@link #unpackDirectory}.
* @param unpackTo Where to unpack to
* @param fullName what to unzip
* @param isZip is this a zip file?
* @param stripFirst do we remove the first "directory" in the path (allows install in place)
+ * @param bootstrapOnly are we only interested in paths starting "bootstrap".
* @throws BuildException if badness is detected.
*/
- private static void unpack(@Nonnull final Path unpackTo, @Nonnull final Path fullName, final boolean isZip, boolean stripFirst) throws BuildException {
+ private static void unpack(@Nonnull final Path unpackTo,
+ @Nonnull final Path fullName,
+ final boolean isZip,
+ boolean stripFirst,
+ boolean bootstrapOnly
+ ) throws BuildException {
LOG.debug("Unpacking {} to {}", fullName, unpackTo);
try (final ArchiveInputStream<?> inStream = getStreamFor(fullName, isZip)) {
@@ -921,16 +975,42 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
LOG.warn("Could not read next entry from {}", inStream);
continue;
}
- Path fromPath = unpackTo;
+ final String entryName = entry.getName();
+ if (entryName.contains("..") ||
+ entryName.startsWith("/") ||
+ entryName.contains(":") || // Windows
+ entryName.contains("\\") || // Windows
+ entryName.contains("%")) {
+ LOG.error("Archive included a invalid path : {}", entryName);
+ throw new BuildException("Corrupt installation package");
+ }
+ boolean isAbsolute;
+ try {
+ isAbsolute = Path.of(entry.getName()).isAbsolute();
+ } catch (Throwable e) {
+ LOG.error("Archive included a invalid path : {}", entryName);
+ throw new BuildException("Corrupt installation package", e);
+ }
+ if (isAbsolute) {
+ LOG.error("Archive included a invalid path : {}", entryName);
+ throw new BuildException("Corrupt installation package");
+ }
+ Path fromPath;
+ final boolean inBootstrap = (entryName.startsWith("bootstrap") && entry.isDirectory()) ||
+ entryName.equals("bootstrap/keys.txt") ||
+ entryName.equals("bootstrap/plugin.properties");
+ if (bootstrapOnly & !inBootstrap) {
+ continue;
+ }
if (stripFirst) {
- final String names[] = entry.getName().split("/");
+ fromPath = unpackTo;
+ final String names[] = entryName.split("/");
for (int i = 1; i < names.length; i++) {
fromPath = fromPath.resolve(names[i]);
}
- } else {
- fromPath = fromPath.resolve(entry.getName());
}
- final File output = unpackTo.resolve(fromPath).toFile();
+ fromPath = entry.resolveIn(unpackTo);
+ final File output = fromPath.toFile();
LOG.trace("Unpacking {} to {}", entry.getName(), output);
if (entry.isDirectory()) {
if (!output.isDirectory() && !output.mkdirs()) {
@@ -938,6 +1018,11 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
throw new BuildException("failed to create unpacked directory");
}
} else {
+ if (output.exists()) {
+ if (bootstrapOnly || !inBootstrap) {
+ LOG.warn("Plugin Installer overwrote {}", output);
+ }
+ }
final File parent = output.getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
LOG.error("Failed to create parent directory {}", parent);
@@ -1234,4 +1319,4 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
return new InstallableComponentVersion(version);
}
-}
\ No newline at end of file
+}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java
index 744a2aef2..fddd45405 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java
@@ -177,7 +177,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
assert pluginId != null;
return autoPluginFromId(pluginId, !args.isNoCheck());
}
- inst.installPlugin(args.getInputURL(), args.getInputFileName(), !args.isNoCheck());
+ inst.installPlugin(args.getInputURL(), args.getInputFileName(), !args.isNoCheck(), null);
doList = true;
break;
@@ -540,7 +540,8 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
assert updateURL != null;
inst.installPlugin(updateURL,
info.getUpdateBaseName(versionToInstall) + ".tar.gz",
- checkVersion);
+ checkVersion,
+ versionToInstall);
return RC_OK;
}
@@ -616,7 +617,8 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
assert updateURL != null;
inst.installPlugin(updateURL,
state.getPluginInfo().getUpdateBaseName(installVersion) + ".tar.gz",
- checkVersion);
+ checkVersion,
+ installVersion);
return true;
}
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginCLITest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginCLITest.java
index 9c56f700f..2bdb9b168 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginCLITest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginCLITest.java
@@ -15,15 +15,19 @@
package net.shibboleth.idp.installer.plugin.impl;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.fail;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.hc.client5.http.classic.HttpClient;
+import org.apache.tools.ant.BuildException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.testng.annotations.BeforeSuite;
@@ -31,8 +35,10 @@ import org.testng.annotations.Test;
import net.shibboleth.idp.installer.InstallerSupport;
import net.shibboleth.idp.installer.ProgressReportingOutputStream;
+import net.shibboleth.profile.installablecomponent.InstallableComponentVersion;
import net.shibboleth.shared.cli.AbstractCommandLine;
import net.shibboleth.shared.httpclient.HttpClientBuilder;
+import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.spring.httpclient.resource.HTTPResource;
@SuppressWarnings("javadoc")
@@ -118,6 +124,22 @@ public class PluginCLITest extends BasePluginTest {
AbstractCommandLine.RC_OK);
}
+ @Test(enabled = RunInstallTests, dependsOnMethods = {"testWeb"})
+ public void testWrongVersion() throws Exception {
+ final HttpClient client = new HttpClientBuilder().buildClient();
+ try (PluginInstaller installer = new PluginInstaller(client)){
+ installer.setIdpHome(getIdpHome());
+ installer.initialize();
+ installer.installPlugin(new URL("http://shibboleth.net/downloads/identity-provider/plugins/oidc-common/3.1.0/oidc-common-dist-3.1.0.tar.gz"),
+ "oidc-common-dist-3.1.0.tar.gz",
+ false,
+ new InstallableComponentVersion("4.1.0"));
+ fail("test should have thrown an exception");
+ } catch (final BuildException e) {
+ assertEquals(e.getMessage(), "Corrupt distribution");
+ }
+ }
+
@Test(enabled = RunInstallTests, dependsOnMethods = {"testForceUpdate"})
public void testListContents() {
assertEquals(PluginInstallerCLI.runMain(new String[] {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list