[java-idp-plugin-jetty] 174/186: JJETTY-13 Implement Jetty-base plugin V2
Rod Widdowson
rdw at steadingsoftware.com
Thu Jul 24 15:58:45 UTC 2025
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch dev/foo
in repository java-idp-plugin-jetty.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-jetty.git;a=commit;h=b952f273b3d282980b03db0134c8d4a396468c87
commit b952f273b3d282980b03db0134c8d4a396468c87
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Jul 14 15:48:34 2025 +0100
JJETTY-13 Implement Jetty-base plugin V2
https://shibboleth.atlassian.net/browse/JJETTY-13
Flesh out together the download bit of the jetty command
---
jetty-cli/pom.xml | 17 ++-
.../jetty/cli/impl/JettyDownloadArguments.java | 18 +--
.../plugin/jetty/cli/impl/JettyDownloadCLI.java | 141 +++++++++++++--------
3 files changed, 112 insertions(+), 64 deletions(-)
diff --git a/jetty-cli/pom.xml b/jetty-cli/pom.xml
index 8fd4ccc..e6445da 100644
--- a/jetty-cli/pom.xml
+++ b/jetty-cli/pom.xml
@@ -31,6 +31,12 @@
<version>${idp.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>${idp.groupId}</groupId>
+ <artifactId>idp-conf-impl</artifactId>
+ <version>${idp.version}</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>${idp.groupId}</groupId>
<artifactId>idp-installer</artifactId>
@@ -42,6 +48,16 @@
<artifactId>shib-cli</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>${shib-shared.groupId}</groupId>
+ <artifactId>shib-networking</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${shib-shared.groupId}</groupId>
+ <artifactId>shib-networking-spring</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>${slf4j.groupId}</groupId>
<artifactId>slf4j-api</artifactId>
@@ -67,7 +83,6 @@
<scope>test</scope>
</dependency>
-
</dependencies>
<build>
diff --git a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java
index 955a931..eea348a 100644
--- a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java
+++ b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java
@@ -60,10 +60,10 @@ public class JettyDownloadArguments extends AbstractIdPHomeAwareCommandLineArgum
@Parameter(names= {"--keystore"})
@Nonnull private String keystore="credentials/jetty-base-download-keystore.gpg";
- /** The FQP of the download base artifact.
+ /** The BaseURL of the download base artifact.
* If not set, the command line initializes this from the maven coordinates. */
- @Parameter(names= {"-fqp"})
- @Nonnull private String fqp;
+ @Parameter(names= {"--baseURL"})
+ @Nonnull private String baseURL;
/** Whether to download the signature file. */
@Parameter(names= {"--noascfile"})
@@ -162,19 +162,19 @@ public class JettyDownloadArguments extends AbstractIdPHomeAwareCommandLineArgum
}
/**
- * Set the fully qualified path we are to download path.
+ * Set the BaseURL we are to download from.
* @param what the path
*/
- public void setFqp(@Nonnull String what) {
- fqp = Constraint.isNotNull(what, "injected FPQ must be non null");
+ public void setBaseUrl(@Nonnull String what) {
+ baseURL = Constraint.isNotNull(what, "injected FPQ must be non null");
}
/**
- * What is the fully qualified path we are to download path?
+ * What is the base URL we are to download from? (the artifact name and appropriate garnish is added)
* @return the path
*/
- @Nullable public String getFqp() {
- return fqp;
+ @Nullable public String getBaseURL() {
+ return baseURL;
}
/** get keystore location (relative to idp home).
diff --git a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java
index e23ea6b..80ca450 100644
--- a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java
+++ b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java
@@ -16,22 +16,31 @@ package net.shibboleth.idp.plugin.jetty.cli.impl;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.opensaml.security.httpclient.HttpClientSecurityContextHandler;
+import org.opensaml.security.httpclient.HttpClientSecurityParameters;
import org.slf4j.Logger;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
import net.shibboleth.idp.Version;
import net.shibboleth.idp.cli.AbstractIdPHomeAwareCommandLine;
+import net.shibboleth.idp.installer.InstallerSupport;
import net.shibboleth.shared.cli.AbstractCommandLine;
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.spring.httpclient.resource.HTTPResource;
public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownloadArguments> {
/** Logger. */
- @Nullable private Logger log;
+ @Nullable private final Logger log = LoggerFactory.getLogger(JettyDownloadCLI.class);
/** the keystore (if provided). */
@Nullable private Path keyStore;
@@ -45,6 +54,9 @@ public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownl
/** The directory we will unpack to (including type). */
private String downloadDirName;
+ /** The securityParams for the module context. */
+ @Nullable private HttpClientSecurityParameters securityParams;
+
/** {@inheritDoc} */
@Override
protected Class<JettyDownloadArguments> getArgumentClass() {
@@ -61,80 +73,91 @@ public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownl
/** {@inheritDoc} */
@Override
protected Logger getLogger() {
- Logger localLog = log;
- if (localLog == null) {
- localLog = log = LoggerFactory.getLogger(JettyDownloadCLI.class);
- }
- return localLog;
+ return log;
}
- /** if no name was specified then plug the maven coordinates together
- * @param args
- */
- @Nonnull private String deriveNameFromCoordinates(@Nonnull final JettyDownloadArguments args) {
- //
- // Root of request
- // https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/12.0.23/jetty-home-12.0.23
- // https://repo1.maven.org/maven2/commons-daemon/commons-daemon/1.4.1/commons-daemon-1.4.1
- //
- final StringBuilder sb = new StringBuilder(args.getMavenbase())
- .append('/')
- .append(args.getGroupId().replaceAll("\\.", "/"))
- .append('/')
- .append(args.getArtifactId())
- .append('/')
- .append(args.getVersion())
- .append('/')
- .append(args.getArtifactId())
- .append('-')
- .append(args.getVersion());
-
- final String classifier = args.getClassifier();
- if (classifier != null) {
- //
- // Add classifier
- // https://repo1.maven.org/maven2/commons-daemon/commons-daemon/1.4.1/commons-daemon-1.4.1-bin-windows
- //
- sb.append(args.getClassifier());
- }
- //
- // Add type
- // https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/12.0.23/jetty-home-12.0.23.tar.gz
- // https://repo1.maven.org/maven2/commons-daemon/commons-daemon/1.4.1/commons-daemon-1.4.1-bin-windows.zip
- //
- sb.append('.').append(args.getType());
- return sb.toString();
- }
+ /** {@inheritDoc} */
+ @Nonnull protected List<Resource> getAdditionalSpringResources() {
+ return CollectionSupport.singletonList(
+ new ClassPathResource("net/shibboleth/idp/conf/http-client.xml"));
+ }
@Override
protected int doRun(@Nonnull final JettyDownloadArguments args) {
- super.doRun(args);
+ if (args.getHttpClientName() == null) {
+ args.setHttpClientName("shibboleth.InternalHttpClient");
+ }
+
+ super.doRun(args);
+
- if (args.getFqp() == null) {
+ if (args.getBaseURL() == null) {
//
// Calculate the address
//
if (args.getVersion() == null) {
- getLogger().error("No version and no FQP supplied");
+ log.error("No version and no FQP supplied");
return RC_IO;
}
- args.setFqp(deriveNameFromCoordinates(args));
+ //
+ // Root of request
+ // https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/12.0.23/jetty-home-12.0.23/
+ // https://repo1.maven.org/maven2/commons-daemon/commons-daemon/1.4.1/commons-daemon-1.4.1/
+ //
+ final StringBuilder fqpBuilder = new StringBuilder(args.getMavenbase())
+ .append('/')
+ .append(args.getGroupId().replaceAll("\\.", "/"))
+ .append('/')
+ .append(args.getArtifactId())
+ .append('/')
+ .append(args.getVersion())
+ .append('/');
+
+ args.setBaseUrl(fqpBuilder.toString());
}
+ //
+ // jetty-home
+ // commons-daemon
+ //
downloadDirName = args.getArtifactId();
if (args.getVersion() != null) {
+ //
+ // jetty-home-12.0.23
+ // commons-daemon-1.4.1
+ //
downloadDirName += "-" + args.getVersion();
}
- downloadFileName = downloadDirName + "." + args.getType();
+ final StringBuilder nameBuilder = new StringBuilder(downloadDirName);
+ final String classifier = args.getClassifier();
+ if (classifier != null) {
+ //
+ // Add classifier
+ // commons-daemon-1.4.1-bin-windows
+ //
+ nameBuilder.append(args.getClassifier());
+ }
+
+ //
+ // And type
+ //
+ // jetty-home-12.0.23.tar.gz
+ // commons-daemon-1.4.1-bin-windows.zip
+ //
+ downloadFileName = nameBuilder
+ .append('.')
+ .append(args.getType())
+ .toString();
+
final String pathString = Constraint.isNotNull(
getApplicationContext().getEnvironment().getProperty("idp.home"), "idp home must be specified");
final Path idpHome;
try {
idpHome = Path.of(pathString);
} catch (final Exception ex) {
- getLogger().error("Could not find idp home at {}", pathString, ex);
+ log.error("Could not find idp home at {}", pathString, ex);
return RC_IO;
}
@@ -143,7 +166,7 @@ public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownl
keyStore = idpHome.resolve(args.getKeystore());
if (Files.exists(keyStore)) {
- getLogger().error("keystore file {} does not exist", keyStore);
+ log.error("keystore file {} does not exist", keyStore);
return RC_IO;
}
}
@@ -157,7 +180,7 @@ public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownl
try {
Files.createDirectory(downloadsDir);
} catch (final IOException e) {
- getLogger().error("Could not create {}", downloadsDir, e);
+ log.error("Could not create {}", downloadsDir, e);
return RC_IO;
}
}
@@ -182,9 +205,19 @@ public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownl
* @return an RC result
*/
private int download(JettyDownloadArguments args) {
- getLogger().info("Would download {} to {}", args.getFqp(), downloadFileName);
- if (!args.isNoAscFile()) {
- getLogger().info("Would download {}.asc to {}.asc", args.getFqp(), downloadFileName);
+ try {
+ final HTTPResource baseResource = new HTTPResource(getHttpClient(), args.getBaseURL());
+ final HttpClientSecurityContextHandler handler = new HttpClientSecurityContextHandler();
+ handler.setHttpClientSecurityParameters(getHttpClientSecurityParameters());
+ handler.initialize();
+ baseResource.setHttpClientContextHandler(handler);
+ InstallerSupport.download(baseResource, handler, downloadsDir, downloadFileName);
+ if (!args.isNoAscFile()) {
+ InstallerSupport.download(baseResource, handler, downloadsDir, downloadFileName + ".asc");
+ }
+ } catch (final IOException | ComponentInitializationException e) {
+ log.error("Download failed", e);
+ return RC_IO;
}
return RC_OK;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list