[java-identity-provider] 03/05: IDP-2121 Future Proofing the Module Plugin infrastructure for Future SP use
Rod Widdowson
rdw at steadingsoftware.com
Fri Jun 9 09:37:01 UTC 2023
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=d04ddc458ac7754419b6f1a55ee7aa88b3a1e835
commit d04ddc458ac7754419b6f1a55ee7aa88b3a1e835
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jun 8 19:54:02 2023 +0100
IDP-2121 Future Proofing the Module Plugin infrastructure for Future SP use
https://shibboleth.atlassian.net/browse/IDP-2121
Push the Property driven Plugin down to shib-profile.
Remove AbstractIdPPlugin.java
---
.../shibboleth/idp/plugin/AbstractIdPPlugin.java | 29 ----
.../net/shibboleth/idp/plugin/PluginException.java | 3 +-
.../idp/plugin/PropertyDrivenIdPPlugin.java | 174 +--------------------
.../java/net/shibboleth/idp/plugin/TestPlugin.java | 1 +
.../idp/plugin/impl/FirstPartyIdPPlugin.java | 2 +-
.../installer/plugin/impl/PluginInstallerTest.java | 5 +-
.../idp/installer/plugin/impl/TestPlugin.java | 9 +-
7 files changed, 18 insertions(+), 205 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
deleted file mode 100644
index e2825bb8c..000000000
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/AbstractIdPPlugin.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.plugin;
-
-import net.shibboleth.idp.module.IdPModule;
-import net.shibboleth.profile.plugin.AbstractPlugin;
-
-/**
- * A base class implementing {@link IdPPlugin} that defaults common settings.
- *
- * @since 4.1.0
- */
-public abstract class AbstractIdPPlugin extends AbstractPlugin<IdPModule> implements IdPPlugin {
-}
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginException.java b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginException.java
index a2f9e58f6..0b0b15f93 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginException.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginException.java
@@ -26,7 +26,8 @@ import javax.annotation.concurrent.ThreadSafe;
* @since 4.1.0
*/
@ThreadSafe
-public class PluginException extends Exception {
+ at Deprecated
+public class PluginException extends net.shibboleth.profile.plugin.PluginException {
/** Serial number. */
private static final long serialVersionUID = 3469763471281379002L;
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 95dd1a67d..ab66f3e09 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
@@ -19,72 +19,20 @@ package net.shibboleth.idp.plugin;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Properties;
-import java.util.Set;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.slf4j.Logger;
-
-import net.shibboleth.idp.module.PropertyDrivenIdPModule;
-import net.shibboleth.profile.installablecomponent.InstallableComponentVersion;
-import net.shibboleth.shared.annotation.constraint.NonNegative;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
-import net.shibboleth.shared.annotation.constraint.NotEmpty;
-import net.shibboleth.shared.annotation.constraint.NotLive;
-import net.shibboleth.shared.annotation.constraint.Unmodifiable;
-import net.shibboleth.shared.collection.CollectionSupport;
-import net.shibboleth.shared.logic.Constraint;
-import net.shibboleth.shared.primitive.LoggerFactory;
-import net.shibboleth.shared.primitive.StringSupport;
+import net.shibboleth.idp.module.IdPModule;
+import net.shibboleth.profile.plugin.PluginException;
+import net.shibboleth.profile.plugin.PropertyDrivenPlugin;
/**
* Implementation of {@link IdPPlugin} relying on Java {@link Properties}.
*
* @since 4.1.0
*/
-public abstract class PropertyDrivenIdPPlugin extends AbstractIdPPlugin {
-
- /** Default name of plugin properties resource. */
- @Nonnull @NotEmpty public static final String DEFAULT_RESOURCE = "plugin.properties";
-
- /** Property for plugin ID. */
- @Nonnull @NotEmpty public static final String PLUGIN_ID_PROPERTY = "plugin.id";
-
- /** 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.";
-
- /** Property for plugin's required modules. */
- @Nonnull @NotEmpty public static final String PLUGIN_REQ_MODULES_PROPERTY = "plugin.modules.required";
-
- /** Class logger. */
- @Nonnull private Logger log = LoggerFactory.getLogger(PropertyDrivenIdPModule.class);
-
- /** Properties describing plugin. */
- @Nonnull private final Properties pluginProperties;
-
- /** Non-defaulted plugin ID. */
- @Nullable private String pluginId;
-
- /** Handles parsing of plugin version. */
- @Nullable private InstallableComponentVersion pluginVersion;
-
- /** Plugin update URLs. */
- @Nonnull @NonnullElements private List<URL> updateURLs = CollectionSupport.emptyList();
-
- /** Required modules. */
- @Nonnull @NonnullElements private Set<String> requiredModules = CollectionSupport.emptySet();
+public abstract class PropertyDrivenIdPPlugin extends PropertyDrivenPlugin<IdPModule> implements IdPPlugin {
/**
* Constructor.
@@ -95,7 +43,7 @@ public abstract class PropertyDrivenIdPPlugin extends AbstractIdPPlugin {
* @throws PluginException if the plugin is not in a valid state
*/
public PropertyDrivenIdPPlugin(@Nonnull final Class<? extends IdPPlugin> claz) throws IOException, PluginException {
- this(claz.getResourceAsStream(DEFAULT_RESOURCE));
+ super(claz);
}
/**
@@ -108,9 +56,7 @@ public abstract class PropertyDrivenIdPPlugin extends AbstractIdPPlugin {
*/
public PropertyDrivenIdPPlugin(@Nonnull final InputStream inputStream)
throws IOException, PluginException {
- pluginProperties = new Properties();
- pluginProperties.load(inputStream);
- load();
+ super(inputStream);
}
/**
@@ -121,113 +67,7 @@ public abstract class PropertyDrivenIdPPlugin extends AbstractIdPPlugin {
* @throws PluginException if the plugin is not in a valid state
*/
public PropertyDrivenIdPPlugin(@Nonnull final Properties properties) throws PluginException {
- pluginProperties = Constraint.isNotNull(properties, "Properties cannot be null");
- load();
- }
-
- /**
- * Load plugin information from properties.
- *
- * @throws PluginException on errors
- */
- protected void load() throws PluginException {
-
- pluginId = StringSupport.trimOrNull(pluginProperties.getProperty(PLUGIN_ID_PROPERTY));
-
- String version = getClass().getPackage().getImplementationVersion();
- if (version == null) {
- version = StringSupport.trimOrNull(pluginProperties.getProperty(PLUGIN_VERSION_PROPERTY));
- if (version == null) {
- throw new PluginException("No plugin version property or package attribute available for " + pluginId);
- }
- } else {
- log.debug("Ignoring plugin '{}' version property in favor of package manifest", pluginId);
- }
-
- try {
- pluginVersion = new InstallableComponentVersion(version);
- } catch (final NumberFormatException e) {
- throw new PluginException(e);
- }
-
- final List<URL> urls = new ArrayList<>();
-
- for (Integer urlnum = 1; ; ++urlnum) {
-
- final String urlstr = pluginProperties.getProperty(PLUGIN_URL_PROPERTY + urlnum.toString());
- if (urlstr == null) {
- break;
- }
-
- try {
- urls.add(new URL(urlstr));
- } catch (final MalformedURLException e) {
- log.error("Unable to convert property value '{}' to URL", urlstr, e);
- }
- }
-
- urls.addAll(getDefaultUpdateURLs());
-
- updateURLs = CollectionSupport.copyToList(urls);
-
- requiredModules = CollectionSupport.copyToSet(StringSupport.normalizeStringCollection(
- StringSupport.stringToList(pluginProperties.getProperty(PLUGIN_REQ_MODULES_PROPERTY, ""), ",")));
-
- log.debug("Plugin {} loaded", getPluginId());
- }
-
- /** {@inheritDoc} */
- @Override
- @Nonnull @NotEmpty public String getPluginId() {
- if (pluginId != null) {
- return pluginId;
- }
- return super.getPluginId();
- }
-
- /** {@inheritDoc} */
- @Nonnull @NonnullElements @Unmodifiable @NotLive public List<URL> getUpdateURLs() {
- return updateURLs;
- }
-
- /** {@inheritDoc} */
- @Override
- @Nonnull @NonnullElements @Unmodifiable @NotLive public Set<String> getRequiredModules() {
- return requiredModules;
- }
-
- /** {@inheritDoc} */
- @Override
- @Nullable public String getLicenseFileLocation() {
- return pluginProperties.getProperty(PLUGIN_LICENSE_PROPERTY);
- }
-
- /** {@inheritDoc} */
- @NonNegative public int getMajorVersion() {
- assert pluginVersion != null;
- return pluginVersion.getMajor();
- }
-
- /** {@inheritDoc} */
- @NonNegative public int getMinorVersion() {
- assert pluginVersion != null;
- return pluginVersion.getMinor();
- }
-
- /** {@inheritDoc} */
- @NonNegative public int getPatchVersion() {
- assert pluginVersion != null;
- return pluginVersion.getPatch();
- }
-
- /**
- * Provides default update locations to use.
- *
- * @return default update locations
- * @throws PluginException if a derived class throws it (see derived classes)
- */
- @Nonnull @NonnullElements @Unmodifiable @NotLive protected List<URL> getDefaultUpdateURLs() throws PluginException {
- return CollectionSupport.emptyList();
+ super(properties);
}
}
\ No newline at end of file
diff --git a/idp-admin-api/src/test/java/net/shibboleth/idp/plugin/TestPlugin.java b/idp-admin-api/src/test/java/net/shibboleth/idp/plugin/TestPlugin.java
index 80dca1ab3..7892c3b08 100644
--- a/idp-admin-api/src/test/java/net/shibboleth/idp/plugin/TestPlugin.java
+++ b/idp-admin-api/src/test/java/net/shibboleth/idp/plugin/TestPlugin.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import net.shibboleth.idp.module.IdPModule;
import net.shibboleth.idp.module.TestModule;
import net.shibboleth.profile.module.ModuleException;
+import net.shibboleth.profile.plugin.PluginException;
import net.shibboleth.shared.collection.CollectionSupport;
/**
diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/FirstPartyIdPPlugin.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/FirstPartyIdPPlugin.java
index ec1443a70..11d755205 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/FirstPartyIdPPlugin.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/FirstPartyIdPPlugin.java
@@ -25,8 +25,8 @@ import java.util.List;
import javax.annotation.Nonnull;
import net.shibboleth.idp.plugin.IdPPlugin;
-import net.shibboleth.idp.plugin.PluginException;
import net.shibboleth.idp.plugin.PropertyDrivenIdPPlugin;
+import net.shibboleth.profile.plugin.PluginException;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotLive;
import net.shibboleth.shared.annotation.constraint.Unmodifiable;
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
index 03a204512..f3fe8d28b 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
@@ -36,8 +36,9 @@ import org.slf4j.Logger;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import net.shibboleth.idp.plugin.AbstractIdPPlugin;
+import net.shibboleth.idp.module.IdPModule;
import net.shibboleth.idp.plugin.IdPPlugin;
+import net.shibboleth.profile.plugin.AbstractPlugin;
import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.httpclient.HttpClientBuilder;
@@ -122,7 +123,7 @@ public class PluginInstallerTest extends BasePluginTest {
}
- public static class Wibble extends AbstractIdPPlugin {
+ public static class Wibble extends AbstractPlugin<IdPModule> {
/** {@inheritDoc} */
public @Nonnull String getPluginId() {
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 9a3896a87..df278aed1 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
@@ -25,13 +25,12 @@ import javax.annotation.Nonnull;
import org.springframework.core.io.ClassPathResource;
-import net.shibboleth.idp.plugin.AbstractIdPPlugin;
+import net.shibboleth.idp.module.IdPModule;
+import net.shibboleth.idp.plugin.IdPPlugin;
+import net.shibboleth.profile.plugin.AbstractPlugin;
import net.shibboleth.shared.collection.CollectionSupport;
-/**
- *
- */
-public class TestPlugin extends AbstractIdPPlugin {
+public class TestPlugin extends AbstractPlugin<IdPModule> implements IdPPlugin {
/** {@inheritDoc} */
@Override
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list