[java-identity-provider] 03/03: IDP-2103 Redo installer to accomodate new layout

Rod Widdowson rdw at steadingsoftware.com
Sat May 13 12:28:15 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=2be1a8ffdde064f3230d9ec0fe975d45647a4b53

commit 2be1a8ffdde064f3230d9ec0fe975d45647a4b53
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat May 13 13:27:05 2023 +0100

    IDP-2103 Redo installer to accomodate new layout
    
    https://shibboleth.atlassian.net/browse/IDP-2103
    
    Copy much less from the distribution and rely much more on modules.
---
 .../shibboleth/idp/installer/CopyDistribution.java |   6 +-
 .../idp/installer/InstallerProperties.java         |  15 ++-
 .../idp/installer/InstallerPropertiesImpl.java     |   2 +-
 .../net/shibboleth/idp/installer/V4Install.java    | 138 +++++++--------------
 .../installer/impl/CurrentInstallStateImpl.java    |   5 +-
 5 files changed, 64 insertions(+), 102 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java
index 96c5c1951..a245f5eb4 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java
@@ -145,10 +145,6 @@ public final class CopyDistribution extends AbstractInitializableComponent {
             log.error("Source distribution {} not found.", src);
             throw new BuildException("Source distribution not found");
         }
-        distCopy(src, dist, "conf");
-        distCopy(src, dist, "flows");
-        distCopy(src, dist, "messages");
-        distCopy(src, dist, "views");
         distCopy(src, dist, "webapp");
     }
 
