[xmlsectool] branch main updated: XSTJ-84 - Use DeprecationSupport for changing command line options
Ian Young
ian at iay.org.uk
Tue Oct 27 17:02:49 UTC 2020
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch main
in repository xmlsectool.
View the commit online:
http://git.shibboleth.net/view/?p=xmlsectool.git;a=commit;h=c70851b26f7adfef4fcf11617ecb75d5c6ad7d93
The following commit(s) were added to refs/heads/main by this push:
new c70851b XSTJ-84 - Use DeprecationSupport for changing command line options
c70851b is described below
commit c70851b26f7adfef4fcf11617ecb75d5c6ad7d93
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Tue Oct 27 17:02:45 2020 +0000
XSTJ-84 - Use DeprecationSupport for changing command line options
https://issues.shibboleth.net/jira/browse/XSTJ-84
---
pom.xml | 2 +-
.../tool/xmlsectool/CommandLineArguments.java | 58 +++++++++++++++++++---
.../tool/xmlsectool/CredentialHelper.java | 8 +--
.../net/shibboleth/tool/xmlsectool/XMLSecTool.java | 5 +-
.../net/shibboleth/tool/xmlsectool/XSTJ82Test.java | 3 +-
5 files changed, 57 insertions(+), 19 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4ac95a7..9ec05df 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<properties>
<opensaml.groupId>org.opensaml</opensaml.groupId>
<opensaml.version>4.0.1</opensaml.version>
- <java-support.version>8.0.0</java-support.version>
+ <java-support.version>8.1.0-SNAPSHOT</java-support.version>
</properties>
<repositories>
diff --git a/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java b/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java
index 897a01d..6b3fb3c 100644
--- a/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java
+++ b/src/main/java/net/shibboleth/tool/xmlsectool/CommandLineArguments.java
@@ -24,13 +24,13 @@ import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
+
/** Command line arguments for the {@link XMLSecTool} command line tool. */
public class CommandLineArguments {
- /*
- * Checkstyle: JavadocVariable OFF
- * Checkstyle: JavadocMethod OFF
- */
+ // Checkstyle: JavadocVariable OFF
/** Prefix for all command-line option names. Separated out to make it easer to replicate the old usage text. */
private static final String OPT = "--";
@@ -242,6 +242,21 @@ public class CommandLineArguments {
@Parameter(names = HELP_ARG, help = true)
private boolean help;
+ /**
+ * Parse the command-line arguments.
+ *
+ * <p>
+ * As well as basic parsing, this also:
+ * </p>
+ *
+ * <ul>
+ * <li>validates the options used: results in fatal errors if they are invalid</li>
+ * <li>applies some defaults</li>
+ * <li>processes the options related to the disallowed algorithm list</li>
+ * </ul>
+ *
+ * @param args array of command-line arguments to parse
+ */
public void parseCommandLineArguments(final String[] args) {
try {
final JCommander jc = new JCommander(this);
@@ -257,7 +272,27 @@ public class CommandLineArguments {
errorAndExit(e.getMessage());
}
}
-
+
+ /**
+ * Checks for any deprecations in the command-line options.
+ *
+ * <p>
+ * The logging system <strong>must</strong> have been set up
+ * before this is called.
+ * </p>
+ */
+ public void checkForDeprecations() {
+
+ // --keystoreProvider with --pkcs11Config deprecated in V3.0.0
+ if (getPkcs11Config() != null) {
+ if (getKeystoreProvider() != null) {
+ DeprecationSupport.warn(ObjectType.CLI_OPTION, OPT + KEYSTORE_PROVIDER_ARG,
+ "now ignored when used with " + OPT + PKCS11_CONFIG_ARG, null);
+ }
+ }
+
+ }
+
/**
* Handle options related to setting up the blacklist.
*
@@ -288,6 +323,9 @@ public class CommandLineArguments {
}
}
}
+
+ // Checkstyle: JavadocMethod OFF
+
public String getHttpProxy() {
return httpProxy;
@@ -474,6 +512,9 @@ public class CommandLineArguments {
return help;
}
+ // Checkstyle: MethodLength OFF
+ // Checkstyle: CyclomaticComplexity OFF
+
private void validateCommandLineArguments() {
if (doHelp()) {
return;
@@ -548,9 +589,12 @@ public class CommandLineArguments {
if (doVerboseOutput() && doQuietOutput()) {
errorAndExit("Verbose and quiet output are mutually exclusive");
}
-
}
+ // Checkstyle: MethodLength OFF
+ // Checkstyle: CyclomaticComplexity OFF
+ // Checkstyle: JavadocMethod ON
+
/**
* Print command line help instructions.
*
@@ -730,4 +774,4 @@ public class CommandLineArguments {
System.out.flush();
throw new Terminator(ReturnCode.RC_INIT);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/net/shibboleth/tool/xmlsectool/CredentialHelper.java b/src/main/java/net/shibboleth/tool/xmlsectool/CredentialHelper.java
index a228260..d93f42b 100644
--- a/src/main/java/net/shibboleth/tool/xmlsectool/CredentialHelper.java
+++ b/src/main/java/net/shibboleth/tool/xmlsectool/CredentialHelper.java
@@ -146,7 +146,6 @@ public final class CredentialHelper {
/**
* Reads in an X.509 credential from a PKCS11 source.
*
- * @param keystoreProvider keystore provider class (legacy: should now be <code>null</code>)
* @param pkcs11Config configuration file used by the PKCS#11 provider
* @param keyAlias private key keystore alias
* @param keyPassword private key password, may not be null
@@ -156,14 +155,9 @@ public final class CredentialHelper {
* @throws IOException if it is not possible to read the keystore
* @throws GeneralSecurityException if there is a problem loading the keystore, or loading the credential from it
*/
- protected static BasicX509Credential getPKCS11Credential(final String keystoreProvider, final String pkcs11Config,
+ protected static BasicX509Credential getPKCS11Credential(final String pkcs11Config,
final String keyAlias, final String keyPassword) throws IOException, GeneralSecurityException {
- // Warn about the legacy use of --keystoreProvider
- if (keystoreProvider != null) {
- LOG.warn("The --keystoreProvider option is now ignored when used with --pkcs11Config; remove it");
- }
-
dumpSecurityProviders("Acquiring PKCS11 keystore");
// Head off legacy use of --pkcs11Config DUMMY
diff --git a/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java b/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java
index 114a09f..0b13e82 100644
--- a/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java
+++ b/src/main/java/net/shibboleth/tool/xmlsectool/XMLSecTool.java
@@ -120,6 +120,7 @@ public final class XMLSecTool {
final CommandLineArguments cli = new CommandLineArguments();
cli.parseCommandLineArguments(args);
initLogging(cli);
+ cli.checkForDeprecations();
try {
InitializationSupport.initialize();
@@ -900,8 +901,8 @@ public final class XMLSecTool {
} else if (cli.getPkcs11Config() != null) {
try {
credential =
- CredentialHelper.getPKCS11Credential(cli.getKeystoreProvider(),
- cli.getPkcs11Config(), cli.getKey(), cli.getKeyPassword());
+ CredentialHelper.getPKCS11Credential(cli.getPkcs11Config(),
+ cli.getKey(), cli.getKeyPassword());
} catch (final IOException e) {
log.error("Error accessing PKCS11 store", e);
throw new Terminator(ReturnCode.RC_IO);
diff --git a/src/test/java/net/shibboleth/tool/xmlsectool/XSTJ82Test.java b/src/test/java/net/shibboleth/tool/xmlsectool/XSTJ82Test.java
index b76ce8b..02dac8a 100644
--- a/src/test/java/net/shibboleth/tool/xmlsectool/XSTJ82Test.java
+++ b/src/test/java/net/shibboleth/tool/xmlsectool/XSTJ82Test.java
@@ -46,7 +46,6 @@ public class XSTJ82Test extends BaseTest {
"--inFile", "in.xml",
"--outFile", "out.xml",
"--pkcs11Config", configFile.getAbsolutePath(),
- "--keystoreProvider", "dummy",
"--keyPassword", "1234",
"--key", "key2048",
};
@@ -55,7 +54,7 @@ public class XSTJ82Test extends BaseTest {
XMLSecTool.initLogging(cli);
// Deep unit test on the CredentialHelper's credential acquisition method
- var cred = CredentialHelper.getPKCS11Credential(cli.getKeystoreProvider(), cli.getPkcs11Config(),
+ var cred = CredentialHelper.getPKCS11Credential(cli.getPkcs11Config(),
cli.getKey(), cli.getKeyPassword());
Assert.assertNotNull(cred);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list