[java-identity-provider] 02/03: IDP-1523 Installer support for secrets.properties

Rod Widdowson rdw at steadingsoftware.com
Fri Dec 20 04:25:33 EST 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=396f6494e94787f2115ffb35c585b44248be22a9

commit 396f6494e94787f2115ffb35c585b44248be22a9
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Dec 20 09:24:16 2019 +0000

    IDP-1523 Installer support for secrets.properties
    
    https://issues.shibboleth.net/jira/browse/IDP-1523
---
 .../idp/installer/CurrentInstallState.java         |  7 +++-
 .../idp/installer/InstallerProperties.java         | 10 ++++-
 .../idp/installer/InstallerPropertiesImpl.java     |  8 ++++
 .../net/shibboleth/idp/installer/V4Install.java    | 46 ++++++++++++++++++----
 .../installer/impl/CurrentInstallStateImpl.java    |  9 +++++
 .../src/main/wix/scripts/shib_write_configs.vbs    | 15 ++++++-
 6 files changed, 84 insertions(+), 11 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 ad0e32a..82446b6 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
@@ -43,11 +43,16 @@ public interface CurrentInstallState extends InitializableComponent {
      */
     boolean isIdPPropertiesPresent();
 
-    /** Was ldapp.properties present in the target file when we started the install?
+    /** Was ldap.properties present in the target file when we started the install?
      * @return if it was.
      */
     boolean isLDAPPropertiesPresent();
  
+    /** Was secrets.properties present in the target file when we started the install?
+     * @return if it was.
+     */
+    boolean isSecretsPropertiesPresent();
+
     /** Get the properties associated with the current configuration.
      * This comes idp.properties and anything it points to via
      * {@value IdPPropertiesApplicationContextInitializer#IDP_ADDITIONAL_PROPERTY}.
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 4de3254..cbb7e13 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
@@ -118,7 +118,15 @@ public interface InstallerProperties extends InitializableComponent {
      */
     @Nullable public Path getLDAPMergeProperties() throws BuildException;
 
-    /** Get a directory to use to "pre-overlay" the conf directory.
+    /** Get the a file to merge with secrets.properties or null.
+    *
+    * @return the path or null if it none required.
+    * @throws BuildException  if badness happens
+    */
+   @Nullable public Path getSecretsMergeProperties() throws BuildException;
+
+
+   /** Get a directory to use to "pre-overlay" the conf directory.
      * Files will be copied from here if they don't already exist in conf,
      * <b>before</b> the files are copied from the distribution.
      * @return the path or null if non specified.
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 65893c0..2c71271 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
@@ -61,6 +61,9 @@ public class InstallerPropertiesImpl extends AbstractInitializableComponent impl
     /** The name of a property file to merge with ldap.properties. */
     public static final String LDAP_PROPERTIES_MERGE = "ldap.merge.properties";
 
+    /** The name of a property file to merge with ldap.properties. */
+    public static final String SECRETS_PROPERTIES_MERGE = "secrets.merge.properties";
+
     /** The name of a directory to overlay "under" the distribution conf. */
     public static final String CONF_PRE_OVERLAY = "idp.conf.preoverlay";
 
@@ -572,6 +575,11 @@ public class InstallerPropertiesImpl extends AbstractInitializableComponent impl
     }
 
     /** {@inheritDoc}. */
