[java-identity-provider] 02/05: IDP-1499 New V4 Installer: Adapt MetadataGenerator for new installer

Rod Widdowson rdw at steadingsoftware.com
Tue Oct 15 10:20: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=5cba1646d0da2d2e715d85114d594474ada9e1f7

commit 5cba1646d0da2d2e715d85114d594474ada9e1f7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Oct 14 09:23:43 2019 +0100

    IDP-1499 New V4 Installer: Adapt MetadataGenerator for new installer
    
    https://issues.shibboleth.net/jira/browse/IDP-1499
    
    Add Interfaces for Metadata Generation
    
    Parameters are entirely separated from the installer implementation.
---
 .../idp/installer/{AntRun.java => Installer.java}  |  16 +-
 .../idp/installer/MetadataGenerator.java           |  47 +++
 .../idp/installer/MetadataGeneratorParameters.java |  74 +++++
 .../installer/ant/impl/MetadataGeneratorTask.java  | 110 +------
 ...taGenerator.java => MetadataGeneratorImpl.java} | 324 +++++++--------------
 ...s.java => MetadataGeneratorParametersImpl.java} | 136 +++++----
 .../idp/installer/metadata-generator-ant.xml       |  19 ++
 7 files changed, 336 insertions(+), 390 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/AntRun.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/Installer.java
similarity index 92%
rename from idp-installer/src/main/java/net/shibboleth/idp/installer/AntRun.java
rename to idp-installer/src/main/java/net/shibboleth/idp/installer/Installer.java
index 0a12638..eeaf52b 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/AntRun.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/Installer.java
@@ -25,17 +25,17 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
 /**
  * Entry point to run the main classes.
  */
