[java-identity-provider] branch main updated: IDP-1854 Add a discovery option to the plugin command
Rod Widdowson
rdw at steadingsoftware.com
Tue Aug 24 18:35:01 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=6f806278d12a64005ab4d59d6d20bd30f1ec07c7
The following commit(s) were added to refs/heads/main by this push:
new 6f806278d IDP-1854 Add a discovery option to the plugin command
6f806278d is described below
commit 6f806278d12a64005ab4d59d6d20bd30f1ec07c7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Aug 24 17:22:16 2021 +0100
IDP-1854 Add a discovery option to the plugin command
https://shibboleth.atlassian.net/browse/IDP-1854
Phase 1 - split PluginState into two
---
.../idp/installer/plugin/impl/PluginInfo.java | 248 +++++++++++++++++++++
.../idp/installer/plugin/impl/PluginState.java | 202 ++---------------
2 files changed, 270 insertions(+), 180 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInfo.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInfo.java
new file mode 100644
index 000000000..fc3f20d53
--- /dev/null
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInfo.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.installer.plugin.impl;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+
+import net.shibboleth.idp.installer.impl.InstallationLogger;
+import net.shibboleth.idp.installer.plugin.impl.PluginState.VersionInfo;
+import net.shibboleth.idp.plugin.PluginSupport;
+import net.shibboleth.idp.plugin.PluginSupport.SupportLevel;
+import net.shibboleth.idp.plugin.PluginVersion;
+import net.shibboleth.utilities.java.support.collection.Pair;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/**
+ * Class which encapsulates the information about a given plugin as downloaded
+ * fro the plugin URL (or file).
+ */
+public class PluginInfo {
+
+ /** regexp for spaces. */
+ private static final Pattern SPACE_CONTAINING = Pattern.compile("\\s+");
+
+ /** Class logger. */
+ @Nonnull private final Logger log = InstallationLogger.getLogger(PluginInfo.class);
+
+ /** 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<>();
+
+ /** The pluginId. */
+ @Nonnull private final String pluginId;
+
+ /** Whether the information was sufficient. */
+ private boolean allInfoPresent = true;
+
+ /**
+ * Constructor.
+ *
+ * @param id the id we care about
+ * @param props all the properties.
+ */
+ public PluginInfo(final String id, final Properties props) {
+ pluginId = Constraint.isNotNull(StringSupport.trimOrNull(id), "pluginID must be non-null");
+ parse(props);
+ }
+
+ /** Did the property file have enough information?
+ * @return true if something was missing.
+ */
+ public boolean isInfoComplete() {
+ return allInfoPresent;
+ }
+
+ /** Get the base URL for this version.
+ * @param version which version
+ * @return the base URL
+ */
+ @Nullable public URL getUpdateURL(final PluginVersion version) {
+ final Pair<URL, String> p = downloadInfo.get(version);
+ if (p == null) {
+ return null;
+ }
+ return p.getFirst();
+ }
+
+ /** Get the base Name for this version.
+ * @param version which version
+ * @return the base name
+ */
+ @Nullable public String getUpdateBaseName(final PluginVersion version) {
+ final Pair<URL, String> p = downloadInfo.get(version);
+ if (p == null) {
+ return null;
+ }
+ return p.getSecond();
+ }
+
+ /** Get the raw version imfo for this plugin.
+ * @return the info.
+ */
+ public Map<PluginVersion, VersionInfo> getAvailableVersions() {
+ return versionInfo;
+ }
+
+ /** (try to) populate the information about this plugin.
+ * @param props what to load.
+ */
+ private void parse(@Nonnull final Properties props) {
+ final String name = pluginId + PluginSupport.AVAILABLE_VERSIONS_PROPERTY_SUFFIX;
+ final String availableVersions = StringSupport.trim(props.getProperty(name));
+ if (availableVersions == null) {
+ log.warn("Plugin {}: Could not find {} property.", pluginId, name);
+ allInfoPresent = false;
+ } else {
+ handleAvailableVersions(props, availableVersions);
+ }
+ }
+
+ /** Given a version find out more.
+ * @param props the property files for this plugin we are looking at
+ * @param version the version in question.
+ */
+ // Checkstyle: CyclomaticComplexity OFF
+ private void handleAvailableVersion(final Properties props, final String version) {
+ final PluginVersion theVersion = new PluginVersion(version);
+ if (theVersion.getMajor() == 0 && theVersion.getMinor() == 0 && theVersion.getPatch() == 0) {
+ log.warn("Plugin {}: Improbable version {}", pluginId, version);
+ }
+ if (versionInfo.containsKey(theVersion)) {
+ log.warn("Plugin {}: Duplicate version {}", pluginId, version);
+ }
+
+ final String maxVersionInfo = StringSupport.trimOrNull(
+ props.getProperty(pluginId + PluginSupport.MAX_IDP_VERSION_INTERFIX + version));
+ if (maxVersionInfo == null) {
+ log.warn("Plugin {}, Version {}: Could not find max idp version.", pluginId, version);
+ allInfoPresent = false;
+ return;
+ }
+
+ final String minVersionInfo = StringSupport.trimOrNull(
+ props.getProperty(pluginId + PluginSupport.MIN_IDP_VERSION_INTERFIX + version));
+ if (minVersionInfo == null) {
+ log.warn("Plugin {}, Version {}: Could not find min idp version.", pluginId, version);
+ allInfoPresent = false;
+ return;
+ }
+
+ final String supportLevelString = StringSupport.trimOrNull(
+ props.getProperty(pluginId + PluginSupport.SUPPORT_LEVEL_INTERFIX + version));
+ PluginSupport.SupportLevel supportLevel;
+ if (supportLevelString == null) {
+ log.debug("Plugin {}, Version {}: Could not find support level for {}.", pluginId, version);
+ supportLevel = SupportLevel.Unknown;
+ } else {
+ try {
+ supportLevel = Enum.valueOf(SupportLevel.class, supportLevelString);
+ } catch (final IllegalArgumentException e) {
+ log.warn("Plugin {}, Version {}: Invalid support level {}.", pluginId, version, supportLevelString);
+ supportLevel = SupportLevel.Unknown;
+ }
+ }
+
+ log.debug("Plugin {}: MaxIdP {}, MinIdP {}, Support Level {}",
+ pluginId, maxVersionInfo, minVersionInfo, supportLevel);
+ final VersionInfo info;
+ info = new VersionInfo(new PluginVersion(maxVersionInfo), new PluginVersion(minVersionInfo), supportLevel);
+ versionInfo.put(theVersion, info);
+ String downloadURL = StringSupport.trimOrNull(
+ getDefaultedValue(props, PluginSupport.DOWNLOAD_URL_INTERFIX, version));
+ final String baseName = StringSupport.trimOrNull(
+ getDefaultedValue(props, PluginSupport.BASE_NAME_INTERFIX, version));
+ if (baseName != null && downloadURL != null) {
+ try {
+ if (!downloadURL.endsWith("/")) {
+ downloadURL += "/";
+ }
+ final URL url = new URL(downloadURL);
+ downloadInfo.put(theVersion, new Pair<>(url, baseName));
+ log.trace("Plugin {}, version {}: Added download URL {} baseName {} for {}",
+ pluginId, theVersion, url, baseName);
+ } catch (final MalformedURLException e) {
+ log.warn("Plugin {}, version {}: Download URL '{}' could not be constructed",
+ pluginId, theVersion, downloadURL, e);
+ }
+ } else {
+ log.info("Plugin {}, version {}: no download information present", pluginId, theVersion);
+ }
+ }
+ // Checkstyle: CyclomaticComplexity ON
+
+ /** Given a list of versions find out more.
+ * @param props the property files for this plugin we are looking at
+ * @param availableVersions a space delimited array of versions
+ */
+ private void handleAvailableVersions(final Properties props, final String availableVersions) {
+ final String[] versions = SPACE_CONTAINING.split(availableVersions, 0);
+
+ log.debug("Plugin {}: Available versions : {} ", pluginId, availableVersions);
+ for (final String version:versions) {
+ log.debug("Plugin {}: Considering {}", pluginId, version);
+ handleAvailableVersion(props, version);
+ }
+ }
+
+ /** Look up the key derived from the pluginId, the interfix and the version, but if that
+ * fails look for a templated definition.
+ * @param props what to look in
+ * @param interfix the interface (between the ID and the version)
+ * @param version the version.
+ * @return the suitable value
+ */
+ @Nullable private String getDefaultedValue(final Properties props, final String interfix, final String version) {
+ String result = props.getProperty(pluginId + interfix + version);
+ if (result != null) {
+ return result;
+ }
+ result = props.getProperty(pluginId + interfix + PluginSupport.VERSION_PATTERN);
+ if (result == null) {
+ return result;
+ }
+ return result.replaceAll(PluginSupport.VERSION_PATTERN_REGEX, version);
+ }
+
+ /** Is the specified plugin supported with this IdP version.
+ * @param pluginVersion the version if the plugin as a {@link PluginVersion}
+ * @param idPVersion the version if the IDP as a {@link PluginVersion}
+ * @return whether it is supported.
+ */
+ public boolean isSupportedWithIdPVersion(final PluginVersion pluginVersion, final PluginVersion idPVersion) {
+ final VersionInfo info = versionInfo.get(pluginVersion);
+ if (info == null) {
+ log.error("Plugin {}: Unknown version {} supplied.", pluginId, pluginVersion);
+ log.debug("Plugin {}: Available {}", pluginId, versionInfo.keySet());
+ return false;
+ }
+ return PluginState.isSupportedWithIdPVersion(info, idPVersion);
+ }
+}
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 869829970..017fcfedd 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
@@ -18,13 +18,10 @@
package net.shibboleth.idp.installer.plugin.impl;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -37,18 +34,15 @@ import org.springframework.core.io.Resource;
import net.shibboleth.ext.spring.resource.HTTPResource;
import net.shibboleth.idp.installer.impl.InstallationLogger;
import net.shibboleth.idp.plugin.IdPPlugin;
-import net.shibboleth.idp.plugin.PluginSupport;
import net.shibboleth.idp.plugin.PluginSupport.SupportLevel;
import net.shibboleth.idp.plugin.PluginVersion;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.collection.Pair;
import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder;
import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
/**
* A class which will answer questions about a plugin state as of now
@@ -56,24 +50,15 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
*/
public class PluginState extends AbstractInitializableComponent {
- /** regexp for spaces. */
- private static final Pattern SPACE_CONTAINING = Pattern.compile("\\s+");
-
/** The plug in in question. */
@Nonnull private final IdPPlugin plugin;
+ /** My Plugin Info. */
+ @NonnullAfterInit private PluginInfo myPluginInfo;
+
/** 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<>();
-
- /** My support information. */
- @NonnullAfterInit private VersionInfo myVersionInfo;
-
/** Class logger. */
@Nonnull private final Logger log = InstallationLogger.getLogger(PluginState.class);
@@ -100,11 +85,7 @@ public class PluginState extends AbstractInitializableComponent {
* @return the base URL
*/
@Nullable public URL getUpdateURL(final PluginVersion version) {
- final Pair<URL, String> p = downloadInfo.get(version);
- if (p == null) {
- return null;
- }
- return p.getFirst();
+ return myPluginInfo.getUpdateURL(version);
}
/** Get the base Name for this version.
@@ -112,153 +93,21 @@ public class PluginState extends AbstractInitializableComponent {
* @return the base name
*/
@Nullable public String getUpdateBaseName(final PluginVersion version) {
- final Pair<URL, String> p = downloadInfo.get(version);
- if (p == null) {
- return null;
- }
- return p.getSecond();
- }
-
- /** Set the client.
- * @param what what to set.
- */
- public void setHttpClient(@Nonnull final HttpClient what) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
- httpClient = Constraint.isNotNull(what, "HttpClient cannot be null");
- }
-
- /** Look up the key derived from the pluginId, the interfix and the version, but if that
- * fails look for a templated definition.
- * @param props what to look in
- * @param interfix the interface (between the ID and the version)
- * @param version the version.
- * @return the suitable value
- */
- @Nullable private String getDefaultedValue(final Properties props, final String interfix, final String version) {
- String result = props.getProperty(plugin.getPluginId() + interfix + version);
- if (result != null) {
- return result;
- }
- result = props.getProperty(plugin.getPluginId() + interfix + PluginSupport.VERSION_PATTERN);
- if (result == null) {
- return result;
- }
- return result.replaceAll(PluginSupport.VERSION_PATTERN_REGEX, version);
- }
-
- /** Given a version find out more.
- * @param props the property files for this plugin we are looking at
- * @param version the version in question.
- * @return true if we processed everything OK.
- */
- // Checkstyle: CyclomaticComplexity OFF
- private boolean handleAvailableVersion(final Properties props, final String version) {
- final PluginVersion theVersion = new PluginVersion(version);
- if (theVersion.getMajor() == 0 && theVersion.getMinor() == 0 && theVersion.getPatch() == 0) {
- log.warn("Plugin {}: Improbable version {}", plugin.getPluginId(), version);
- }
- if (versionInfo.containsKey(theVersion)) {
- log.warn("Plugin {}: Duplicate version {}", plugin.getPluginId(), version);
- }
-
- final String maxVersionInfo = StringSupport.trimOrNull(
- props.getProperty(plugin.getPluginId() + PluginSupport.MAX_IDP_VERSION_INTERFIX + version));
- if (maxVersionInfo == null) {
- log.warn("Plugin {}, Version {}: Could not find max idp version.", plugin.getPluginId(), version);
- return false;
- }
-
- final String minVersionInfo = StringSupport.trimOrNull(
- props.getProperty(plugin.getPluginId() + PluginSupport.MIN_IDP_VERSION_INTERFIX + version));
- if (minVersionInfo == null) {
- log.warn("Plugin {}, Version {}: Could not find min idp version.", plugin.getPluginId(), version);
- return false;
- }
-
- final String supportLevelString = StringSupport.trimOrNull(
- props.getProperty(plugin.getPluginId()+ PluginSupport.SUPPORT_LEVEL_INTERFIX + version));
- PluginSupport.SupportLevel supportLevel;
- if (supportLevelString == null) {
- log.debug("Plugin {}, Version {}: Could not find support level for {}.", plugin.getPluginId(), version);
- supportLevel = SupportLevel.Unknown;
- } else {
- try {
- supportLevel = Enum.valueOf(SupportLevel.class, supportLevelString);
- } catch (final IllegalArgumentException e) {
- log.warn("Plugin {}, Version {}: Invalid support level {}.",
- plugin.getPluginId(), version, supportLevelString);
- supportLevel = SupportLevel.Unknown;
- }
- }
-
- log.debug("Plugin {}: MaxIdP {}, MinIdP {}, Support Level {}",
- plugin.getPluginId(), maxVersionInfo, minVersionInfo, supportLevel);
- final VersionInfo info;
- info = new VersionInfo(new PluginVersion(maxVersionInfo), new PluginVersion(minVersionInfo), supportLevel);
- versionInfo.put(theVersion, info);
- if (myPluginVersion.equals(theVersion)) {
- myVersionInfo = info;
- }
- String downloadURL = StringSupport.trimOrNull(
- getDefaultedValue(props, PluginSupport.DOWNLOAD_URL_INTERFIX, version));
- final String baseName = StringSupport.trimOrNull(
- getDefaultedValue(props, PluginSupport.BASE_NAME_INTERFIX, version));
- if (baseName != null && downloadURL != null) {
- try {
- if (!downloadURL.endsWith("/")) {
- downloadURL += "/";
- }
- final URL url = new URL(downloadURL);
- downloadInfo.put(theVersion, new Pair<>(url, baseName));
- log.trace("Plugin {}, version {}: Added download URL {} baseName {} for {}",
- plugin.getPluginId(), theVersion, url, baseName);
- } catch (final MalformedURLException e) {
- log.warn("Plugin {}, version {}: Download URL '{}' could not be constructed",
- plugin.getPluginId(), theVersion, downloadURL, e);
- }
- } else {
- log.info("Plugin {}, version {}: no download information present", plugin.getPluginId(), theVersion);
- }
- return true;
- }
- // Checkstyle: CyclomaticComplexity ON
-
- /** Given a list of versions find out more.
- * @param props the property files for this plugin we are looking at
- * @param availableVersions a space delimited array of versions
- * @return true if we processed everything OK.
- */
- private boolean handleAvailableVersions(final Properties props, final String availableVersions) {
- final String[] versions = SPACE_CONTAINING.split(availableVersions, 0);
-
- log.debug("Plugin {}: Available versions : {} ", plugin.getPluginId(), availableVersions);
- for (final String version:versions) {
- log.debug("Plugin {}: Considering {}", plugin.getPluginId(), version);
- if (!handleAvailableVersion(props, version)) {
- return false;
- }
- }
- return true;
+ return myPluginInfo.getUpdateBaseName(version);
}
/** (try to) populate the information about this plugin.
* @param propertyResource where to start looking
* @return whether it worked
*/
- protected boolean populate(@Nonnull final Resource propertyResource) {
+ private boolean populate(@Nonnull final Resource propertyResource) {
try {
final Properties props = new Properties();
log.debug("Loading properties from {}", propertyResource.getDescription());
props.load(propertyResource.getInputStream());
- final String name = plugin.getPluginId() + PluginSupport.AVAILABLE_VERSIONS_PROPERTY_SUFFIX;
- final String availableVersions = StringSupport.trim(props.getProperty(name));
- if (availableVersions == null) {
- log.warn("Plugin {}: Could not find {} property in {}",
- plugin.getPluginId(), name, propertyResource.getDescription());
- return false;
- }
- return handleAvailableVersions(props, availableVersions);
+ myPluginInfo = new PluginInfo(plugin.getPluginId(), props);
+ return myPluginInfo.isInfoComplete();
} catch (final IOException e) {
// INFO - not being there is not a failure
log.info("Plugin {}: Could not find description {}",
@@ -266,7 +115,15 @@ public class PluginState extends AbstractInitializableComponent {
return false;
}
}
-
+
+ /** Set the client.
+ * @param what what to set.
+ */
+ public void setHttpClient(@Nonnull final HttpClient what) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ httpClient = Constraint.isNotNull(what, "HttpClient cannot be null");
+ }
+
/** {@inheritDoc} */
// CheckStyle: CyclomaticComplexity OFF
protected void doInitialize() throws ComponentInitializationException {
@@ -306,7 +163,7 @@ public class PluginState extends AbstractInitializableComponent {
if (populate(propertyResource)) {
log.debug("Plugin {}: PluginState populated from {}",
plugin.getPluginId(), propertyResource.getDescription());
- if (myVersionInfo == null) {
+ if (myPluginInfo.getAvailableVersions().get(myPluginVersion) == null) {
log.error("Plugin {} : Could not find version {} in descriptions at {}",
plugin.getPluginId(), myPluginVersion, propertyResource.getDescription());
}
@@ -329,24 +186,16 @@ public class PluginState extends AbstractInitializableComponent {
}
}
// CheckStyle: CyclomaticComplexity ON
-
+
/** Is the specified plugin supported with this IdP version.
* @param pluginVersion the version if the plugin as a {@link PluginVersion}
* @param idPVersion the version if the IDP as a {@link PluginVersion}
* @return whether it is supported.
*/
public boolean isSupportedWithIdPVersion(final PluginVersion pluginVersion, final PluginVersion idPVersion) {
- final VersionInfo info = versionInfo.get(pluginVersion);
-
- if (info == null) {
- log.error("Plugin {}: Unknown version {} supplied.", plugin.getPluginId(), pluginVersion);
- log.debug("Plugin {}: Available {}", plugin.getPluginId(), versionInfo.keySet());
- return false;
- }
-
- return isSupportedWithIdPVersion(info, idPVersion);
+ return myPluginInfo.isSupportedWithIdPVersion(pluginVersion, idPVersion);
}
-
+
/** Is the specified plugin supported with this IdP version.
* Worker method for all 'isSupportedWith' classes.
* @param pluginVersionInfo the version info to consider
@@ -371,19 +220,12 @@ public class PluginState extends AbstractInitializableComponent {
return false;
}
- /** Return the current state (from provided plugin).
- * @return Returns the Current Info.
- */
- public VersionInfo getCurrentInfo() {
- return myVersionInfo;
- }
-
/** Return all announced versions.
* @return the versions.
*/
@Nonnull @NotEmpty public Map<PluginVersion, VersionInfo> getAvailableVersions() {
ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
- return versionInfo;
+ return myPluginInfo.getAvailableVersions();
}
/** Encapsulation of the information about a given IdP version. */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list