[java-identity-provider] branch main updated: IDP-1747 Local override for plugin version properties

Rod Widdowson rdw at steadingsoftware.com
Thu Feb 11 13:37:32 UTC 2021


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=5446312a14c3b062b4abd3bf50e6d446b09e3cf2

The following commit(s) were added to refs/heads/main by this push:
       new  5446312a1 IDP-1747 Local override for plugin version properties
5446312a1 is described below

commit 5446312a14c3b062b4abd3bf50e6d446b09e3cf2
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Feb 11 13:34:28 2021 +0000

    IDP-1747 Local override for plugin version properties
    
    https://issues.shibboleth.net/jira/browse/IDP-1747
---
 .../idp/installer/plugin/impl/PluginInstaller.java |  12 ++-
 .../plugin/impl/PluginInstallerArguments.java      |  15 ++-
 .../installer/plugin/impl/PluginInstallerCLI.java  |  28 ++++--
 .../idp/installer/plugin/impl/PluginState.java     |  28 ++++--
 .../idp/installer/plugin/impl/PluginCLITest.java   |   8 ++
 .../idp/installer/plugin/impl/PluginStateTest.java |   8 +-
 .../net/shibboleth/idp/plugin/allPlugins.props     | 106 +++++++++++++++++++++
 7 files changed, 185 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 812dbf3f4..3cfaf1276 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
@@ -121,6 +121,9 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
     /** What to use to download things. */
     private HttpClient httpClient;
 
+    /** If overridden these are the urls to us for update (rather than what the plugin asks for. */
+    @Nonnull private List<URL> updateOverrideURLs = Collections.emptyList();
+
     /** Dumping space for renamed files. */
     @NonnullAfterInit private Path workspacePath;
 
@@ -184,6 +187,13 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         httpClient = Constraint.isNotNull(what, "HttpClient should be non-null");
     }
 
+    /** Set the override URLS.
+     * @param urls The updateOverrideURLs to set.
+     */
+    public void setUpdateOverrideURLs(@Nonnull final List<URL> urls) {
+        updateOverrideURLs = Constraint.isNotNull(urls, "Override URLS must be non null");
+    }
+
     /** Set the Module Context security parameters.
      * @param params what to set.
      */
@@ -232,7 +242,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         checkSignature(base, fileName);
         setupDescriptionFromDistribution();
         if (checkVersion) {
-            final PluginState state = new PluginState(description);
+            final PluginState state = new PluginState(description, updateOverrideURLs);
             try {
                 state.initialize();
             } catch (final ComponentInitializationException e) {
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 713ffc0ab..153a91c45 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
@@ -34,6 +34,7 @@ import com.beust.jcommander.Parameter;
 
 import net.shibboleth.idp.cli.AbstractIdPHomeAwareCommandLineArguments;
 import net.shibboleth.idp.plugin.PluginVersion;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /**
  * Arguments for Plugin Installer CLI.
@@ -91,6 +92,10 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
     @Parameter(names= {"-cl", "--contents-list"})
     @Nullable private String contentsList;
 
+    /** location to override the plugin supplied location. */
+    @Parameter(names= {"--updateURL"})
+    @Nullable private String updateURL;
+
     /** The {@link #forceUpdateVersion} as a {@link PluginVersion}. */
     @Nullable private PluginVersion updateVersion;
 
@@ -206,7 +211,6 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
         return noPrompt;
     }
 
-
     /** Return the version to update to or null.
      * @return the version or null
      */
@@ -214,6 +218,13 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
         return updateVersion;
     }
 
+    /** return the update URL or null.
+     * @return null or the calue supplied
+     */
+    @Nullable public String getUpdateURL() {
+        return StringSupport.trimOrNull(updateURL);
+    }
+
     /**
      * Get operation to perform.
      * @return operation
@@ -342,6 +353,8 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
         out.println(String.format("  %-22s %s", "--noPrompt", "Unattended Install"));
         out.println(String.format("  %-22s %s", "--truststore <path>",
                 "Explicit location to look for keys (should exist but may be an empty file)"));
+        out.println(String.format("  %-22s %s", "--updateURL <URL>",
+                "Explicit location to look for update information (overrides the plugin's value)"));
         out.println();
     }
 
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 29ab839e6..639a35ed5 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
@@ -21,9 +21,12 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.nio.file.Path;
 import java.security.Security;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -59,12 +62,15 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
 
     /** Class logger. */
     @Nullable private Logger log;
-    
+
     /** A Plugin Installer to use. */
     @Nullable private PluginInstaller installer;
 