-public final class AntRun {
-    
+public final class Installer {
+
     /** hidden  Constructor. */
-    private AntRun() {}
+    private Installer() {}
 
     /** simulate the ant tasks.
      * @param args what
-     * @throws ComponentInitializationException 
+     * @throws ComponentInitializationException
      */
     public static void main(final String[] args) throws ComponentInitializationException {
-        final Logger log = LoggerFactory.getLogger(AntRun.class);
+        final Logger log = LoggerFactory.getLogger(Installer.class);
         if (args.length !=1) {
             log.error("One Parameter only {}", (Object[]) args);
             return;
@@ -60,15 +60,15 @@ public final class AntRun {
             final CopyDistribution dist = new CopyDistribution(ip, is);
             dist.execute();
         }
-        
+
         if (doInstall) {
             final V4Install inst = new V4Install(ip, is);
             inst.execute();
         }
-        
+
         final BuildWar bw = new BuildWar(ip, is);
         bw.execute();
-        
+
     }
 
 }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/MetadataGenerator.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/MetadataGenerator.java
new file mode 100644
index 0000000..d164c81
--- /dev/null
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/MetadataGenerator.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.installer;
+
+import java.io.File;
+
+import javax.annotation.Nonnull;
+
+import org.apache.tools.ant.BuildException;
+
+import net.shibboleth.utilities.java.support.component.InitializableComponent;
+
+/**
+ * Interface to define Metadata Generation.
+ */
+public interface MetadataGenerator extends InitializableComponent {
+
+    /** Set where to write the metadata.
+     * @param file what to set.
+     */
+    public void setOutput(@Nonnull File file);
+
+    /** Set a description of the IdP.
+     * @param what what to set.
+     */
+    public void setParameters(@Nonnull final MetadataGeneratorParameters what);
+
+    /** Generate the metadata given the parameters.
+     * @throws BuildException if badness occurs.
+     */
+    void generate() throws BuildException;
+}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/MetadataGeneratorParameters.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/MetadataGeneratorParameters.java
new file mode 100644
index 0000000..6a7bb6f
--- /dev/null
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/MetadataGeneratorParameters.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.installer;
+
+import java.util.List;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
+/**
+ * Interface which describes metadata that needs to be generated.
+ */
+public interface MetadataGeneratorParameters {
+
+    /**
+     * Get the (mutli-line) string representations of the encryption certs.
+     *
+     * @return Returns the encryption cert or null if none available.
+     */
+    @Nullable public List<String> getEncryptionCert();
+
+    /**
+     * Get the (mutli-line) string representation of the signing cert.
+     *
+     * @return Returns the signing cert or null if none available.
+     */
+    @Nullable public List<String> getSigningCert();
+
+    /**
+     * Get the (mutli-line)string representation of the back channel cert.
+     *
+     * @return Returns the back channel cert or null if non available.
+     */
+    @Nullable public List<String> getBackchannelCert();
+
+    /**
+     * Returns the entityID.
+     *
+     * @return the entityID.
+     */
+    @Nonnull @NotEmpty public String getEntityID();
+
+    /**
+     * Returns the dnsName (for use in endpoints).
+     *
+     * @return the dnsname.
+     */
+    @Nonnull @NotEmpty public String getDnsName();
+
+    /**
+     * Returns the scope used.
+     *
+     * @return the scope.
+     */
+    public String getScope();
+
+}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MetadataGeneratorTask.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MetadataGeneratorTask.java
index b0ba2fb..4baa1e2 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MetadataGeneratorTask.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MetadataGeneratorTask.java
@@ -18,9 +18,7 @@
 package net.shibboleth.idp.installer.ant.impl;
 
 import java.io.File;
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.List;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -34,8 +32,8 @@ import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 
 import net.shibboleth.ext.spring.util.ApplicationContextBuilder;
-import net.shibboleth.idp.installer.metadata.impl.MetadataGenerator;
-import net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorParameters;
+import net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorImpl;
+import net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorParametersImpl;
 import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
 
 /**
@@ -51,24 +49,12 @@ public class MetadataGeneratorTask extends Task {
     /** Where idp.home is. */
     @Nullable private String idpHome;
 
-    /** Ant level override for the encryption certificate. */
-    @Nullable private File encryptionCert;
-
-    /** Ant level override for the signing certificate. */
-    @Nullable private File signingCert;
-
     /** Ant level override for the back channel certificate. */
     @Nullable private File backchannelCert;
 
-    /** Ant level override for the entity ID. */
-    @Nullable private String entityID;
-
     /** Ant level override for the DNS name. */
     @Nullable private String dnsName;
 
-    /** Ant level override for the scope. */
-    @Nullable private String scope;
-
     /**
      * Whether to comment out the SAML2 AA port.
      */
@@ -108,24 +94,6 @@ public class MetadataGeneratorTask extends Task {
     }
 
     /**
-     * Set the encryption Certificate file. Overrides the Spring definition.
-     * 
-     * @param file what to set.
-     */
-    public void setEncryptionCert(final File file) {
-        encryptionCert = file;
-    }
-
-    /**
-     * Set the signing Certificate file. Overrides the Spring definition.
-     * 
-     * @param file what to set.
-     */
-    public void setSigningCert(final File file) {
-        signingCert = file;
-    }
-
-    /**
      * Set the Backchannel Certificate file.
      * 
      * @param file what to set.
@@ -135,15 +103,6 @@ public class MetadataGeneratorTask extends Task {
     }
 
     /**
-     * Sets the entityID. Overrides the Spring definition.
-     * 
-     * @param id what to set.
-     */
-    public void setEntityID(final String id) {
-        entityID = id;
-    }
-
-    /**
      * Sets the dns name.
      * 
      * @param name what to set.
@@ -153,15 +112,6 @@ public class MetadataGeneratorTask extends Task {
     }
 
     /**
-     * Sets the scope. Overrides the Spring definition.
-     * 
-     * @param value what to set.
-     */
-    public void setScope(final String value) {
-        scope = value;
-    }
-
-    /**
      * Returns whether to comment the SAML2 AA endpoint.
      * 
      * @return Returns when to comment the SAML2 AA endpoint.
@@ -198,12 +148,11 @@ public class MetadataGeneratorTask extends Task {
     }
 
     /** {@inheritDoc} */
-    // Checkstyle: CyclomaticComplexity OFF
     @Override public void execute() {
         try {
-            final MetadataGeneratorParameters parameters;
+            final MetadataGeneratorParametersImpl parameters;
 
-            final Resource resource = new ClassPathResource("net/shibboleth/idp/installer/metadata-generator.xml");
+            final Resource resource = new ClassPathResource("net/shibboleth/idp/installer/metadata-generator-ant.xml");
 
             final GenericApplicationContext context = new ApplicationContextBuilder()
                     .setName(MetadataGeneratorTask.class.getName())
@@ -211,51 +160,16 @@ public class MetadataGeneratorTask extends Task {
                     .setContextInitializer(new Initializer())
                     .build();
             
-            parameters = context.getBean("IdPConfiguration", MetadataGeneratorParameters.class);
+            parameters = context.getBean("IdPConfiguration", MetadataGeneratorParametersImpl.class);
 
-            if (encryptionCert != null) {
-                parameters.setEncryptionCert(encryptionCert);
-            }
-            if (signingCert != null) {
-                parameters.setSigningCert(signingCert);
-            }
-            if (backchannelCert != null) {
-                parameters.setBackchannelCert(backchannelCert);
-            }
+            parameters.setBackchannelCert(backchannelCert);
+            parameters.setDnsName(dnsName);
+            parameters.initialize();
 
-            final MetadataGenerator generator = new MetadataGenerator(outputFile);
-            final List<List<String>> signing = new ArrayList<>(2);
-            List<String> value = parameters.getBackchannelCert();
-            // IDP-1233 Note that MetadataGenerator.WriteKeyDescriptors() assumes that the order is backchannel, signing
-            if (null != value) {
-                signing.add(value);
-            }
-            value = parameters.getSigningCert();
-            if (null != value) {
-                signing.add(value);
-            }
-            generator.setSigningCerts(signing);
-            value = parameters.getEncryptionCert();
-            if (null != value) {
-                generator.setEncryptionCerts(Collections.singletonList(value));
-            }
-            if (dnsName != null) {
-                generator.setDNSName(dnsName);
-            } else {
-                generator.setDNSName(parameters.getDnsName());
-            }
-            if (entityID != null) {
-                generator.setEntityID(entityID);
-            } else {
-                generator.setEntityID(parameters.getEntityID());
-            }
-            if (scope != null) {
-                generator.setScope(scope);
-            } else {
-                generator.setScope(parameters.getScope());
-            }
-            generator.setSAML2AttributeQueryCommented(isSAML2AttributeQueryCommented());
-            generator.setSAML2LogoutCommented(isSAML2LogoutCommented());
+            final MetadataGeneratorImpl generator = new MetadataGeneratorImpl();
+            generator.setParameters(parameters);
+            generator.setOutput(outputFile);
+            generator.initialize();
             generator.generate();
 
         } catch (final Exception e) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGenerator.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorImpl.java
similarity index 82%
rename from idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGenerator.java
rename to idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorImpl.java
index b1fa2a0..5045482 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGenerator.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorImpl.java
@@ -24,6 +24,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.time.Instant;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.EnumSet;
@@ -32,6 +33,7 @@ import java.util.List;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.apache.tools.ant.BuildException;
 import org.opensaml.core.xml.LangBearing;
 import org.opensaml.saml.common.xml.SAMLConstants;
 import org.opensaml.saml.ext.reqattr.RequestedAttributes;
@@ -55,9 +57,13 @@ import org.opensaml.xmlsec.signature.support.SignatureConstants;
 
 import com.google.common.collect.ImmutableSet;
 
+import net.shibboleth.idp.installer.MetadataGenerator;
+import net.shibboleth.idp.installer.MetadataGeneratorParameters;
 import net.shibboleth.idp.saml.xmlobject.ExtensionsConstants;
 import net.shibboleth.idp.saml.xmlobject.Scope;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.xml.DOMTypeSupport;
 import net.shibboleth.utilities.java.support.xml.XMLConstants;
@@ -66,8 +72,7 @@ import net.shibboleth.utilities.java.support.xml.XMLConstants;
  * This class gathers information which it then uses to generate IdP Metadata. Loosely based on the SP metadata
  * generator, and the V2 metadata.
  */
-// Checkstyle: HideUtilityClassConstructor OFF
-public class MetadataGenerator {
+public class MetadataGeneratorImpl extends AbstractInitializableComponent implements MetadataGenerator {
 
     /**
      * The end points we understand.
@@ -121,21 +126,6 @@ public class MetadataGenerator {
     private EnumSet<Endpoints> endpoints;
 
     /**
-     * The EntityID.
-     */
-    private String entityID;
-
-    /**
-     * The Dns Name.
-     */
-    private String dnsName;
-
-    /**
-     * The Scope.
-     */
-    private String scope;
-
-    /**
      * Whether to comment out the SAML2 AA endpoint.
      */
     private boolean saml2AttributeQueryCommented = true;
@@ -146,121 +136,38 @@ public class MetadataGenerator {
     private boolean saml2LogoutCommented = true;
 
     /**
-     * The signing certificates.
+     * Where to write to - as {@link BufferedWriter}.
      */
-    private List<List<String>> signingCerts;
+    @Nonnull private BufferedWriter writer;
 
     /**
-     * The encryption certificates.
+     * Where to write to - as {@link File}.
      */
-    private List<List<String>> encryptionCerts;
+    private File output;
 
-    /**
-     * Where to write to.
-     */
-    private final BufferedWriter writer;
+    /** The parameters. */
+    private MetadataGeneratorParameters params;
 
-    /**
-     * Constructor.
-     * 
-     * @param file file to output to.
-     * @throws FileNotFoundException if the file cannot be found.
-     */
-    public MetadataGenerator(@Nonnull final File file) throws FileNotFoundException {
-        final File nonnullFile = Constraint.isNotNull(file, "provided file must be nonnull");
-        final FileOutputStream outStream = new FileOutputStream(nonnullFile);
-        writer = new BufferedWriter(new OutputStreamWriter(outStream));
+    /** {@inheritDoc} */
+    protected void doInitialize() throws ComponentInitializationException {
+        try {
+            final FileOutputStream outStream;
+            outStream = new FileOutputStream(output);
+            writer = new BufferedWriter(new OutputStreamWriter(outStream));
+        } catch (final FileNotFoundException e) {
+            throw new ComponentInitializationException(e);
+        }
         endpoints = EnumSet.allOf(Endpoints.class);
     }
 
-    /**
-     * Get the entityID.
-     * 
-     * @return Returns the entityID.
-     */
-    public String getEntityID() {
-        return entityID;
-    }
-
-    /**
-     * Set the entityID.
-     * 
-     * @param id what to set.
-     */
-    public void setEntityID(final String id) {
-        entityID = id;
-    }
-
-    /**
-     * Get the Scope.
-     * 
-     * @return Returns the Scope.
-     */
-    public String getScope() {
-        return scope;
-    }
-
-    /**
-     * Set the Scope.
-     * 
-     * @param id what to set.
-     */
-    public void setScope(final String id) {
-        scope = id;
-    }
-
-    /**
-     * Get the DNSName.
-     * 
-     * @return Returns the DNSName.
-     */
-    public String getDNSName() {
-        return dnsName;
-    }
-
-    /**
-     * Set the DNSName.
-     * 
-     * @param id what to set.
-     */
-    public void setDNSName(final String id) {
-        dnsName = id;
-    }
-
-    /**
-     * Get the signingCerts.
-     * 
-     * @return Returns the signingCerts.
-     */
-    public List<List<String>> getSigningCerts() {
-        return signingCerts;
-    }
-
-    /**
-     * Set the signingCerts.
-     * 
-     * @param certs what to set.
-     */
-    public void setSigningCerts(final List<List<String>> certs) {
-        signingCerts = certs;
+    /** {@inheritDoc} */
+    public void setOutput(@Nonnull final File file) {
+        output = Constraint.isNotNull(file, "provided file must be nonnull");
     }
 
-    /**
-     * Get the encryptionCerts.
-     * 
-     * @return Returns the signingCerts.
-     */
-    public List<List<String>> getEncryptionCerts() {
-        return encryptionCerts;
-    }
-
-    /**
-     * Set the encryptionCerts.
-     * 
-     * @param certs what to set.
-     */
-    public void setEncryptionCerts(final List<List<String>> certs) {
-        encryptionCerts = certs;
+    /** {@inheritDoc} */
+    public void setParameters(@Nonnull final MetadataGeneratorParameters what) {
+        params = Constraint.isNotNull(what, "provided params must be nonnull");
     }
 
     /**
@@ -272,7 +179,7 @@ public class MetadataGenerator {
 
     /**
      * Get the Endpoints.
-     * 
+     *
      * @return Returns the Endpoints
      */
     public EnumSet<Endpoints> getEndpoints() {
@@ -281,7 +188,7 @@ public class MetadataGenerator {
 
     /**
      * Set the Endpoints.
-     * 
+     *
      * @param points what to set.
      */
     public void setEndpoints(@Nonnull final EnumSet<Endpoints> points) {
@@ -290,7 +197,7 @@ public class MetadataGenerator {
 
     /**
      * Returns whether to comment the SAML2 AA endpoint.
-     * 
+     *
      * @return whether to comment the SAML2 AA endpoint
      */
     public boolean isSAML2AttributeQueryCommented() {
@@ -299,7 +206,7 @@ public class MetadataGenerator {
 
     /**
      * Sets whether to comment the SAML2 AA endpoint.
-     * 
+     *
      * @param asComment whether to comment or not.
      */
     public void setSAML2AttributeQueryCommented(final boolean asComment) {
@@ -308,7 +215,7 @@ public class MetadataGenerator {
 
     /**
      * Returns whether to comment the SAML2 Logout endpoints.
-     * 
+     *
      * @return whether to comment the SAML2 Logout endpoints
      */
     public boolean isSAML2LogoutCommented() {
@@ -317,56 +224,56 @@ public class MetadataGenerator {
 
     /**
      * Sets whether to comment the SAML2 Logout endpoints.
-     * 
+     *
      * @param asComment whether to comment or not
      */
     public void setSAML2LogoutCommented(final boolean asComment) {
         saml2LogoutCommented = asComment;
     }
 
-    /**
-     * Generate the metadata.
-     * 
-     * @throws IOException if we have a failure.
-     */
-    public void generate() throws IOException {
-        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-        writer.newLine();
-        writeComments();
-        writer.write("<");
-        writer.write(EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME);
-        writer.write(' ');
-        writeNameSpace(null, SAMLConstants.SAML20MD_NS);
-        writeNameSpace(SignatureConstants.XMLSIG_PREFIX, SignatureConstants.XMLSIG_NS);
-        writeNameSpace(ExtensionsConstants.SHIB_MDEXT10_PREFIX, ExtensionsConstants.SHIB_MDEXT10_NS);
-        writeNameSpace(XMLConstants.XML_PREFIX, XMLConstants.XML_NS);
-        writeNameSpace(SAMLConstants.SAML20MDUI_PREFIX, SAMLConstants.SAML20MDUI_NS);
-        writeNameSpace(SAMLConstants.SAML20PREQ_ATTRR_PREFIX, SAMLConstants.SAML20PREQ_ATTR_NS);
-
-        writer.write(" validUntil=\"" + DOMTypeSupport.instantToString(Instant.now()) + "\"");
-        
-        writer.write(" entityID=\"");
-        writer.write(getEntityID());
-        writer.write("\">");
-        writer.newLine();
-        writer.newLine();
-        
-        
+    /** {@inheritDoc} */
+    public void generate() throws BuildException {
+        try {
+            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+            writer.newLine();
+            writeComments();
+            writer.write("<");
+            writer.write(EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME);
+            writer.write(' ');
+            writeNameSpace(null, SAMLConstants.SAML20MD_NS);
+            writeNameSpace(SignatureConstants.XMLSIG_PREFIX, SignatureConstants.XMLSIG_NS);
+            writeNameSpace(ExtensionsConstants.SHIB_MDEXT10_PREFIX, ExtensionsConstants.SHIB_MDEXT10_NS);
+            writeNameSpace(XMLConstants.XML_PREFIX, XMLConstants.XML_NS);
+            writeNameSpace(SAMLConstants.SAML20MDUI_PREFIX, SAMLConstants.SAML20MDUI_NS);
+            writeNameSpace(SAMLConstants.SAML20PREQ_ATTRR_PREFIX, SAMLConstants.SAML20PREQ_ATTR_NS);
+
+            writer.write(" validUntil=\"" + DOMTypeSupport.instantToString(Instant.now()) + "\"");
+
+            writer.write(" entityID=\"");
+            writer.write(params.getEntityID());
+            writer.write("\">");
+            writer.newLine();
+            writer.newLine();
 
-        writeIDPSSO();
-        writer.newLine();
-        writer.newLine();
-        writeAttributeAuthorityDescriptor();
-        writer.newLine();
-        writer.write("</EntityDescriptor>");
-        writer.newLine();
-        writer.flush();
-        writer.close();
+
+
+            writeIDPSSO();
+            writer.newLine();
+            writer.newLine();
+            writeAttributeAuthorityDescriptor();
+            writer.newLine();
+            writer.write("</EntityDescriptor>");
+            writer.newLine();
+            writer.flush();
+            writer.close();
+        } catch (final IOException e) {
+            throw new BuildException(e);
+        }
     }
 
     /**
      * Add appropriate comments to metadata header.
-     * 
+     *
      * @throws IOException if badness occurs in the writer
      */
     protected void writeComments() throws IOException {
@@ -385,7 +292,7 @@ public class MetadataGenerator {
 
     /**
      * Writeout a prefix/namespace pair.
-     * 
+     *
      * @param prefix the prefix, or null
      * @param name the namespace
      * @throws IOException if badness happens
@@ -403,7 +310,7 @@ public class MetadataGenerator {
 
     /**
      * Write the <IDPSSODescriptor>.
-     * 
+     *
      * @throws IOException if badness happens
      */
     protected void writeIDPSSO() throws IOException {
@@ -436,7 +343,7 @@ public class MetadataGenerator {
             writer.write("        -->");
             writer.newLine();
         }
-        
+
         writer.newLine();
         for (final Endpoints endpoint : SSO_ENDPOINTS) {
             if (getEndpoints().contains(endpoint)) {
@@ -452,7 +359,7 @@ public class MetadataGenerator {
 
     /**
      * Write the <AttributeAuthorityDescriptor>.
-     * 
+     *
      * @throws IOException if badness happens
      */
     private void writeAttributeAuthorityDescriptor() throws IOException {
@@ -483,7 +390,7 @@ public class MetadataGenerator {
 
     /**
      * Write out an role descriptor.
-     * 
+     *
      * @param name the name
      * @param protocols the supported protocols
      * @throws IOException when badness happebns
@@ -506,7 +413,7 @@ public class MetadataGenerator {
 
     /**
      * Write the open <Extensions> elements.
-     * 
+     *
      * @throws IOException if badness happens
      */
     protected void openExtensions() throws IOException {
@@ -519,7 +426,7 @@ public class MetadataGenerator {
 
     /**
      * Write out the close <\Extensions> Element.
-     * 
+     *
      * @throws IOException if badness happens
      */
     protected void closeExtensions() throws IOException {
@@ -531,33 +438,19 @@ public class MetadataGenerator {
     }
 
     /**
-     * Write out any <Extensions>Elements. Currently this is just the scope TODO: mdui TODO: entityAttributes
-     * 
-     * @deprecated use {@link #openExtensions()} and {@link #closeExtensions()}
-     * @throws IOException if badness happens
-     */
-    @Deprecated protected void writeExtensions() throws IOException {
-
-        openExtensions();
-        writeScope();
-        writeMDUI();
-        closeExtensions();
-    }
-
-    /**
      * Write out the <shibmd:Scope> element.
-     * 
+     *
      * @throws IOException if badness happens
      */
     protected void writeScope() throws IOException {
-        if (null == getScope() || getScope().isEmpty()) {
+        if (null == params.getScope() || params.getScope().isEmpty()) {
             return;
         }
 
         writer.write("            <");
         writeNameSpaceQualified(ExtensionsConstants.SHIB_MDEXT10_PREFIX, Scope.DEFAULT_ELEMENT_LOCAL_NAME);
         writer.write(" regexp=\"false\">");
-        writer.write(getScope());
+        writer.write(params.getScope());
         writer.write("</");
         writeNameSpaceQualified(ExtensionsConstants.SHIB_MDEXT10_PREFIX, Scope.DEFAULT_ELEMENT_LOCAL_NAME);
         writer.write('>');
@@ -566,7 +459,7 @@ public class MetadataGenerator {
 
     /**
      * Write out the <mdui:UIINFO> element and children.
-     * 
+     *
      * @throws IOException if badness happens
      */
     protected void writeMDUI() throws IOException {
@@ -588,7 +481,7 @@ public class MetadataGenerator {
         writeLangAttribute("en");
         writer.write('>');
         writer.write("A Name for the IdP at ");
-        writer.write(getDNSName());
+        writer.write(params.getDnsName());
         writer.write("</");
         writeNameSpaceQualified(SAMLConstants.SAML20MDUI_PREFIX, DisplayName.DEFAULT_ELEMENT_LOCAL_NAME);
         writer.write('>');
@@ -601,7 +494,7 @@ public class MetadataGenerator {
         writeLangAttribute("en");
         writer.write('>');
         writer.write("Enter a description of your IdP at ");
-        writer.write(getDNSName());
+        writer.write(params.getDnsName());
         writer.write("</");
         writeNameSpaceQualified(SAMLConstants.SAML20MDUI_PREFIX, Description.DEFAULT_ELEMENT_LOCAL_NAME);
         writer.write('>');
@@ -612,7 +505,7 @@ public class MetadataGenerator {
         writeNameSpaceQualified(SAMLConstants.SAML20MDUI_PREFIX, Logo.DEFAULT_ELEMENT_LOCAL_NAME);
         writer.write(" height=\"80\" width=\"80\">");
         writer.write("https://");
-        writer.write(getDNSName());
+        writer.write(params.getDnsName());
         writer.write("/Path/To/Logo.png");
         writer.write("</");
         writeNameSpaceQualified(SAMLConstants.SAML20MDUI_PREFIX, Logo.DEFAULT_ELEMENT_LOCAL_NAME);
@@ -630,7 +523,7 @@ public class MetadataGenerator {
 
     /**
      * Write the language attribute.
-     * 
+     *
      * @param language which languages
      * @throws IOException if badness happens
      */
@@ -643,22 +536,27 @@ public class MetadataGenerator {
 
     /**
      * Write out any <KeyDescriptor>Elements.
-     * 
+     *
      * @throws IOException if badness happens
      */
     protected void writeKeyDescriptors() throws IOException {
-        if (getSigningCerts().size() == 2) {
+        final List<List<String>> signing = new ArrayList<>(2);
+        if (params.getBackchannelCert() != null && !params.getBackchannelCert().isEmpty()) {
             writer.write("        <!-- First signing certificate is BackChannel, the Second is FrontChannel -->");
             writer.newLine();
+            signing.add(params.getBackchannelCert());
+        }
+        if (params.getSigningCert() != null && !params.getSigningCert().isEmpty()) {
+            signing.add(params.getSigningCert());
         }
-        writeKeyDescriptors(getSigningCerts(), "signing");
-        writeKeyDescriptors(getEncryptionCerts(), "encryption");
+        writeKeyDescriptors(signing, "signing");
+        writeKeyDescriptors(Collections.singletonList(params.getEncryptionCert()), "encryption");
         writer.newLine();
     }
 
     /**
      * Write out <KeyDescriptor>Elements. of a specific type
-     * 
+     *
      * @param certs the certificates
      * @param use the type - signing or encryption
      * @throws IOException if badness happens
@@ -714,7 +612,7 @@ public class MetadataGenerator {
 
     /**
      * Output the SAML for a single endpoint.
-     * 
+     *
      * @param endpoint the type
      * @throws IOException if badness happens.
      */
@@ -728,7 +626,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML1_SOAP11_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write(":8443/idp/profile/SAML1/SOAP/ArtifactResolution\"");
                 writer.write(" index=\"1\"/>");
                 writer.newLine();
@@ -741,7 +639,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML2_SOAP11_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write(":8443/idp/profile/SAML2/SOAP/ArtifactResolution\"");
                 writer.write(" index=\"2\"/>");
                 writer.newLine();
@@ -754,7 +652,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML2_REDIRECT_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write("/idp/profile/SAML2/Redirect/SLO\"/>");
                 writer.newLine();
                 break;
@@ -766,7 +664,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML2_POST_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write("/idp/profile/SAML2/POST/SLO\"/>");
                 writer.newLine();
                 break;
@@ -778,7 +676,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML2_POST_SIMPLE_SIGN_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write("/idp/profile/SAML2/POST-SimpleSign/SLO\"/>");
                 writer.newLine();
                 break;
@@ -790,7 +688,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML2_SOAP11_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write(":8443/idp/profile/SAML2/SOAP/SLO\"/>");
                 writer.newLine();
                 break;
@@ -801,7 +699,7 @@ public class MetadataGenerator {
                 writer.write(SingleSignOnService.DEFAULT_ELEMENT_LOCAL_NAME);
                 writer.write(" Binding=\"urn:mace:shibboleth:1.0:profiles:AuthnRequest\"");
                 writer.write(" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write("/idp/profile/Shibboleth/SSO\"/>");
                 writer.newLine();
                 break;
@@ -816,7 +714,7 @@ public class MetadataGenerator {
                 writeNameSpaceQualified(SAMLConstants.SAML20PREQ_ATTRR_PREFIX,
                         RequestedAttributes.SUPPORTS_REQUESTED_ATTRIBUTES_LOCAL_NAME);
                 writer.write("=\"true\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write("/idp/profile/SAML2/POST/SSO\"/>");
                 writer.newLine();
                 break;
@@ -831,7 +729,7 @@ public class MetadataGenerator {
                 writeNameSpaceQualified(SAMLConstants.SAML20PREQ_ATTRR_PREFIX,
                         RequestedAttributes.SUPPORTS_REQUESTED_ATTRIBUTES_LOCAL_NAME);
                 writer.write("=\"true\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write("/idp/profile/SAML2/POST-SimpleSign/SSO\"/>");
                 writer.newLine();
                 break;
@@ -846,7 +744,7 @@ public class MetadataGenerator {
                 writeNameSpaceQualified(SAMLConstants.SAML20PREQ_ATTRR_PREFIX,
                         RequestedAttributes.SUPPORTS_REQUESTED_ATTRIBUTES_LOCAL_NAME);
                 writer.write("=\"true\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write("/idp/profile/SAML2/Redirect/SSO\"/>");
                 writer.newLine();
                 break;
@@ -858,7 +756,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML1_SOAP11_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write(":8443/idp/profile/SAML1/SOAP/AttributeQuery\"/>");
                 writer.newLine();
                 break;
@@ -873,7 +771,7 @@ public class MetadataGenerator {
                 writer.write(" Binding=\"");
                 writer.write(SAMLConstants.SAML2_SOAP11_BINDING_URI);
                 writer.write("\" Location=\"https://");
-                writer.write(getDNSName());
+                writer.write(params.getDnsName());
                 writer.write(":8443/idp/profile/SAML2/SOAP/AttributeQuery\"/>");
                 if (isSAML2AttributeQueryCommented()) {
                     writer.write(" -->");
@@ -892,7 +790,7 @@ public class MetadataGenerator {
 
     /**
      * Write a namespace:identifier pair.
-     * 
+     *
      * @param nameSpace the namespace
      * @param what the identifier
      * @throws IOException if badness happens
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorParameters.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorParametersImpl.java
similarity index 68%
rename from idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorParameters.java
rename to idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorParametersImpl.java
index fa06fe6..ea4f3de 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorParameters.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorParametersImpl.java
@@ -28,10 +28,15 @@ import javax.annotation.Nullable;
 
 import org.springframework.core.io.Resource;
 
+import net.shibboleth.idp.installer.MetadataGeneratorParameters;
+import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
 /**
- * POJO to collect parameters from the metadata configuration (partially via spring).
+ * Implementation of {@link MetadataGeneratorParameters}.
  */
-public class MetadataGeneratorParameters {
+public class MetadataGeneratorParametersImpl extends AbstractInitializableComponent
+    implements MetadataGeneratorParameters {
 
     /**
      * The file with the certificate the IDP uses to encrypt.
@@ -39,15 +44,30 @@ public class MetadataGeneratorParameters {
     private File encryptionCert;
 
     /**
+     * The strings with the encryption cert in them (to allow for multiline output).
+     */
+    private List<String> encryptionCerts;
+
+    /**
      * The file with the certificate that TLS uses to 'sign'.
      */
     private File backChannelCert;
 
     /**
+     * The strings with the back channel cert in them (to allow for multiline output).
+     */
+    private List<String> backChannelCerts;
+
+    /**
      * The file with the certificate the IDP uses to sign.
      */
     private File signingCert;
 
+    /**
+     * The strings with the signing certs in them (to allow for multiline output).
+     */
+    private List<String> signingCerts;
+
     /** The entityID. */
     private String entityID;
 
@@ -56,30 +76,26 @@ public class MetadataGeneratorParameters {
 
     /** The scope. */
     private String scope;
-    
-    /**
-     * Get the string representation of the encryption cert.
-     * 
-     * @return Returns the encryptionCert.
-     * @throws IOException if badness occurrs
-     */
-    @Nullable public List<String> getEncryptionCert() throws IOException {
-        return getCertificateContents(encryptionCert);
-    }
 
-    /**
-     * Set the encryption Certificate file.
-     * 
-     * @param file what to set.
-     */
-    public void setEncryptionCert(final File file) {
+    /** {@inheritDoc} */
+    protected void doInitialize() throws ComponentInitializationException {
+        try {
+            encryptionCerts = getCertificateContents(encryptionCert);
+            signingCerts = getCertificateContents(signingCert);
+            backChannelCerts = getCertificateContents(backChannelCert);
+        } catch (final IOException e) {
+            throw new ComponentInitializationException(e);
+        }
+    }
 
-        encryptionCert = file;
+    /**  {@inheritDoc} */
+    @Nullable public List<String> getEncryptionCert() {
+        return encryptionCerts;
     }
 
     /**
      * Set the encryption Certificate file.
-     * 
+     *
      * @param resource what to set.
      */
     public void setEncryptionCertResource(final Resource resource) {
@@ -91,34 +107,17 @@ public class MetadataGeneratorParameters {
         }
     }
 
-    /**
-     * Get the string representation of the signing cert.
-     * 
-     * @return Returns the encryptionCert.
-     * @throws IOException if badness occurrs
-     */
-    @Nullable public List<String> getSigningCert() throws IOException {
-        return getCertificateContents(signingCert);
+    /**  {@inheritDoc} */
+    @Nullable public List<String> getSigningCert() {
+        return signingCerts;
     }
 
     /**
      * Set the signing Certificate file.
-     * 
-     * @param file what to set.
-     */
-    public void setSigningCert(final File file) {
-
-        signingCert = file;
-    }
-
-    /**
-     * Set the signing Certificate file.
-     * 
+     *
      * @param resource what to set.
      */
     public void setSigningCertResource(final Resource resource) {
-
-
         try {
             signingCert = resource.getFile();
         } catch (final IOException e) {
@@ -126,29 +125,37 @@ public class MetadataGeneratorParameters {
         }
     }
 
-    /**
-     * Get the string representation of the back channel cert.
-     * 
-     * @return Returns the encryptionCert.
-     * @throws IOException if badness occurrs
-     */
-    @Nullable public List<String> getBackchannelCert() throws IOException {
-        return getCertificateContents(backChannelCert);
+    /**  {@inheritDoc} */
+    @Nullable public List<String> getBackchannelCert() {
+        return backChannelCerts;
     }
 
     /**
      * Set the Backchannel Certificate file.
-     * 
+     *
      * @param file what to set.
      */
     public void setBackchannelCert(final File file) {
-
         backChannelCert = file;
     }
+    
+    /**
+     * Set the Backchannel Certificate.
+     *
+     * @param resource what to set.
+     */
+    public void setBackchannelCertResource(final Resource resource) {
+        try {
+            backChannelCert = resource.getFile();
+        } catch (final IOException e) {
+            backChannelCert = null;
+        } 
+    }
+
 
     /**
      * Open the file and return the contents and a list of lines.
-     * 
+     *
      * @param file the file
      * @return the contents
      * @throws IOException if badness occurrs.
@@ -180,58 +187,45 @@ public class MetadataGeneratorParameters {
         }
     }
 
-    /**
-     * Returns the entityID.
-     * 
-     * @return the entityID.
-     */
+    /**  {@inheritDoc} */
     public String getEntityID() {
         return entityID;
     }
 
     /**
      * Sets the entityID.
-     * 
+     *
      * @param id what to set.
      */
     public void setEntityID(final String id) {
         entityID = id;
     }
 
-    /**
-     * Returns the dnsName.
-     * 
-     * @return the dnsname.
-     */
+    /**  {@inheritDoc} */
     public String getDnsName() {
         return dnsName;
     }
 
     /**
      * Sets the dns name.
-     * 
+     *
      * @param name what to set.
      */
     public void setDnsName(final String name) {
         dnsName = name;
     }
 
-    /**
-     * Returns the scope.
-     * 
-     * @return the scope.
-     */
+    /**  {@inheritDoc} */
     public String getScope() {
         return scope;
     }
 
     /**
      * Sets the scope.
-     * 
+     *
      * @param value what to set.
      */
     public void setScope(final String value) {
         scope = value;
     }
-
 }
diff --git a/idp-installer/src/main/resources/net/shibboleth/idp/installer/metadata-generator-ant.xml b/idp-installer/src/main/resources/net/shibboleth/idp/installer/metadata-generator-ant.xml
new file mode 100644
index 0000000..d739eb0
--- /dev/null
+++ b/idp-installer/src/main/resources/net/shibboleth/idp/installer/metadata-generator-ant.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
+	xmlns:c="http://www.springframework.org/schema/c" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+	<bean
+		class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
+		p:placeholderPrefix="%{" p:placeholderSuffix="}" />
+
+    <context:property-placeholder />
+
+	<bean id="IdPConfiguration"
+		class="net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorParametersImpl"
+		p:encryptionCertResource="%{idp.encryption.cert}" p:signingCertResource="%{idp.signing.cert}"
+		p:entityID="%{idp.entityID}" p:scope="%{idp.scope}" />
+</beans>
\ No newline at end of file

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


More information about the commits mailing list