[java-identity-provider] 02/02: IDP-1513 Policy properties files for V2 support values

Rod Widdowson rdw at steadingsoftware.com
Sun Oct 27 10:48:28 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=fe816c7d936ffc356480c78a33f620a8d03438ee

commit fe816c7d936ffc356480c78a33f620a8d03438ee
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Oct 27 14:43:48 2019 +0000

    IDP-1513 Policy properties files for V2 support values
    
    https://issues.shibboleth.net/jira/browse/IDP-1513
---
 .../idp/installer/CurrentInstallState.java         | 10 +++++
 .../net/shibboleth/idp/installer/V4Install.java    | 29 +++++++++++++
 .../installer/impl/CurrentInstallStateImpl.java    | 49 ++++++++++++++++++++++
 3 files changed, 88 insertions(+)

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 1d7a616..ad0e32a 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
@@ -17,10 +17,13 @@
 
 package net.shibboleth.idp.installer;
 
+import java.util.Properties;
+
 import javax.annotation.Nullable;
 
 import org.apache.tools.ant.BuildException;
 
+import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
 import net.shibboleth.utilities.java.support.component.InitializableComponent;
 
 /** Tells the installers about the current install state. */
@@ -44,4 +47,11 @@ public interface CurrentInstallState extends InitializableComponent {
      * @return if it was.
      */
     boolean isLDAPPropertiesPresent();
+ 
+    /** Get the properties associated with the current configuration.
+     * This comes idp.properties and anything it points to via
+     * {@value IdPPropertiesApplicationContextInitializer#IDP_ADDITIONAL_PROPERTY}.
+     * @return the properties, or null if this is a new install.
+     */
+    @Nullable Properties getCurrentlyInstalledProperties();
 }
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 bc99af3..b904b5e 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
@@ -46,6 +46,7 @@ import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
 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;
 import net.shibboleth.utilities.java.support.security.BasicKeystoreKeyStrategyTool;
 import net.shibboleth.utilities.java.support.security.SelfSignedCertificateGenerator;
 
@@ -95,6 +96,7 @@ public class V4Install extends AbstractInitializableComponent {
     public void execute() throws BuildException {
         ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
         handleVersioning();
+        checkPreConditions();
 
         createUserDirectories();
         keyManager.execute();
@@ -115,6 +117,33 @@ public class V4Install extends AbstractInitializableComponent {
         ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
         metadataGenerator = what;
     }
+    
+    /** Check for any preconditions to the install. 
+     * @throws BuildException if one is broken.
+     */
+    protected void checkPreConditions() throws BuildException {
+        final Properties props = currentState.getCurrentlyInstalledProperties();
+        if (props != null) {
+            String value =StringSupport.trimOrNull(props.getProperty("idp.service.relyingparty.resources"));
+            if ("shibboleth.RelyingPartyResolverResources".equals(value)) {
+                log.error("Install failed: system will not work after V4 upgrade");
+                log.error("idp.service.relyingparty.resources is set to shibboleth.RelyingPartyResolverResources");
+                throw new BuildException("Install failed: system will not work after V4 upgrade");
+            }
+            value = StringSupport.trimOrNull(props.getProperty("idp.nameid.saml1.legacyGenerator"));
+            if ("shibboleth.LegacySAML1NameIdentifierGenerator".equals(value)) {
+                log.error("Install failed: system will not work after V4 upgrade");
+                log.error("idp.nameid.saml1.legacyGenerator is set to shibboleth.LegacySAML1NameIdentifierGenerator");
+                throw new BuildException("Install failed: system will not work after V4 upgrade");
+            }
+            value = StringSupport.trimOrNull(props.getProperty("idp.nameid.saml2.legacyGenerator"));
+            if ("shibboleth.LegacySAML2NameIDGenerator".equals(value)) {
+                log.error("Install failed: system will not work after V4 upgrade");
+                log.error("idp.nameid.saml2.legacyGenerator is set to shibboleth.LegacySAML2NameIDGenerator");
+                throw new BuildException("Install failed: system will not work after V4 upgrade");                
+            }
+        }
+    }
 
     /** Report the to be installed and (if there is one) current versions. 
      * Write to be installed version to the dist folder.
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 93a820a..bee55c4 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
@@ -17,8 +17,10 @@
 
 package net.shibboleth.idp.installer.impl;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Properties;
@@ -32,8 +34,10 @@ import org.slf4j.LoggerFactory;
 import net.shibboleth.idp.installer.CurrentInstallState;
 import net.shibboleth.idp.installer.InstallerProperties;
 import net.shibboleth.idp.installer.InstallerSupport;
+import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /** Tells the installers about the current install state. */
 public final class CurrentInstallStateImpl extends AbstractInitializableComponent implements CurrentInstallState {
@@ -52,6 +56,9 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
 
     /** Old Version. */
     private String oldVersion;
+    
+    /** Previous props. */
+    private Properties props;
 
     /** Constructor.
      * @param installerProps the installer situation.
@@ -95,12 +102,49 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
         }
     }
 
+    /** Populate {{@link #props} from idp.properties and other files pointed to by
+     * {@value IdPPropertiesApplicationContextInitializer#IDP_ADDITIONAL_PROPERTY}.
+     */
+    private void setupPreviousProps() {
+        if (!isIdPPropertiesPresent()) {
+            return ;
+        }
+        props = new Properties();
+        try {
+            final File idpPropsFile = targetDir.resolve("conf").resolve("idp.properties").toFile();
+            final InputStream idpPropsStream = new FileInputStream(idpPropsFile);
+            props.load(idpPropsStream);
+        } catch (final IOException e) {
+            log.error("Error loading idp.properties", e);
+            return;
+        }
+        final String additionalSources =
+                props.getProperty(IdPPropertiesApplicationContextInitializer.IDP_ADDITIONAL_PROPERTY);
+        if (additionalSources != null) {
+            final String[] sources = additionalSources.split(",");
+            for (final String source : sources) {
+                final String trimmedSource = StringSupport.trimOrNull(source);
+                if (trimmedSource == null) {
+                    continue;
+                }
+                final Path path = Path.of(targetDir + trimmedSource);
+                try {
+                    final InputStream stream = new FileInputStream(path.toFile());
+                    props.load(stream);
+                } catch (final IOException e) {
+                    log.error("Error loading {}", path, e);
+                }
+            }
+        }
+    }
+
     /** {@inheritDoc} */
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
         idpPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("idp.properties"));
         ldapPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("ldap.properties"));
         findPreviousVersion();
+        setupPreviousProps();
     }
 
     /** {@inheritDoc} */
@@ -117,4 +161,9 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
     public boolean isLDAPPropertiesPresent() {
         return ldapPropertiesPresent;
     }
+
+    /** {@inheritDoc} */
+    @Nullable public Properties getCurrentlyInstalledProperties() {
+        return props;
+    }
 }

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


More information about the commits mailing list