[java-identity-provider] 04/04: IDP-1595 Plugins. Add license information to the API
Rod Widdowson
rdw at steadingsoftware.com
Sun Oct 4 13:51:51 UTC 2020
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=25486f2d54088f03b820318f360854963b86df4a
commit 25486f2d54088f03b820318f360854963b86df4a
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Oct 4 14:50:44 2020 +0100
IDP-1595 Plugins. Add license information to the API
https://issues.shibboleth.net/jira/browse/IDP-1595
This cna be driven from the property file and is emitted
from the command line.
---
.../shibboleth/idp/plugin/AbstractIdPPlugin.java | 7 ++-
.../java/net/shibboleth/idp/plugin/IdPPlugin.java | 7 +++
.../idp/plugin/PropertyDrivenIdPPlugin.java | 9 ++++
.../plugin/impl/PluginInstallerArguments.java | 9 ++++
.../installer/plugin/impl/PluginInstallerCLI.java | 61 ++++++++++++++++++++--
.../idp/installer/plugin/impl/PluginCLITest.java | 4 ++
.../idp/installer/plugin/impl/TestPlugin.java | 6 ++-
.../net/shibboleth/idp/plugin/test.license | 1 +
8 files changed, 97 insertions(+), 7 deletions(-)
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/AbstractIdPPlugin.java b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/AbstractIdPPlugin.java
index 8c2eea9b7..a4325e8bc 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/AbstractIdPPlugin.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/AbstractIdPPlugin.java
@@ -65,7 +65,12 @@ public abstract class AbstractIdPPlugin implements IdPPlugin {
@Nonnull @NonnullElements public Set<IdPModule> getEnableOnInstall() {
return enableModules;
}
-
+
+ /** {@inheritDoc} */
+ public String getLicenseFileLocation() {
+ return null;
+ }
+
/**
* Set the modules to enable on install.
*
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/IdPPlugin.java b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/IdPPlugin.java
index bd1d23210..589ea2277 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/IdPPlugin.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/IdPPlugin.java
@@ -24,6 +24,7 @@ import java.util.Set;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import net.shibboleth.idp.module.IdPModule;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
@@ -76,6 +77,12 @@ public interface IdPPlugin {
*/
@Nonnegative int getPatchVersion();
+ /** Return the classpath location of the license file to emit
+ * when --license is specified.
+ * @return the location
+ */
+ @Nullable String getLicenseFileLocation();
+
/**
* Get the IDs of any {@link IdPModule}s required for installation of this plugin.
*
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java
index 46797f6a4..58b56b45b 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PropertyDrivenIdPPlugin.java
@@ -56,6 +56,9 @@ public abstract class PropertyDrivenIdPPlugin extends AbstractIdPPlugin {
/** Property for plugin version. */
@Nonnull @NotEmpty public static final String PLUGIN_VERSION_PROPERTY = "plugin.version";
+ /** Property for plugin license. */
+ @Nonnull @NotEmpty public static final String PLUGIN_LICENSE_PROPERTY = "plugin.license";
+
/** Prefix of property for plugin update URL. */
@Nonnull @NotEmpty public static final String PLUGIN_URL_PROPERTY = "plugin.url.";
@@ -185,6 +188,12 @@ public abstract class PropertyDrivenIdPPlugin extends AbstractIdPPlugin {
return requiredModules;
}
+ /** {@inheritDoc} */
+ @Override
+ @Nullable public String getLicenseFileLocation() {
+ return pluginProperties.getProperty(PLUGIN_LICENSE_PROPERTY);
+ }
+
/** {@inheritDoc} */
@NonNegative public int getMajorVersion() {
return pluginVersion.getMajor();
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 2cfb6e8fc..407637098 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
@@ -59,6 +59,10 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
@Parameter(names= {"-fl", "--full-list"})
@Nullable private boolean fullList;
+ /** List License. */
+ @Parameter(names= {"--license"})
+ @Nullable private String license;
+
/** What to install. */
@Parameter(names= {"-i", "--input"})
@Nullable private String input;
@@ -103,6 +107,8 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
INSTALLREMOTE,
/** Remove jars from dist - web-ing. */
REMOVEJARS,
+ /** Print the license file to System.out. */
+ OUTPUTLICENSE,
/** Unknown. */
UNKNOWN
};
@@ -251,6 +257,9 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
} else if (removeId != null) {
pluginId = removeId;
operation = OperationType.REMOVEJARS;
+ } else if (license != null) {
+ pluginId = license;
+ operation = OperationType.OUTPUTLICENSE;
} else {
getLog().error("Missing qualifier. Options are : -l, -fl, -i, -u");
throw new IllegalArgumentException("Missing qualifier");
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 8b075f549..7b4462919 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
@@ -17,6 +17,9 @@
package net.shibboleth.idp.installer.plugin.impl;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.nio.file.Path;
import java.security.Security;
import java.util.ArrayList;
@@ -140,6 +143,10 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
installer.removeJars();
break;
+ case OUTPUTLICENSE:
+ outputLicense(args.getPluginId());
+ break;
+
default:
getLogger().error("Invalid operation");
return RC_INIT;
@@ -176,6 +183,17 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
installer = inst;
}
+ /** Emit the line to System.out or the log if not present.
+ * @param message what to emit.
+ */
+ private void outOrLog(final String message) {
+ if (System.out != null) {
+ System.out.println(message);
+ } else {
+ log.info("{}", message);
+ }
+ }
+
/** Print our more information about a plugin.
* Helper method for {@link #doList(boolean, String)}
* @param plugin what we are interested in.
@@ -193,7 +211,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
return;
}
final Map<PluginVersion, VersionInfo> versions = state.getAvailableVersions();
- System.out.println("\tVersions ");
+ outOrLog("\tVersions ");
for (final Entry<PluginVersion, VersionInfo> entry : versions.entrySet()) {
final String downLoadDetails;
if (state.getUpdateBaseName(entry.getKey()) == null || state.getUpdateURL(entry.getKey())==null ) {
@@ -201,7 +219,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
} else {
downLoadDetails = "";
}
- System.out.println(String.format("\t%s:\tMin=%s\tMax=%s\tSupport level: %s%s",
+ outOrLog(String.format("\t%s:\tMin=%s\tMax=%s\tSupport level: %s%s",
entry.getKey(),
entry.getValue().getMinSupported(),
entry.getValue().getMaxSupported(),
@@ -210,6 +228,39 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
}
}
+ /** Print the license file for the specified plugin.
+ * @param pluginId what to list
+ */
+ private void outputLicense(@Nonnull final String pluginId) {
+ final List<IdPPlugin> plugins = installer.getInstalledPlugins();
+ for (final IdPPlugin plugin: plugins) {
+ if (pluginId.equals(plugin.getPluginId())) {
+ final String location = plugin.getLicenseFileLocation();
+ if (location == null) {
+ log.error("Plugin {} has no license", pluginId);
+ return;
+ }
+ final Resource loc = new ClassPathResource(location);
+ if (!loc.exists()) {
+ log.error("Plugin {} license could not be found at {}", pluginId, location);
+ return;
+ }
+ outOrLog(String.format("License for %s", plugin));
+ try (final BufferedReader reader = new BufferedReader(new InputStreamReader(loc.getInputStream()))) {
+ String line = reader.readLine();
+ while (line != null) {
+ outOrLog(line);
+ line = reader.readLine();
+ }
+ } catch (final IOException e) {
+ log.error("Failed to output license", e);
+ }
+ return;
+ }
+ }
+ log.error("Plugin {} not installed", pluginId);
+ }
+
/** List all installed plugins (or just one if provided).
* @param fullList whether to do full deatils
* @param pluginId the pluginId or null.
@@ -220,7 +271,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
for (final IdPPlugin plugin: plugins) {
if (pluginId == null || pluginId.equals(plugin.getPluginId())) {
list = true;
- System.out.println(String.format("Plugin: %-22s\tCurrent Version: %d.%d.%d",
+ outOrLog(String.format("Plugin: %-22s\tCurrent Version: %d.%d.%d",
plugin.getPluginId(),
plugin.getMajorVersion(),plugin.getMinorVersion(), plugin.getPatchVersion()));
if (fullList) {
@@ -230,9 +281,9 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
}
if (!list) {
if (pluginId == null) {
- System.out.println("No plugins installed");
+ outOrLog("No plugins installed");
} else {
- System.out.println("Plugin " + pluginId + " not installed");
+ outOrLog("Plugin " + pluginId + " not installed");
}
}
}
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 0ee11a716..a9b9ef2f4 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
@@ -47,6 +47,10 @@ public class PluginCLITest extends BasePluginTest {
System.setProperty("idp.home",getIdpHome().toString());
}
+ @Test(enabled = true) public void testLicense() {
+ assertEquals(PluginInstallerCLI.runMain(new String[] { "--license", "net.shibboleth.plugin.test"} ), AbstractCommandLine.RC_OK);
+ }
+
@Test(enabled = false) public void testList() throws IOException {
assertEquals(PluginInstallerCLI.runMain(new String[] { "-fl", } ), AbstractCommandLine.RC_OK);
}
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/TestPlugin.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/TestPlugin.java
index 14600c972..145407193 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/TestPlugin.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/TestPlugin.java
@@ -34,7 +34,6 @@ public class TestPlugin extends AbstractIdPPlugin {
/** {@inheritDoc} */
@Override
public String getPluginId() {
- // TODO Auto-generated method stub
return "net.shibboleth.plugin.test";
}
@@ -48,6 +47,11 @@ public class TestPlugin extends AbstractIdPPlugin {
return Collections.EMPTY_LIST;
}
}
+
+ /** {@inheritDoc} */
+ public String getLicenseFileLocation() {
+ return "/net/shibboleth/idp/plugin/test.license";
+ }
/** {@inheritDoc} */
@Override
diff --git a/idp-installer/src/test/resources/net/shibboleth/idp/plugin/test.license b/idp-installer/src/test/resources/net/shibboleth/idp/plugin/test.license
new file mode 100644
index 000000000..817a84f8f
--- /dev/null
+++ b/idp-installer/src/test/resources/net/shibboleth/idp/plugin/test.license
@@ -0,0 +1 @@
+Nibble a happy warthog!
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list