[java-identity-provider] branch main updated: https://shibboleth.atlassian.net/browse/IDP-2342 Path.of() throws an InvalidPathException which is not always caught.
Rod Widdowson
rdw at steadingsoftware.com
Sat Nov 2 16:24:46 UTC 2024
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=61f378dadfd60c7580e10abdb336d3ef8f666db4
The following commit(s) were added to refs/heads/main by this push:
new 61f378dad https://shibboleth.atlassian.net/browse/IDP-2342 Path.of() throws an InvalidPathException which is not always caught.
61f378dad is described below
commit 61f378dadfd60c7580e10abdb336d3ef8f666db4
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Nov 2 16:21:46 2024 +0000
https://shibboleth.atlassian.net/browse/IDP-2342 Path.of() throws an InvalidPathException which is not always caught.
https://shibboleth.atlassian.net/browse/IDP-2342
Introduce a helper class to catch the Exception and rethrow as a BuildException
(whuich is a run time exception and hence always caught)
---
.../net/shibboleth/idp/installer/InstallerSupport.java | 15 +++++++++++++++
.../shibboleth/idp/installer/impl/FinalizeJettyBase.java | 2 +-
.../net/shibboleth/idp/installer/impl/IdPBuildWar.java | 8 +++++---
.../shibboleth/idp/installer/impl/IdPInstallerCLI.java | 4 +++-
.../idp/installer/impl/InstallerPropertiesImpl.java | 4 ++--
.../shibboleth/idp/installer/impl/UpdateIdPArguments.java | 13 ++++++++-----
.../net/shibboleth/idp/installer/impl/UpdateIdPCLI.java | 3 ++-
.../idp/installer/plugin/impl/PluginInstaller.java | 5 +++--
.../installer/plugin/impl/PluginInstallerArguments.java | 5 ++++-
.../idp/installer/plugin/impl/PluginInstallerCLI.java | 3 ++-
.../shibboleth/idp/installer/plugin/impl/TrustStore.java | 5 +++--
11 files changed, 48 insertions(+), 19 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
index 537def056..be068d794 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
@@ -529,6 +529,21 @@ public final class InstallerSupport {
}
// CheckStyle: CyclomaticComplexity ON
+ /** A version of {@link Path#of(String, String...)} that throw a catchable exception.
+ * @param pathString the path as a string
+ * @return the Path
+ * @throws BuildException if {@link Path#of(String, String...)} threw an exception.
+ */
+ @Nonnull public static final Path pathOf(@Nonnull String pathString) throws BuildException {
+ try {
+ final Path result = Path.of(pathString);
+ assert result != null;
+ return result;
+ }
+ catch (final Exception e) {
+ throw new BuildException(e);
+ }
+ }
/**
* A @{link {@link FileVisitor} which detects (and logs) whether a copy would overwrite.
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/FinalizeJettyBase.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/FinalizeJettyBase.java
index fcfafeff0..5147cd4f2 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/FinalizeJettyBase.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/FinalizeJettyBase.java
@@ -49,7 +49,7 @@ import net.shibboleth.idp.installer.PropertiesWithComments;
System.err.println("idp.home not specified");
throw new IOException("idp.home not specified");
}
- Path p = Path.of(home);
+ Path p = InstallerSupport.pathOf(home);
assert p!=null;
idpHome = p;
if (!Files.exists(idpHome) || !Files.isDirectory(idpHome)) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPBuildWar.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPBuildWar.java
index 8cb69ac17..eeb147522 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPBuildWar.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPBuildWar.java
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
import org.slf4j.Logger;
import net.shibboleth.idp.Version;
+import net.shibboleth.idp.installer.InstallerSupport;
import net.shibboleth.shared.cli.AbstractCommandLine;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -66,13 +67,14 @@ public class IdPBuildWar extends AbstractCommandLine<IdPBuildArguments> {
getLogger().debug("{}", args);
getLogger().info("{}", args);
- if (args.getIdPHome() == null) {
+ final String idpHomeString = args.getIdPHome();
+
+ if (idpHomeString == null) {
getLogger().error("--home must be specified");
return RC_INIT;
}
- final Path idpHome = Path.of(args.getIdPHome());
- assert idpHome!=null;
+ final Path idpHome = InstallerSupport.pathOf(idpHomeString);
if (!Files.exists(idpHome)) {
getLogger().error("Could not find {}", idpHome);
return RC_INIT;
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPInstallerCLI.java
index 56ce22ea3..717e7807f 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPInstallerCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/IdPInstallerCLI.java
@@ -31,9 +31,11 @@ import org.springframework.core.io.Resource;
import net.shibboleth.idp.Version;
import net.shibboleth.idp.installer.InstallerProperties;
+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;
/**
@@ -80,7 +82,7 @@ public class IdPInstallerCLI extends AbstractCommandLine<IdPInstallerArguments>
super.doRun(args);
- final Path source = Path.of(args.getSourceDir());
+ final Path source = InstallerSupport.pathOf(Constraint.isNotNull(args.getSourceDir(), "Source dir mist be specified"));
assert source!=null;
if (!Files.exists(source)) {
getLogger().error("Could not find {}", source);
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
index ae1485d43..631df5ca2 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerPropertiesImpl.java
@@ -269,7 +269,7 @@ public class InstallerPropertiesImpl {
return targetDir;
}
final Path td = targetDir =
- Path.of(getValue(InstallerProperties.TARGET_DIR, "Installation Directory:", () -> "/opt/shibboleth-idp"));
+ InstallerSupport.pathOf(getValue(InstallerProperties.TARGET_DIR, "Installation Directory:", () -> "/opt/shibboleth-idp"));
assert td != null;
return td;
}
@@ -524,7 +524,7 @@ public class InstallerPropertiesImpl {
if (propValue == null) {
return null;
}
- Path path = Path.of(propValue);
+ Path path = InstallerSupport.pathOf(propValue);
if (Files.exists(path)) {
log.debug("Property '{}' had value '{}' Path exists ", propName, propValue);
} else {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPArguments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPArguments.java
index b52164921..43015ae42 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPArguments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPArguments.java
@@ -28,6 +28,7 @@ import com.beust.jcommander.Parameter;
import net.shibboleth.idp.Version;
import net.shibboleth.idp.cli.AbstractIdPHomeAwareCommandLineArguments;
+import net.shibboleth.idp.installer.InstallerSupport;
import net.shibboleth.profile.installablecomponent.InstallableComponentVersion;
import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.collection.CollectionSupport;
@@ -201,21 +202,23 @@ public class UpdateIdPArguments extends AbstractIdPHomeAwareCommandLineArguments
throw new IllegalArgumentException("Error in version specifier", e);
}
+ final String localDownloadDir = downloadDir;
+
if (list) {
operation = OperationType.LIST;
- if (downloadDir != null) {
+ if (localDownloadDir != null) {
getLog().error("Cannot List and Dowload in the same operation.");
throw new IllegalArgumentException("Cannot List and Download in the same operation.");
}
- } else if (downloadDir != null) {
+ } else if (localDownloadDir != null) {
operation = OperationType.DOWLOAD;
- downloadDirPath = Path.of(downloadDir);
+ downloadDirPath = InstallerSupport.pathOf(localDownloadDir);
if (!Files.exists(downloadDirPath)) {
- getLog().error("Download directory {}, does not exist", downloadDir);
+ getLog().error("Download directory {}, does not exist", localDownloadDir);
throw new IllegalArgumentException("Download directory does not exist");
}
if (!Files.isDirectory(downloadDirPath)) {
- getLog().error("Download location {}, exists, but is not a directory", downloadDir);
+ getLog().error("Download location {}, exists, but is not a directory", localDownloadDir);
throw new IllegalArgumentException("Download locaition is not a directory");
}
} else {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPCLI.java
index e3f9a6017..b5910a339 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/UpdateIdPCLI.java
@@ -53,6 +53,7 @@ import net.shibboleth.profile.installablecomponent.InstallableComponentSupport.S
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;
@@ -290,7 +291,7 @@ public class UpdateIdPCLI extends AbstractIdPHomeAwareCommandLine<UpdateIdPArgum
try (final InputStream sigStream = new BufferedInputStream(
new FileInputStream(args.getDownloadLocation().resolve(fileName + ".asc").toFile()))) {
final TrustStore trust = new TrustStore();
- final Path idpHome = Path.of(args.getIdPHome());
+ final Path idpHome = InstallerSupport.pathOf(Constraint.isNotNull(args.getIdPHome(), "idp home must be specified"));
assert idpHome != null;
trust.setIdpHome(idpHome);
trust.setTrustStore(args.getTruststore());
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 1ee1a9cd6..edad1b38d 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
@@ -723,7 +723,8 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
} else {
LOG.info("Inferred initial install to {}", s);
}
- return Path.of(s);
+ assert s != null;
+ return InstallerSupport.pathOf(s);
}
val = props.getProperty(PLUGIN_FILE_PROPERTY_PREFIX+Integer.toString(count++));
}
@@ -765,7 +766,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
int count = 1;
String val = props.getProperty(PLUGIN_FILE_PROPERTY_PREFIX+Integer.toString(count++));
while (val != null) {
- final Path valAsPath = Path.of(val);
+ final Path valAsPath = InstallerSupport.pathOf(val);
if (relativePaths || installedIdPHome == null) {
result.add(getIdpHome().resolve(valAsPath));
} else {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java
index 8f0d77edd..9715e9c47 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
import com.beust.jcommander.Parameter;
import net.shibboleth.idp.cli.AbstractIdPHomeAwareCommandLineArguments;
+import net.shibboleth.idp.installer.InstallerSupport;
import net.shibboleth.profile.installablecomponent.InstallableComponentVersion;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -356,7 +357,9 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
getLog().error("File {} does not exist", inputAsFile.getAbsolutePath());
throw new IllegalArgumentException("Input File does not exist");
}
- final Path inputAsPath = Path.of(inputAsFile.getAbsolutePath());
+ final String inputAsFileString = inputAsFile.getAbsolutePath();
+ assert inputAsFileString != null;
+ final Path inputAsPath = InstallerSupport.pathOf(inputAsFileString);
inputDirectory = inputAsPath.getParent();
inputName = inputAsPath.getFileName().toString();
getLog().trace("Found File: {}\t{}", inputDirectory, inputName);
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 a0b8984c6..95fd45671 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
@@ -242,7 +242,8 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
*/
private void constructPluginInstaller(final PluginInstaller inst,
final PluginInstallerArguments args) throws ComponentInitializationException {
- final Path idpHome = Path.of(getApplicationContext().getEnvironment().getProperty("idp.home"));
+ final Path idpHome = InstallerSupport.pathOf(Constraint.isNotNull(
+ getApplicationContext().getEnvironment().getProperty("idp.home"), "idp home must be specified"));
assert idpHome != null;
inst.setIdpHome(idpHome);
if (!args.isUnattended()) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
index e854c7f5c..516289b96 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
@@ -43,6 +43,7 @@ import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProv
import org.bouncycastle.util.encoders.Hex;
import org.slf4j.Logger;
+import net.shibboleth.idp.installer.InstallerSupport;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.AbstractInitializableComponent;
@@ -296,12 +297,12 @@ import net.shibboleth.shared.primitive.LoggerFactory;
}
if (explicitTrustStore != null) {
- store = Path.of(explicitTrustStore);
+ store = InstallerSupport.pathOf(explicitTrustStore);
if (!Files.exists(store)) {
log.error("Trust store {} does not exist", explicitTrustStore);
throw new ComponentInitializationException("Supplied trust store does not exist.");
}
- backup = Path.of(explicitTrustStore + ".backup");
+ backup = InstallerSupport.pathOf(explicitTrustStore + ".backup");
log.debug("Plugin {}: Loading explicit truststore {}", pluginId, explicitTrustStore);
try {
loadStore();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list