[java-identity-provider] branch main updated: IDP-1704 Installer needs to conditionally enable certain modules

Rod Widdowson rdw at steadingsoftware.com
Thu Jan 28 14:43:02 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=9788cc887b3f3cf429cbb98b79057f1caaec6d6e

The following commit(s) were added to refs/heads/main by this push:
       new  9788cc887 IDP-1704 Installer needs to conditionally enable certain modules
9788cc887 is described below

commit 9788cc887b3f3cf429cbb98b79057f1caaec6d6e
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jan 28 14:42:31 2021 +0000

    IDP-1704 Installer needs to conditionally enable certain modules
    
    https://issues.shibboleth.net/jira/browse/IDP-1704
---
 .../idp/installer/InstallerProperties.java         | 11 +++++++++
 .../idp/installer/InstallerPropertiesImpl.java     | 28 ++++++++++++++++++++++
 .../net/shibboleth/idp/installer/V4Install.java    | 12 ++++++++--
 3 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerProperties.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerProperties.java
index f118dfe7f..83705dc88 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerProperties.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerProperties.java
@@ -18,6 +18,7 @@
 package net.shibboleth.idp.installer;
 
 import java.nio.file.Path;
+import java.util.Set;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -30,6 +31,10 @@ import net.shibboleth.utilities.java.support.component.InitializableComponent;
  */
 public interface InstallerProperties extends InitializableComponent {
 
+    /** Those modules enabled by default. */
+    public static final Set<String> DEFAULT_MODULES = Set.of("idp.authn.Password",
+            "idp.intercept.Consent", "idp.admin.Hello");
+
     /** Get where we are installing/updating/building the war.
      * @return the target directory
      * @throws BuildException if something goes awry.
@@ -133,4 +138,10 @@ public interface InstallerProperties extends InitializableComponent {
      * @throws BuildException  if badness happens
      */
     @Nullable public Path getInitialEditWeb() throws BuildException;
+    /** Get the modules to enable after first install.
+     * @return the modules
+     */
+    @Nonnull public default Set<String> getModulesToEnable() {
+        return DEFAULT_MODULES;
+    }
 }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java
index 1d3d9babe..a05e82976 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java
@@ -25,9 +25,12 @@ import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.function.Supplier;
 
 import javax.annotation.Nonnull;
@@ -46,6 +49,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterI
 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.primitive.StringSupport;
 
 /** Class implement {@link InstallerProperties} with properties/UI driven values.
 
@@ -117,6 +121,10 @@ public class InstallerPropertiesImpl extends AbstractInitializableComponent impl
     /** Whether to tidy up after ourselves. */
     public static final String NO_TIDY = "idp.no.tidy";
 
+    /** Which modules to enable on initial install.
+     * @since 4.1.0 */
+    public static final String INITIAL_INSTALL_MODULES = "idp.initial.modules";
+
     /** Whether to tidy up after ourselves. */
     public static final int DEFAULT_KEY_SIZE = 3072;
 
@@ -507,6 +515,26 @@ public class InstallerPropertiesImpl extends AbstractInitializableComponent impl
         return sealerPassword;
     }
 
+    /** {@inheritDoc} */
+    @Override @Nonnull public Set<String> getModulesToEnable() {
+        String prop = StringSupport.trimOrNull(installerProperties.getProperty(INITIAL_INSTALL_MODULES));
+        if (prop == null) {
+            return InstallerProperties.DEFAULT_MODULES;
+        }
+        final boolean additive = prop.startsWith("+");
+        if (additive) {
+            prop = prop.substring(1);
+        }
+        final String[] modules = prop.split(",");
+        if (!additive) {
+            return Set.copyOf(Arrays.asList(modules));
+        }
+        final Set<String> result = new HashSet<>(modules.length + InstallerProperties.DEFAULT_MODULES.size());
+        result.addAll(InstallerProperties.DEFAULT_MODULES);
+        result.addAll(Arrays.asList(modules));
+        return result;
+    }
+
     /** {@inheritDoc}. */
     @Nonnull public String getSealerAlias() {
         if (sealerAlias == null) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
index ddc829c43..a730bb4c9 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
@@ -112,7 +112,7 @@ public class V4Install extends AbstractInitializableComponent {
         populatePropertyFiles(keyManager.isCreatedSealer());
         handleEditWebApp();
         populateUserDirectories();
-        reEnableModules();
+        enableModules();
         deleteSpuriousFiles();
         generateMetadata();
         reprotect();
@@ -398,7 +398,7 @@ public class V4Install extends AbstractInitializableComponent {
     /** ReEnable modules which were already enabled.
      * @throws BuildException if badness occurs
      */
-    protected void reEnableModules() throws BuildException {
+    protected void enableModules() throws BuildException {
         final ModuleContext moduleContext = new ModuleContext(installerProps.getTargetDir());
         final Iterator<IdPModule> modules = ServiceLoader.load(IdPModule.class).iterator();
 
@@ -415,6 +415,14 @@ public class V4Install extends AbstractInitializableComponent {
                         throw new BuildException(e);
                     }
                 }
+                if (currentState.getInstalledVersion() == null && installerProps.getModulesToEnable().contains(id)) {
+                    try {
+                        module.enable(moduleContext);
+                    } catch (final ModuleException e) {
+                        log.error("Error {erforming initial enable on module {}", id, e);
+                        throw new BuildException(e);
+                    }
+                }
             } catch (final ServiceConfigurationError e) {
                 log.error("Error loading modules", e);
             }

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


More information about the commits mailing list