[java-identity-provider] 01/01: IDP-1772 Plugin installation should output module operations
Rod Widdowson
rdw at steadingsoftware.com
Sun May 2 10:08:10 UTC 2021
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch dev/IDP-1772
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=086b34e8ee9f6cb40b60498e5a3d9796390a73eb
commit 086b34e8ee9f6cb40b60498e5a3d9796390a73eb
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun May 2 11:06:31 2021 +0100
IDP-1772 Plugin installation should output module operations
https://issues.shibboleth.net/jira/browse/IDP-1772
---
.../idp/installer/plugin/impl/PluginInstaller.java | 74 ++++++++++++++++++++--
.../plugin/impl/RollbackPluginInstall.java | 28 ++++++--
.../idp/installer/plugin/impl/PluginCLITest.java | 4 +-
.../idp/installer/plugin/impl/RollbackTester.java | 5 +-
4 files changed, 97 insertions(+), 14 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 59b84ace0..230128dc9 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
@@ -34,9 +34,12 @@ import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.Properties;
import java.util.ServiceConfigurationError;
@@ -73,6 +76,8 @@ import net.shibboleth.idp.installer.plugin.impl.TrustStore.Signature;
import net.shibboleth.idp.module.IdPModule;
import net.shibboleth.idp.module.ModuleContext;
import net.shibboleth.idp.module.ModuleException;
+import net.shibboleth.idp.module.IdPModule.ModuleResource;
+import net.shibboleth.idp.module.IdPModule.ResourceResult;
import net.shibboleth.idp.plugin.IdPPlugin;
import net.shibboleth.idp.plugin.PluginVersion;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
@@ -145,6 +150,9 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
/** The Module Context. */
@NonnullAfterInit private ModuleContext moduleContext;
+ /** Module Changes.*/
+ private final Map<ModuleResource,ResourceResult> moduleChanges = new HashMap<>();
+
/** The "plugins" classpath loader. AutoClosed. */
private URLClassLoader installedPluginsLoader;
@@ -263,7 +271,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
description.getMajorVersion(),description.getMinorVersion(), description.getPatchVersion());
final Set<String> loadedModules = getLoadedModules();
- try (final RollbackPluginInstall rollBack = new RollbackPluginInstall(moduleContext)) {
+ try (final RollbackPluginInstall rollBack = new RollbackPluginInstall(moduleContext, moduleChanges)) {
uninstallOld(rollBack);
checkRequiredModules(loadedModules);
@@ -281,6 +289,8 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
throw new BuildException(e);
}
builder.execute();
+
+ emitModuleChanges();
}
/** Remove the jars for this plugin and rebuild the war.
@@ -292,10 +302,10 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
if (description == null) {
LOG.warn("Description for {} not found", pluginId);
} else {
- try (final RollbackPluginInstall rollback = new RollbackPluginInstall(moduleContext)){
+ try (final RollbackPluginInstall rollback = new RollbackPluginInstall(moduleContext, moduleChanges)){
for (final IdPModule module: description.getDisableOnRemoval()) {
moduleId = module.getId();
- module.disable(moduleContext, false);
+ captureChanges(module.disable(moduleContext, false));
rollback.getModulesDisabled().add(module);
}
rollback.completed();
@@ -332,6 +342,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
LOG.info("Removed resources for {} from the war", pluginId);
}
pluginsContents.resolve(pluginId).toFile().deleteOnExit();
+ emitModuleChanges();
}
/** Get hold of the {@link IdPPlugin} for this plugin.
@@ -421,7 +432,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
final IdPModule module = modules.next();
if (pluginId.equals(module.getOwnerId()) && loadedModules.contains(module.getId())) {
LOG.debug("Re-enabling module {}", module.getId());
- module.enable(moduleContext);
+ captureChanges(module.enable(moduleContext));
} else {
LOG.debug("Not re-enabling module {}, not provided by this plugin", module.getId());
}
@@ -449,7 +460,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
for (final IdPModule module: description.getEnableOnInstall()) {
moduleId = module.getId();
if (!module.isEnabled(moduleContext)) {
- module.enable(moduleContext);
+ captureChanges(module.enable(moduleContext));
rollBack.getModulesEnabled().add(module);
}
}
@@ -568,6 +579,59 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
}
}
+ /** Capture module changes.
+ * @param changes what has changed */
+ private void captureChanges(final Map<ModuleResource,ResourceResult> changes) {
+ for (final Entry<ModuleResource, ResourceResult> entry: changes.entrySet()) {
+ moduleChanges.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /** Emit module changes. */
+ private void emitModuleChanges() {
+ if (!moduleChanges.isEmpty()) {
+ LOG.info("Module file changes as a result of this install");
+ moduleChanges.forEach(this::doReportOperation);
+ }
+ }
+
+ /**
+ * Report on a resource result.
+ *
+ * @param resource resource
+ * @param result result of operation
+ */
+ private void doReportOperation(@Nonnull final ModuleResource resource, @Nonnull final ResourceResult result) {
+ final String dest = resource.getDestination().toString();
+ switch (result) {
+ case CREATED:
+ LOG.info("\t{} created", dest);
+ break;
+
+ case REPLACED:
+ LOG.info("\t{} replaced, {}.idpsave created", dest, dest);
+ break;
+
+ case ADDED:
+ LOG.info("\t{}.idpnew created", dest);
+ break;
+
+ case REMOVED:
+ LOG.info("\t{} removed", dest);
+ break;
+
+ case SAVED:
+ LOG.info("\t{} renamed to, {}.idpsave", dest, dest);
+ break;
+
+ case MISSING:
+ LOG.info("\t{} missing, nothing to do", dest);
+ break;
+
+ default:
+ }
+ }
+
/** Download helper method.
* @param baseResource where to go for the file
* @param fileName the file name
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java
index a8b2b3fdb..eaf723e70 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java
@@ -28,6 +28,8 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.annotation.Nonnull;
@@ -35,6 +37,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.shibboleth.idp.module.IdPModule;
+import net.shibboleth.idp.module.IdPModule.ModuleResource;
+import net.shibboleth.idp.module.IdPModule.ResourceResult;
import net.shibboleth.idp.module.ModuleContext;
import net.shibboleth.idp.plugin.IdPPlugin;
import net.shibboleth.utilities.java.support.annotation.constraint.Live;
@@ -64,12 +68,18 @@ public class RollbackPluginInstall implements AutoCloseable {
/** The {@link ModuleContext} that the module subsystem needs.*/
@Nonnull private final ModuleContext moduleContext;
+ /** Module Changes.*/
+ @Nonnull private final Map<ModuleResource, ResourceResult> moduleChanges;
+
/**
* Constructor.
* @param context The Module Context
+ * @param changes Where to capture module changes
*/
- public RollbackPluginInstall(final ModuleContext context) {
- moduleContext = Constraint.isNotNull(context, "Module context should ne non null");
+ public RollbackPluginInstall(final @Nonnull ModuleContext context,
+ final @Nonnull Map<ModuleResource, ResourceResult> changes) {
+ moduleContext = Constraint.isNotNull(context, "Module context should be non null");
+ moduleChanges = Constraint.isNotNull(changes, "Module changes should be non null");
}
/** What was enabled?
@@ -111,7 +121,7 @@ public class RollbackPluginInstall implements AutoCloseable {
final IdPModule module = modulesEnabled.get(i);
try {
log.trace("Deleting {}", module.getId());
- module.disable(moduleContext, false);
+ captureChanges(module.disable(moduleContext, false));
} catch (final Throwable t) {
log.error("Could not disable {}: ", module.getId(), t);
}
@@ -130,7 +140,7 @@ public class RollbackPluginInstall implements AutoCloseable {
final IdPModule module = modulesDisabled.get(i);
try {
log.trace("Deleting {}", module.getId());
- module.enable(moduleContext);
+ captureChanges(module.enable(moduleContext));
} catch (final Throwable t) {
log.error("Could not disable {}, continuing ", module.getId(), t);
}
@@ -157,7 +167,7 @@ public class RollbackPluginInstall implements AutoCloseable {
}
return true;
}
-
+
/** Traverse the {@link #filesRenamedAway} list copying the files back.
* @return true if we did any work.
*/
@@ -180,6 +190,14 @@ public class RollbackPluginInstall implements AutoCloseable {
return true;
}
+ /** Capture module changes.
+ * @param changes what has changed
+ */
+ private void captureChanges(final Map<ModuleResource,ResourceResult> changes) {
+ for (final Entry<ModuleResource, ResourceResult> entry: changes.entrySet()) {
+ moduleChanges.put(entry.getKey(), entry.getValue());
+ }
+ }
/** Perform the rollback. This is done in reverse order from the install,
* which is to say the the lists are iterated over backwards and the order is
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 dc5d546a3..55099ee82 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
@@ -40,9 +40,9 @@ import net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder;
@SuppressWarnings("javadoc")
public class PluginCLITest extends BasePluginTest {
- private final String PLUGIN_DISTRO = "https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/scripting/idp-plugin-rhino-dist/1.0.0/idp-plugin-rhino-dist-1.0.0.tar.gz";
+ private final String PLUGIN_DISTRO = "https://shibboleth.net/downloads/identity-provider/plugins/totp/1.0.0/idp-plugin-totp-dist-1.0.0.tar.gz";
- private final String PLUGIN_ID = "net.shibboleth.idp.plugin.rhino";
+ private final String PLUGIN_ID = "net.shibboleth.idp.plugin.authn.totp";
@BeforeSuite public void setUp() throws IOException
{
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java
index 10b0d93ad..d13a58072 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java
@@ -23,6 +23,7 @@ import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.HashMap;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -79,7 +80,7 @@ public class RollbackTester {
assertFalse(disabled1.isEnabled(null));
assertFalse(disabled2.isEnabled(null));
- try (final RollbackPluginInstall rp = new RollbackPluginInstall(new ModuleContext(parent))) {
+ try (final RollbackPluginInstall rp = new RollbackPluginInstall(new ModuleContext(parent), new HashMap<>())) {
rp.getFilesCopied().add(copied);
rp.getFilesRenamedAway().add(renamed);
rp.getModulesDisabled().add(disabled1);
@@ -90,7 +91,7 @@ public class RollbackTester {
rp.completed();
}
}
-
+
if (commit) {
assertTrue(enabled1.isEnabled(null));
assertTrue(enabled2.isEnabled(null));
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list