[java-identity-provider] 01/06: IDP-1452 Update services.properties for V3 to V4 updates

Rod Widdowson rdw at steadingsoftware.com
Thu Oct 24 12:00:30 EDT 2019


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=efbe536c2a7955779dd245a5c3eb530aeb8238db

commit efbe536c2a7955779dd245a5c3eb530aeb8238db
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Oct 21 16:52:54 2019 +0100

    IDP-1452 Update services.properties for V3 to V4 updates
    
    https://issues.shibboleth.net/jira/browse/IDP-1452
---
 .../idp/installer/CurrentInstallState.java         |  5 +++-
 .../net/shibboleth/idp/installer/V4Install.java    | 28 ++++++++++++++++++++--
 .../installer/impl/CurrentInstallStateImpl.java    |  2 +-
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
index addd684..1d7a616 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
@@ -26,8 +26,11 @@ import net.shibboleth.utilities.java.support.component.InitializableComponent;
 /** Tells the installers about the current install state. */
 public interface CurrentInstallState extends InitializableComponent {
 
+    /** What to return if this is V3. */
+    static final String V3_VERSION = "3";
+
     /** What is the installer version.
-     * @return "3" for a V3 install, null for a new install or the value we write during last install.
+     * @return {@value #V3_VERSION} for a V3 install, null for a new install or the value we wrote during last install.
      * @throws BuildException if we find an inconsistency
      */
     @Nullable String getInstalledVersion() throws BuildException;
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 350235b..ed6faa6 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
@@ -183,7 +183,7 @@ public class V4Install extends AbstractInitializableComponent {
      * @param sealerCreated have we just created a sealer
      * @throws BuildException if badness occurs
      */
-    // CheckStyle: CyclomaticComplexity OFF
+    // CheckStyle: CyclomaticComplexity|MethodLength OFF
     protected void populatePropertyFiles(final boolean sealerCreated) throws BuildException {
         final Path conf = installerProps.getTargetDir().resolve("conf");
         final Path dstConf = installerProps.getTargetDir().resolve("dist").resolve("conf");
@@ -219,6 +219,7 @@ public class V4Install extends AbstractInitializableComponent {
 
         final File ldapMergeFile = installerProps.getLDAPMergePropertiesFile();
         if (ldapMergeFile != null && !currentState.isLDAPPropertiesPresent() ) {
+            log.debug("Merging {} with ldap.properties", ldapMergePath);
             try {
                 final Path target = conf.resolve("ldap.properties");
                 if (Files.exists(target)) {
@@ -239,8 +240,31 @@ public class V4Install extends AbstractInitializableComponent {
                 throw new BuildException("Failed to generate ldap.properties", e);
             }
         }
+
+        if (CurrentInstallState.V3_VERSION.equals(currentState.getInstalledVersion())) {
+            log.debug("Detected a V3 to V4 update.  Editing services.properties");
+            final Path servicesProps = conf.resolve("services.properties");
+            if (!Files.exists(servicesProps)) {
+                log.warn("Previous Version V3 but no services.properties?");
+            } else {
+                try {
+                    // Handle services.properties for a 3->4 upgrade.
+                    final PropertiesWithComments propertiesToReWrite = new PropertiesWithComments();
+                    final File servicesPropsFile = servicesProps.toFile();
+                    propertiesToReWrite.load(new FileInputStream(servicesPropsFile));
+                    propertiesToReWrite.addComment(
+                            "idp.service.attribute.registry.resources modified during v3 upgrade "
+                            + Instant.now().toString());
+                    propertiesToReWrite.replaceProperty("idp.service.attribute.registry.resources",
+                            "shibboleth.LegacyAttributeRegistryResources");
+                    propertiesToReWrite.store(new FileOutputStream(servicesPropsFile));
+                } catch (final IOException e) {
+                    throw new BuildException("Failed to update services.properties", e);
+                }            
+            }
+        }
     }
-    // CheckStyle: CyclomaticComplexity ON
+    // CheckStyle: CyclomaticComplexity|MethodLength ON
 
     /** Create and populate (if it does not exist) edit-webapp.
      * @throws BuildException if badness occurs
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 8d44a9e..9bb3c82 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
@@ -73,7 +73,7 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
 
         final Path currentInstall = targetDir.resolve("dist").resolve(InstallerSupport.VERSION_NAME);
         if (!Files.exists(currentInstall)) {
-            oldVersion= "3";
+            oldVersion= V3_VERSION;
             return;
         }
         final Properties vers = new Properties(1);

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


More information about the commits mailing list