+    /** Update URLs. */
+    private List<URL> updateURLs;
+
     /**
-     * Constrained Constructor.
+      * Constrained Constructor.
      */
     private PluginInstallerCLI() {
         super();
@@ -98,7 +104,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
     }
     
     /** {@inheritDoc} */
-    //CheckStyle: CyclomaticComplexity OFF
+    //CheckStyle: CyclomaticComplexity|MethodLength OFF
     protected int doRun(final PluginInstallerArguments args) {
         
         if (args.getHttpClientName() == null) {
@@ -112,6 +118,16 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
         if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
             Security.addProvider(new BouncyCastleProvider());
         }
+        if (args.getUpdateURL() !=null) {
+            try {
+                updateURLs = List.of(new URL(args.getUpdateURL()));
+            } catch (final MalformedURLException e) {
+                log.error("Could not convert update URL {}", args.getUpdateURL(), e);
+                return RC_INIT;
+            }
+        } else {
+            updateURLs = Collections.emptyList();
+        }
 
         try (final PluginInstaller inst = new PluginInstaller()){
             constructPluginInstaller(inst, args);
@@ -167,7 +183,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
         }
         return ret;
     }
-    //CheckStyle: CyclomaticComplexity OM
+    //CheckStyle: CyclomaticComplexity|MethodLength  ON
 
     /** Build the installer.
      * @param inst the newly created installed
@@ -206,7 +222,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
      */
     private void printDetails(final IdPPlugin plugin) {
         log.debug("Interrogating {}", plugin.getPluginId());
-        final PluginState state =  new PluginState(plugin);
+        final PluginState state =  new PluginState(plugin, updateURLs);
         if (getHttpClient() != null) {
             state.setHttpClient(getHttpClient());
         }
@@ -389,7 +405,7 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
             return;
         }
         log.debug("Interrogating {} ", plugin.getPluginId());
-        final PluginState state =  new PluginState(plugin);
+        final PluginState state =  new PluginState(plugin, updateURLs);
         if (getHttpClient() != null) {
             state.setHttpClient(getHttpClient());
         }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java