@@ -156,7 +152,7 @@ public final class CopyDistribution extends AbstractInitializableComponent {
      * @throws BuildException if badness occurs
      */
     protected void copyBinDocSystem() {
-        distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "bin", true);
+        distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "bin/lib", true);
         distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "doc");
         if (installState.isSystemPresent()) {
             distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "system");
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 4e8935891..9b724609b 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
@@ -32,8 +32,12 @@ import net.shibboleth.shared.component.InitializableComponent;
  */
 public interface InstallerProperties extends InitializableComponent {
 
+    /** Those modules which are "core". */
+    @Nonnull public static final Set<String> CORE_MODULES = CollectionSupport.setOf("idp.Core");
+
     /** Those modules enabled by default. */
-    @Nonnull public static final Set<String> DEFAULT_MODULES = CollectionSupport.setOf("idp.Core", "idp.authn.Password", "idp.admin.Hello");
+    @Nonnull public static final Set<String> DEFAULT_MODULES = CollectionSupport.setOf("idp.EditWebApp",
+            "idp.CommandLine" ,"idp.authn.Password", "idp.admin.Hello");
 
     /** Get where we are installing/updating/building the war.
      * @return the target directory
@@ -138,10 +142,19 @@ 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;
     }
+
+    /** Get the modules to enable before ant install.
+     * @return the modules
+     */
+    @Nonnull public default Set<String> getCoreModules() {
+        return CORE_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 12ba8d382..f41b10550 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
@@ -57,7 +57,7 @@ import net.shibboleth.shared.primitive.StringSupport;
 
 */
 public class InstallerPropertiesImpl extends AbstractInitializableComponent implements InstallerProperties {
-    
+
     /** The base directory, inherited and shared with ant. */
     public static final String ANT_BASE_DIR = Launcher.ANTHOME_PROPERTY;
 
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 a6aa6f673..186aaf095 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
@@ -39,7 +39,6 @@ import java.util.regex.Pattern;
 import javax.annotation.Nonnull;
 
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.taskdefs.Copy;
 import org.slf4j.Logger;
 import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.ConfigurableApplicationContext;
@@ -118,12 +117,10 @@ public class V4Install extends AbstractInitializableComponent {
         checkComponentActive();
         handleVersioning();
         checkPreConditions();
-
-        createUserDirectories();
+        enableCoreModules();
         keyManager.execute();
         populatePropertyFiles(keyManager.isCreatedSealer());
-        handleEditWebApp();
-        populateUserDirectories();
+        checkWebXml(installerProps.getTargetDir().resolve("edit-webapp").resolve("WEB-INF").resolve("web.xml"));
         enableModules();
         deleteSpuriousFiles();
         generateMetadata();
@@ -155,7 +152,7 @@ public class V4Install extends AbstractInitializableComponent {
             }
         }
         final String versionAsString = Version.getVersion();
-        final PluginVersion idpVersion = new PluginVersion(versionAsString!=null?versionAsString:"4.2.0");
+        final PluginVersion idpVersion = new PluginVersion(versionAsString!=null?versionAsString:"5.0.0");
         for (final IdPPlugin plugin: ServiceLoader.load(IdPPlugin.class, currentState.getInstalledPluginsLoader())) {
             final String pluginId = plugin.getPluginId();
             final PluginVersion pluginVersion = new PluginVersion(plugin);
@@ -207,22 +204,6 @@ public class V4Install extends AbstractInitializableComponent {
         }
     }
 
-    /** Create (if they do not exist) the user editable folders, suitable for
-     * later population during update or install.
-     * @throws BuildException if badness occurs
-     */
-    protected void createUserDirectories() throws BuildException {
-        final Path target = installerProps.getTargetDir();
-        InstallerSupport.createDirectory(target.resolve("conf"));
-        InstallerSupport.createDirectory(target.resolve("credentials"));
-        InstallerSupport.createDirectory(target.resolve("flows"));
-        InstallerSupport.createDirectory(target.resolve("logs"));
-        InstallerSupport.createDirectory(target.resolve("messages"));
-        InstallerSupport.createDirectory(target.resolve("metadata"));
-        InstallerSupport.createDirectory(target.resolve("views"));
-        InstallerSupport.createDirectory(target.resolve("war"));
-    }
-    
     /** Create the properties we need to replace when we merge idp.properties.
      * @param sealerCreated have we just created a sealer
      * @return what we need to replace
@@ -250,23 +231,18 @@ public class V4Install extends AbstractInitializableComponent {
                 "idp.attribute.resolver.LDAP.bindDNCredential",
                 "idp.persistentId.salt");
         final Path conf = installerProps.getTargetDir().resolve("conf");
-        final Path dstConf = installerProps.getTargetDir().resolve("dist").resolve("conf");
         if (!currentState.isIdPPropertiesPresent()) {
             // We have to populate it
             try {
                 final Path target = conf.resolve("idp.properties");
-                if (Files.exists(target)) {
-                    throw new BuildException("Internal error - idp.properties");
+                if (!Files.exists(target)) {
+                   throw new BuildException("idp.properties didnt exist.  Was irp.Core installed");
                 }
                 final Path mergePath = installerProps.getIdPMergeProperties();
-                final Path source = dstConf.resolve("idp.properties");
-                if (!Files.exists(source)) {
-                    throw new BuildException("missing idp.properties in dist");
-                }
                 final PropertiesWithComments propertiesToReWrite = new PropertiesWithComments(doNotReplaceList);
                 final Properties replacements;
                 if (mergePath != null) {
-                    log.debug("Creating {} from {} and {}", target, source, mergePath);
+                    log.debug("Updating {} from ", target, mergePath);
                     replacements = new Properties();
                     final File mergeFile = mergePath.toFile();
                     if (!installerProps.isNoTidy()) {
@@ -277,9 +253,9 @@ public class V4Install extends AbstractInitializableComponent {
                     }
                 } else {
                     replacements = getIdPReplacements(sealerCreated);
-                    log.debug("Creating {} from {} and {}", target, source, replacements.keySet());
+                    log.debug("Updating {} from {}", target, replacements.keySet());
                 }
-                try (final FileInputStream stream = new FileInputStream(source.toFile())) {
+                try (final FileInputStream stream = new FileInputStream(target.toFile())) {
                     propertiesToReWrite.load(stream);
                 }
                 propertiesToReWrite.replaceProperties(replacements);
@@ -287,7 +263,7 @@ public class V4Install extends AbstractInitializableComponent {
                     propertiesToReWrite.store(stream);
                 }
             } catch (final IOException e) {
-                throw new BuildException("Failed to generate idp.properties", e);
+                throw new BuildException("Failed to regenerate idp.properties", e);
             }
         }
 
@@ -296,14 +272,10 @@ public class V4Install extends AbstractInitializableComponent {
             log.debug("Merging {} with ldap.properties", ldapMergePath);
             try {
                 final Path target = conf.resolve("ldap.properties");
-                if (Files.exists(target)) {
-                    throw new BuildException("Internal error - ldap.properties");
-                }
-                final Path source = dstConf.resolve("ldap.properties");
-                if (!Files.exists(source)) {
-                    throw new BuildException("missing ldap.properties in dist");
+                if (!Files.exists(target)) {
+                    throw new BuildException("Internal error - ldap.properties doesnt exist ?");
                 }
-                log.debug("Creating {} from {} and {}", target, source, ldapMergePath);
+                log.debug("Updating {} from {}", target, ldapMergePath);
                 final PropertiesWithComments propertiesToReWrite = new PropertiesWithComments(doNotReplaceList);
                 final Properties replacements = new Properties();
                 final File mergeFile = ldapMergePath.toFile();
@@ -313,7 +285,7 @@ public class V4Install extends AbstractInitializableComponent {
                 try (final FileInputStream stream = new FileInputStream(mergeFile)) {
                     replacements.load(stream);
                 }
-                try (final FileInputStream stream = new FileInputStream(source.toFile())) {
+                try (final FileInputStream stream = new FileInputStream(target.toFile())) {
                     propertiesToReWrite.load(stream);
                 }
                 propertiesToReWrite.replaceProperties(replacements);
@@ -321,7 +293,7 @@ public class V4Install extends AbstractInitializableComponent {
                     propertiesToReWrite.store(stream);
                 }
             } catch (final IOException e) {
-                throw new BuildException("Failed to generate ldap.properties", e);
+                throw new BuildException("Failed to regenerate ldap.properties", e);
             }
         }
 
@@ -374,42 +346,6 @@ public class V4Install extends AbstractInitializableComponent {
     }
     // CheckStyle: CyclomaticComplexity|MethodLength ON
 
-    /** Create and populate (if it does not exist) edit-webapp.
-     * @throws BuildException if badness occurs
-     */
-    protected void handleEditWebApp() throws BuildException {
-        final Path editWebApp = installerProps.getTargetDir().resolve("edit-webapp");
-        final Path css = editWebApp.resolve("css");
-        final Path images = editWebApp.resolve("images");
-        final Path distEditWebApp =  installerProps.getTargetDir().resolve("dist").resolve("webapp");
-
-        if (Files.exists(editWebApp)) {
-            checkWebXml(editWebApp.resolve("WEB-INF").resolve("web.xml"));
-            InstallerSupport.copyDirIfNotPresent(distEditWebApp.resolve("css"), css);
-            InstallerSupport.copyDirIfNotPresent(distEditWebApp.resolve("images"), images);
-            return;
-        }
-        final Path suppliedInput = installerProps.getInitialEditWeb();
-        if (suppliedInput != null) {
-            final Copy copy = InstallerSupport.getCopyTask(suppliedInput, editWebApp);
-            copy.setFailOnError(false);
-            copy.execute();
-        } else {
-            InstallerSupport.createDirectory(editWebApp);
-            InstallerSupport.createDirectory(css);
-            InstallerSupport.createDirectory(images);
-            InstallerSupport.createDirectory(editWebApp.resolve("WEB-INF"));
-            InstallerSupport.createDirectory(editWebApp.resolve("WEB-INF").resolve("lib"));
-            InstallerSupport.createDirectory(editWebApp.resolve("WEB-INF").resolve("classes"));
-            final Copy cssCopy = InstallerSupport.getCopyTask(distEditWebApp.resolve("css"), css);
-            cssCopy.setFailOnError(false);
-            cssCopy.execute();
-            final Copy imagesCopy = InstallerSupport.getCopyTask(distEditWebApp.resolve("images"), images);
-            imagesCopy.setFailOnError(false);
-            imagesCopy.execute();
-        }
-    }
-
     /** If it exists check web.xml for deprecated content.
      * @param webXml the path of the file
      * We do this in a very simplistic fashion at first
@@ -438,29 +374,45 @@ public class V4Install extends AbstractInitializableComponent {
         }
     }
 
-    /** Create and populate (if they not exist) the "user visible" folders.
-     * (conf, flows, messages, views, logs)
+    /** Enable Core modules if this is a new install
      * @throws BuildException if badness occurs
      */
-    protected void populateUserDirectories() throws BuildException {
-        final Path targetBase = installerProps.getTargetDir();
-        final Path distBase = targetBase.resolve("dist");
-        final Path preConfPath = installerProps.getConfPreOverlay();
-        if (preConfPath != null) {
-            InstallerSupport.copyDirIfNotPresent(preConfPath, targetBase.resolve("conf"));
-        }
-        InstallerSupport.copyDirIfNotPresent(distBase.resolve("conf"), targetBase.resolve("conf"));
-        InstallerSupport.copyDirIfNotPresent(distBase.resolve("flows"), targetBase.resolve("flows"));
-        InstallerSupport.copyDirIfNotPresent(distBase.resolve("views"), targetBase.resolve("views"));
-        InstallerSupport.copyDirIfNotPresent(distBase.resolve("messages"), targetBase.resolve("messages"));
-        InstallerSupport.createDirectory(targetBase.resolve("logs"));
+    protected void enableCoreModules() throws BuildException {
+        if (currentState.getInstalledVersion() != null) {
+            // Not an initial install
+            return;
+        }
+        final String targetDir = installerProps.getTargetDir().toString();
+        assert targetDir!=null;
+        final ModuleContext moduleContext = new ModuleContext(targetDir);
+        final Iterator<IdPModule> modules = ServiceLoader.load(IdPModule.class).iterator();
+
+        while (modules.hasNext()) {
+            try {
+                final IdPModule module = modules.next();
+                final String id = module.getId();
+                if (currentState.getInstalledVersion() == null && installerProps.getCoreModules().contains(id)) {
+                    try {
+                        module.enable(moduleContext);
+                    } catch (final ModuleException e) {
+                        log.error("Error performing initial enable on module {}", id, e);
+                        throw new BuildException(e);
+                    }
+                }
+            } catch (final ServiceConfigurationError e) {
+                log.error("Error loading modules", e);
+            }
+        }
     }
+
     
     /** ReEnable modules which were already enabled.
      * @throws BuildException if badness occurs
      */
     protected void enableModules() throws BuildException {
-        final ModuleContext moduleContext = new ModuleContext(installerProps.getTargetDir().toString());
+        final String targetDir = installerProps.getTargetDir().toString();
+        assert targetDir!=null;
+        final ModuleContext moduleContext = new ModuleContext(targetDir);
         final Iterator<IdPModule> modules = ServiceLoader.load(IdPModule.class).iterator();
 
         while (modules.hasNext()) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
index 492cee600..2151a7423 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
@@ -109,9 +109,10 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
     private void findPreviousVersion() throws ComponentInitializationException {
         final Path conf = targetDir.resolve("conf");
         final Path currentInstall = targetDir.resolve("dist").resolve(InstallerSupport.VERSION_NAME);
-        if (!Files.exists(conf.resolve("relying-party.xml"))) {
+        final Path rp = conf.resolve("relying-party.xml");
+        if (!Files.exists(rp)) {
             // No relying party, no install
-            log.debug("No relying-party.xml file detetected.  Inferring a clean install");
+            log.debug("No relying-party.xml file detetected at {} .  Inferring a clean install", rp);
             oldVersion = null;
         } else if (!Files.exists(conf.resolve("idp.properties"))) {
             throw new ComponentInitializationException("V2 Installation detected");

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


More information about the commits mailing list