+    @Override public Path getSecretsMergeProperties() throws BuildException {
+        return getMergeFile(SECRETS_PROPERTIES_MERGE);
+    }
+
+    /** {@inheritDoc}. */
     @Override public Path getConfPreOverlay() throws BuildException {
         return getMergeFile(CONF_PRE_OVERLAY);
     }
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 f077903..11874a1 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
@@ -188,10 +188,6 @@ public class V4Install extends AbstractInitializableComponent {
      */
     private Properties getIdPReplacements(final boolean sealerCreated) {
         final Properties result = new Properties();
-        if (sealerCreated) {
-            result.setProperty("idp.sealer.storePassword", installerProps.getSealerPassword());
-            result.setProperty("idp.sealer.keyPassword", installerProps.getSealerPassword());
-        }
         result.setProperty("idp.entityID", installerProps.getEntityID());
         result.setProperty("idp.scope", installerProps.getScope());
         return result;
@@ -206,7 +202,7 @@ public class V4Install extends AbstractInitializableComponent {
     // 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");
+        final Path distConf = installerProps.getTargetDir().resolve("dist").resolve("conf");
         if (!currentState.isIdPPropertiesPresent()) {
             // We have to populate it
             try {
@@ -215,7 +211,7 @@ public class V4Install extends AbstractInitializableComponent {
                     throw new BuildException("Internal error - idp.properties");
                 }
                 final Path mergePath = installerProps.getIdPMergeProperties();
-                final Path source = dstConf.resolve("idp.properties");
+                final Path source = distConf.resolve("idp.properties");
                 if (!Files.exists(source)) {
                     throw new BuildException("missing idp.properties in dist");
                 }
@@ -249,7 +245,7 @@ public class V4Install extends AbstractInitializableComponent {
                 if (Files.exists(target)) {
                     throw new BuildException("Internal error - ldap.properties");
                 }
-                final Path source = dstConf.resolve("ldap.properties");
+                final Path source = distConf.resolve("ldap.properties");
                 if (!Files.exists(source)) {
                     throw new BuildException("missing ldap.properties in dist");
                 }
@@ -269,6 +265,42 @@ public class V4Install extends AbstractInitializableComponent {
             }
         }
 
+        if (sealerCreated) {
+            // We need to write the passwords to secrets.properties
+            try {
+                final Path target = conf.resolve("secrets.properties");
+                if (Files.exists(target)) {
+                    throw new BuildException("Internal error - secrets.properties");
+                }
+                final Path mergePath = installerProps.getSecretsMergeProperties();
+                final Path source = distConf.resolve("secrets.properties");
+                if (!Files.exists(source)) {
+                    throw new BuildException("missing secrets.properties in dist");
+                }
+                final PropertiesWithComments propertiesToReWrite = new PropertiesWithComments();
+                final Properties replacements;
+                if (mergePath != null) {
+                    log.debug("Creating {} from {} and {}", target, source, mergePath);
+                    replacements = new Properties();
+                    final File mergeFile = mergePath.toFile();
+                    if (!installerProps.isNoTidy()) {
+                        mergeFile.deleteOnExit();
+                    }
+                    replacements.load(new FileInputStream(mergeFile));
+                } else {
+                    replacements = new Properties(2);
+                    replacements .setProperty("idp.sealer.storePassword", installerProps.getSealerPassword());
+                    replacements .setProperty("idp.sealer.keyPassword", installerProps.getSealerPassword());
+                    log.debug("Creating {} from {} and {}", target, source, replacements.keySet());
+                }
+                propertiesToReWrite.load(new FileInputStream(source.toFile()));
+                propertiesToReWrite.replaceProperties(replacements);
+                propertiesToReWrite.store(new FileOutputStream(target.toFile()));
+            } catch (final IOException e) {
+                throw new BuildException("Failed to generate secrets.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");
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 bee55c4..eafbece 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
@@ -54,6 +54,9 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
     /** Whether the LDAP properties file exists.*/
     private boolean ldapPropertiesPresent;
 
+    /** Whether the secrets properties file exists.*/
+    private boolean secretsPropertiesPresent;
+
     /** Old Version. */
     private String oldVersion;
     
@@ -143,6 +146,7 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
         super.doInitialize();
         idpPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("idp.properties"));
         ldapPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("ldap.properties"));
+        secretsPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("secrets.properties"));
         findPreviousVersion();
         setupPreviousProps();
     }
@@ -163,6 +167,11 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
     }
 
     /** {@inheritDoc} */
+    public boolean isSecretsPropertiesPresent() {
+        return secretsPropertiesPresent;
+    }
+
+    /** {@inheritDoc} */
     @Nullable public Properties getCurrentlyInstalledProperties() {
         return props;
     }
diff --git a/idp-installer/src/main/wix/scripts/shib_write_configs.vbs b/idp-installer/src/main/wix/scripts/shib_write_configs.vbs
index 0140538..f180d4b 100644
--- a/idp-installer/src/main/wix/scripts/shib_write_configs.vbs
+++ b/idp-installer/src/main/wix/scripts/shib_write_configs.vbs
@@ -64,6 +64,7 @@ if (Err.Number = 0 ) then
     AntFile.WriteLine "idp.sealer.password=" & SealerPassword
     AntFile.WriteLine "idp.target.dir=" & InstallDirJava 
     AntFile.WriteLine "idp.merge.properties=idp.install.replace.properties"
+    AntFile.WriteLine "secrets.merge.properties=secrets.replace.properties"
     if (IdPScope <> "") then
        AntFile.WriteLine "idp.scope=" & IdPScope
     end if
@@ -87,8 +88,6 @@ if (Err.Number = 0 ) then
     PropsFile.WriteLine "# File to be merged into idp.properties"
     PropsFile.WriteLine "#"
     PropsFile.WriteLine "idp.entityID=https://" & Domain & "/idp"
-    PropsFile.WriteLine "idp.sealer.storePassword=" & SealerPassword
-    PropsFile.WriteLine "idp.sealer.keyPassword=" & SealerPassword
     if (IdPScope <> "") then
         PropsFile.WriteLine "idp.scope=" & IdPScope
     end if
@@ -97,6 +96,18 @@ else
     LogFile.Writeline "PropsFile failed " & Err & "  -  " & PropsFile
 end if
 
+set SecretsFile=FileSystemObj.OpenTextFile(InstallDir & "\secrets.replace.properties" , 2, True)
+if (Err.Number = 0 ) then
+    SecretsFile.WriteLine "#"
+    SecretsFile.WriteLine "# File to be merged into secrets.properties"
+    SecretsFile.WriteLine "#"
+    SecretsFile.WriteLine "idp.sealer.storePassword=" & SealerPassword
+    SecretsFile.WriteLine "idp.sealer.keyPassword=" & SealerPassword
+    SecretsFile.Close
+else
+    LogFile.Writeline "SecretsFile failed " & Err & "  -  " & SecretsFile
+end if
+
 if (InstallJetty <> "") then
     set JettyAntFile=FileSystemObj.OpenTextFile(InstallDir & "\jetty.install.properties" , 2, True)
     if (Err.Number = 0 ) then

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


More information about the commits mailing list