index f46b6df1f..5a76f5dc1 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java
@@ -61,13 +61,13 @@ public class PluginState extends AbstractInitializableComponent {
 
     /** The plug in in question. */
     @Nonnull private final IdPPlugin plugin;
-    
+
     /** The version of this plugin. */
     @Nonnull private final PluginVersion myPluginVersion;
-    
+
     /** The support information. */
     @Nonnull private final Map<PluginVersion, VersionInfo> versionInfo = new HashMap<>();
-    
+
     /** The Download information. */
     @Nonnull private final Map<PluginVersion, Pair<URL,String>> downloadInfo = new HashMap<>();
 
@@ -76,16 +76,21 @@ public class PluginState extends AbstractInitializableComponent {
     
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(PluginState.class);
-    
+
     /** The HttpClient to use.*/
     @NonnullAfterInit private HttpClient httpClient;
 
+    /** If overridden these are the urls to us for update (rather than what the plguin asks for. */
+    @Nonnull private final List<URL> updateOverrideURLs;
+
     /**
      * Constructor.
      *
      * @param description what we are talking about.
+     * @param updateOverrides override for update locations.  An empty list signifies no overrride.
      */
-    public PluginState(@Nonnull final IdPPlugin description) {
+    public PluginState(@Nonnull final IdPPlugin description, final List<URL> updateOverrides) {
+        updateOverrideURLs = Constraint.isNotNull(updateOverrides, "updated Locations must not be null");
         plugin = Constraint.isNotNull(description, "Plugin must not be null");
         myPluginVersion = new PluginVersion(plugin);
     }
@@ -270,10 +275,15 @@ public class PluginState extends AbstractInitializableComponent {
             if (httpClient == null) {
                 httpClient = new HttpClientBuilder().buildClient();
             }
-            final List<URL> urls = plugin.getUpdateURLs();
-            if (urls == null) {
-                log.error("Plugin {} was malformed", plugin.getPluginId());
-                throw new ComponentInitializationException("Could not locate information plugin"); 
+            final List<URL> urls;
+            if (updateOverrideURLs.isEmpty()) {
+                urls = plugin.getUpdateURLs();
+                if (urls == null) {
+                    log.error("Plugin {} was malformed", plugin.getPluginId());
+                    throw new ComponentInitializationException("Could not locate information plugin");
+                }
+            } else {
+                urls = updateOverrideURLs;
             }
             for (final URL url: urls) {
                 final Resource propertyResource;
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 a1d7f22ff..ef57becdd 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
@@ -68,6 +68,14 @@ public class PluginCLITest extends BasePluginTest {
         assertEquals(PluginInstallerCLI.runMain(new String[] { "-fl", } ), AbstractCommandLine.RC_OK);
     }
 
+    @Test(enabled = true,dependsOnMethods = {/*"testWeb"*/}) public void testListWithOverride() throws IOException {
+        ClassPathResource resource = new ClassPathResource("/net/shibboleth/idp/plugin/allPlugins.props");
+        String url = resource.getURL().toString();
+        final String parms[]=  { "-fl", "--updateURL", url};
+        final int rc = PluginInstallerCLI.runMain(parms);
+        assertEquals(rc, AbstractCommandLine.RC_OK);
+    }
+
     @Test(enabled = true) public void testWrong() {
         assertEquals(PluginInstallerCLI.runMain(new String[] { "-i", "a"}), AbstractCommandLine.RC_INIT);
     }
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java
index a4bdc4e97..266beecbf 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java
@@ -25,6 +25,7 @@ import static org.testng.Assert.fail;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Collections;
 import java.util.List;
 
 import org.testng.annotations.Test;
@@ -49,7 +50,7 @@ public class PluginStateTest {
 
         final IdPPlugin simple = new TestPlugin();
         
-        final PluginState state = new PluginState(simple);
+        final PluginState state = new PluginState(simple, Collections.EMPTY_LIST);
         
         state.initialize();
 
@@ -86,7 +87,8 @@ public class PluginStateTest {
 
     @Test
     public void testTemplating() throws ComponentInitializationException, MalformedURLException {
-        final PluginState state = new PluginState(new TestPlugin());
+        final TestPlugin tp = new TestPlugin();
+        final PluginState state = new PluginState(tp, tp.getUpdateURLs());
         state.initialize();
         final PluginVersion v123 = new PluginVersion(1,2,3);
         final PluginVersion v124 = new PluginVersion(1,2,4);
@@ -116,7 +118,7 @@ public class PluginStateTest {
             }
         };
         
-        final PluginState state = new PluginState(simple);
+        final PluginState state = new PluginState(simple, Collections.EMPTY_LIST);
         state.initialize();
         
         assertEquals(state.getAvailableVersions().size(), 3);
diff --git a/idp-installer/src/test/resources/net/shibboleth/idp/plugin/allPlugins.props b/idp-installer/src/test/resources/net/shibboleth/idp/plugin/allPlugins.props
new file mode 100644
index 000000000..f84bfcddf
--- /dev/null
+++ b/idp-installer/src/test/resources/net/shibboleth/idp/plugin/allPlugins.props
@@ -0,0 +1,106 @@
+# This file manages compatibility and update properties for
+# Shibboleth Project-delivered IdP plugins.
+
+#######################
+# TOTP Authentication #
+#######################
+net.shibboleth.idp.plugin.authn.totp.versions = 0.0.3
+
+net.shibboleth.idp.plugin.authn.totp.downloadURL.%{version} = https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/authn/idp-plugin-totp-dist/%{version}
+net.shibboleth.idp.plugin.authn.totp.baseName.%{version} = idp-plugin-totp-dist-%{version}
+
+net.shibboleth.idp.plugin.authn.totp.idpVersionMax.0.0.3 = 5.0.0
+net.shibboleth.idp.plugin.authn.totp.idpVersionMin.0.0.3 = 4.1.0
+net.shibboleth.idp.plugin.authn.totp.supportLevel.0.0.3 = Current
+
+
+#######################
+# SCRIPTING Plugins   #
+#######################
+net.shibboleth.idp.plugin.nashorn.versions=0.1.3 0.1.4
+net.shibboleth.idp.plugin.nashorn.downloadURL.%{version} = https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/scripting/idp-plugin-nashorn-dist/%{version}
+net.shibboleth.idp.plugin.nashorn.baseName.%{version} = idp-plugin-nashorn-dist-%{version}
+
+net.shibboleth.idp.plugin.nashorn.idpVersionMax.0.1.3=5.0.0
+net.shibboleth.idp.plugin.nashorn.idpVersionMin.0.1.3=4.1.0
+net.shibboleth.idp.plugin.nashorn.supportLevel.0.1.3 = Withdrawn
+
+net.shibboleth.idp.plugin.nashorn.idpVersionMax.0.1.4=5.0.0
+net.shibboleth.idp.plugin.nashorn.idpVersionMin.0.1.4=4.1.0
+net.shibboleth.idp.plugin.nashorn.supportLevel.0.1.4 = Current
+
+net.shibboleth.idp.plugin.rhino.versions=0.1.3 0.1.4
+net.shibboleth.idp.plugin.rhino.downloadURL.%{version} = https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/scripting/idp-plugin-rhino-dist/%{version}
+net.shibboleth.idp.plugin.rhino.baseName.%{version} = idp-plugin-rhino-dist-%{version}
+
+net.shibboleth.idp.plugin.rhino.idpVersionMax.0.1.3=5.0.0
+net.shibboleth.idp.plugin.rhino.idpVersionMin.0.1.3=4.1.0
+net.shibboleth.idp.plugin.rhino.supportLevel.0.1.3 = Withdrawn
+
+net.shibboleth.idp.plugin.rhino.idpVersionMax.0.1.4=5.0.0
+net.shibboleth.idp.plugin.rhino.idpVersionMin.0.1.4=4.1.0
+net.shibboleth.idp.plugin.rhino.supportLevel.0.1.4 = Current
+
+
+################################################################
+# DuoOIDC Authentication based on the Shibboleth Nimbus client #
+################################################################
+net.shibboleth.idp.plugin.authn.duo.nimbus.versions = 0.9.0
+net.shibboleth.idp.plugin.authn.duo.nimbus.downloadURL.%{version} = https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/authn/idp-plugin-duo-nimbus-dist/%{version}
+net.shibboleth.idp.plugin.authn.duo.nimbus.baseName.%{version} = idp-plugin-duo-dist-${version}
+
+net.shibboleth.idp.plugin.authn.duo.nimbus.idpVersionMax.0.9.0 = 5.0.0
+net.shibboleth.idp.plugin.authn.duo.nimbus.idpVersionMin.0.9.0 = 4.1.0
+net.shibboleth.idp.plugin.authn.duo.nimbus.supportLevel.0.9.0 = Current
+
+#####################################################
+# DuoOIDC Authentication based on the Duo WebSDK v4 #
+#####################################################
+net.shibboleth.idp.plugin.authn.duo.sdk.versions = 0.9.0
+net.shibboleth.idp.plugin.authn.duo.sdk.downloadURL.%{version} = https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/authn/idp-plugin-duo-sdk-dist/%{version}
+net.shibboleth.idp.plugin.authn.duo.sdk.baseName.%{version} = idp-plugin-duo-dist-${version}
+
+net.shibboleth.idp.plugin.authn.duo.sdk.idpVersionMax.0.9.0 = 5.0.0
+net.shibboleth.idp.plugin.authn.duo.sdk.idpVersionMin.0.9.0 = 4.1.0
+net.shibboleth.idp.plugin.authn.duo.sdk.supportLevel.0.9.0 = Current
+
+###############################
+# OIDC Commons library plugin #
+###############################
+net.shibboleth.oidc.common.versions = 0.0.1
+net.shibboleth.oidc.common.downloadURL.%{version} = https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/oidc/oidc-common-dist/%{version}
+net.shibboleth.oidc.common.baseName.%{version} = oidc-common-dist-${version}
+
+net.shibboleth.oidc.common.idpVersionMax.0.0.1 = 5.0.0
+net.shibboleth.oidc.common.idpVersionMin.0.0.1 = 4.1.0
+net.shibboleth.oidc.common.supportLevel.0.0.1 = Current
+##########
+## TEST ONLY
+##########
+net.shibboleth.plugin.test.versions=1.2.3 1.2.4 2.0.0
+
+net.shibboleth.plugin.test.baseName.%{version}=base-%{version}-%{version}
+net.shibboleth.plugin.test.downloadURL.%{version}=https://example.org/plugins
+
+#
+# 1.2.3
+#
+net.shibboleth.plugin.test.idpVersionMax.1.2.3=5.0.0
+net.shibboleth.plugin.test.idpVersionMin.1.2.3=4.1.0
+net.shibboleth.plugin.test.supportLevel.1.2.3 = Current
+#
+# 1.2.4
+#
+net.shibboleth.plugin.test.downloadURL.1.2.4=https://example.org/plugins4
+net.shibboleth.plugin.test.idpVersionMax.1.2.4=5.0.0
+net.shibboleth.plugin.test.idpVersionMin.1.2.4=4.2.0
+net.shibboleth.plugin.test.supportLevel.1.2.4 = OutOfDate
+#
+# 2.0.0.
+#
+net.shibboleth.plugin.test.downloadURL.2.0.0=https://example.org/plugins2
+net.shibboleth.plugin.test.baseName.2.0.0=base-1-2-4
+net.shibboleth.plugin.test.idpVersionMax.2.0.0=8.0.0
+net.shibboleth.plugin.test.idpVersionMin.2.0.0=4.99.1
+net.shibboleth.plugin.test.supportLevel.2.0.0 = Unsupported
+

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list