[java-identity-provider] 04/05: IDP-1499 V4 Installer: Wire in metadata generation
Rod Widdowson
rdw at steadingsoftware.com
Tue Oct 15 10:20:32 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=12adb6ed3b8c6670e5653958de78ccf0e53cc84e
commit 12adb6ed3b8c6670e5653958de78ccf0e53cc84e
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Oct 15 13:46:48 2019 +0100
IDP-1499 V4 Installer: Wire in metadata generation
https://issues.shibboleth.net/jira/browse/IDP-1499
As with the ant version the metadata parameters are derived using spring wiring
so we get to interrogate idp.properties.
Involved using a tricky ApplicationContextInitializer
---
.../shibboleth/idp/installer/InstallerSupport.java | 1 +
.../net/shibboleth/idp/installer/V4Install.java | 107 ++++++++++++++++++---
.../idp/installer/metadata-generator.xml | 12 ++-
.../java/net/shibboleth/idp/installer/Test.java | 15 ++-
4 files changed, 116 insertions(+), 19 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
index 45b0fe6..e70300c 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
@@ -147,6 +147,7 @@ public final class InstallerSupport {
log.error("Directory to be delete {} was a file");
throw new BuildException("Wanted a directory, found a file");
}
+ log.debug("Deleting tree {}", where);
final Delete delete = new Delete();
delete.setDir(where.toFile());
delete.setFailOnError(false);
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 b975803..5a2d92f 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
@@ -34,9 +34,18 @@ import org.apache.tools.ant.taskdefs.Copy;
import org.joda.time.Instant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import net.shibboleth.ext.spring.util.ApplicationContextBuilder;
import net.shibboleth.idp.Version;
+import net.shibboleth.idp.installer.ant.impl.MetadataGeneratorTask;
+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.security.BasicKeystoreKeyStrategyTool;
import net.shibboleth.utilities.java.support.security.SelfSignedCertificateGenerator;
@@ -54,6 +63,12 @@ public class V4Install extends AbstractInitializableComponent {
/** Current Install. */
@Nonnull private final CurrentInstallState currentState;
+ /** Key Manager. */
+ @Nonnull private final KeyManagement keyManager;
+
+ /** What will generate metadata? */
+ private MetadataGenerator metadataGenerator;
+
/** Constructor.
* @param props The properties to drive the installs.
* @param installState The current install.
@@ -63,26 +78,45 @@ public class V4Install extends AbstractInitializableComponent {
ComponentSupport.ifNotInitializedThrowUninitializedComponentException(installState);
installerProps = props;
currentState = installState;
+ keyManager = new KeyManagement(installerProps, currentState);
+ }
+
+ /** {@inheritDoc} */
+ protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+ keyManager.initialize();
+ if (metadataGenerator != null) {
+ log.warn("No metadata generator configured");
+ }
}
/** Method to do the work. It assumes that the distribution has been copied.
* @throws BuildException if unexpected badness occurs.
*/
public void execute() throws BuildException {
+ ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
handleVersioning();
- // To keep the UI order the same as the V3 Installer
- //installerProps.getEntityID();
- //installerProps.getScope();
+
createUserDirectories();
- final KeyManagement keys = new KeyManagement(installerProps, currentState);
- keys.execute();
- populatePropertyFiles(keys.isCreatedSealer());
+ keyManager.execute();
+ populatePropertyFiles(keyManager.isCreatedSealer());
handleEditWebApp();
populateUserDirectories();
generateMetadata();
reprotect();
}
+ /** Set the {@link MetadataGenerator}.
+ * @param what what to set. This need not have been initialized yet
+ * {@link MetadataGenerator#setOutput(File)} and
+ * {@link MetadataGenerator#setParameters(MetadataGeneratorParameters)} are called
+ * prior to initialization.
+ */
+ public void setMetadataGenerator(final MetadataGenerator what) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ metadataGenerator = what;
+ }
+
/** Report the to be installed and (if there is one) current versions.
* Write to be installed version to the dist folder.
* @throws BuildException if the write fails
@@ -251,12 +285,37 @@ public class V4Install extends AbstractInitializableComponent {
* @throws BuildException if badness occurs
*/
protected void generateMetadata() throws BuildException {
+ if (metadataGenerator == null) {
+ log.warn("No Metadata Generator registered");
+ return;
+ }
+
final Path parentDir = installerProps.getTargetDir().resolve("metadata");
final Path metadataFile = parentDir.resolve("idp-metadata");
if (Files.exists(metadataFile)) {
+ log.debug("Metadata file {} exists", metadataFile.toString());
return;
}
- log.warn("Metadata Implementation still pending");
+ final Resource resource = new ClassPathResource("net/shibboleth/idp/installer/metadata-generator.xml");
+ final GenericApplicationContext context = new ApplicationContextBuilder()
+ .setName(MetadataGeneratorTask.class.getName())
+ .setServiceConfigurations(Collections.singletonList(resource))
+ .setContextInitializer(new Initializer())
+ .build();
+
+ final MetadataGeneratorParameters parameters = context.getBean("IdPConfiguration",
+ MetadataGeneratorParameters.class);
+
+ log.info("Creating Metadata to {}", metadataFile);
+ log.debug("Parameters {}", parameters);
+ metadataGenerator.setOutput(metadataFile.toFile());
+ metadataGenerator.setParameters(parameters);
+ try {
+ metadataGenerator.initialize();
+ } catch (final ComponentInitializationException e) {
+ throw new BuildException(e);
+ }
+ metadataGenerator.generate();
}
/** Set the protection on the files.
@@ -269,10 +328,7 @@ public class V4Install extends AbstractInitializableComponent {
/**
* Create (if needs be) all the keys needed by an install.
*/
- private static class KeyManagement extends AbstractInitializableComponent {
-
- /** Log. */
- private final Logger log = LoggerFactory.getLogger(KeyManagement.class);
+ private class KeyManagement extends AbstractInitializableComponent {
/** Properties for the job. */
@Nonnull private final InstallerProperties installerProps;
@@ -308,6 +364,7 @@ public class V4Install extends AbstractInitializableComponent {
* @throws BuildException if badness occurs
*/
protected void execute() throws BuildException {
+ ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
createdSigning = generateKey("idp-signing");
createdEncryption = generateKey("idp-encryption");
generateKeyStore();
@@ -467,4 +524,32 @@ public class V4Install extends AbstractInitializableComponent {
return createdSealer;
}
}
+
+ /**
+ * An {@link ApplicationContextInitializer} which knows about our idp.home and
+ * also injects properties for the backchannel certificate and hostname.
+ */
+ private class Initializer extends IdPPropertiesApplicationContextInitializer {
+
+ /** {@inheritDoc} */
+ @Override @Nonnull public String selectSearchLocation(
+ @Nonnull final ConfigurableApplicationContext applicationContext) {
+ return installerProps.getTargetDir().toString();
+ }
+
+ /** {@inheritDoc} */
+ @Override @Nonnull public String getSearchLocation() {
+ return installerProps.getTargetDir().toString();
+ }
+
+ /** {@inheritDoc} */
+ public void initialize(final ConfigurableApplicationContext applicationContext) {
+ final Properties props = new Properties(2);
+ props.setProperty("idp.backchannel.cert",
+ installerProps.getTargetDir().resolve("credentials").resolve("idp-backchannel.crt").toString());
+ props.setProperty("idp.dnsname", installerProps.getHostName());
+ appendPropertySource(applicationContext, "internal", props);
+ super.initialize(applicationContext);
+ }
+ }
}
diff --git a/idp-installer/src/main/resources/net/shibboleth/idp/installer/metadata-generator.xml b/idp-installer/src/main/resources/net/shibboleth/idp/installer/metadata-generator.xml
index f9d393c..1fe209a 100644
--- a/idp-installer/src/main/resources/net/shibboleth/idp/installer/metadata-generator.xml
+++ b/idp-installer/src/main/resources/net/shibboleth/idp/installer/metadata-generator.xml
@@ -5,7 +5,10 @@
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">
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+ default-init-method="initialize"
+ default-destroy-method="destroy">
+
<bean
class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
p:placeholderPrefix="%{" p:placeholderSuffix="}" />
@@ -13,7 +16,10 @@
<context:property-placeholder />
<bean id="IdPConfiguration"
- class="net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorParameters"
- p:encryptionCertResource="%{idp.encryption.cert}" p:signingCertResource="%{idp.signing.cert}"
+ class="net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorParametersImpl"
+ p:encryptionCertResource="%{idp.encryption.cert}"
+ p:signingCertResource="%{idp.signing.cert}"
+ p:backchannelCertResource="%{idp.backchannel.cert}"
+ p:dnsName="%{idp.dnsname}"
p:entityID="%{idp.entityID}" p:scope="%{idp.scope}" />
</beans>
\ No newline at end of file
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java
index 80edf40..963aae9 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java
@@ -24,6 +24,7 @@ import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorImpl;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
/**
@@ -41,7 +42,6 @@ public class Test {
*/
public static void main(String[] args) throws IOException, ComponentInitializationException {
-
System.setProperty(InstallerPropertiesImpl.TARGET_DIR,"H:\\Downloads\\v4test");
System.setProperty(InstallerPropertiesImpl.SOURCE_DIR,
"h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.0.0-SNAPSHOT");
@@ -49,20 +49,25 @@ public class Test {
"h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.0.0-SNAPSHOT\\bin");
System.setProperty(InstallerPropertiesImpl.KEY_STORE_PASSWORD, "p1");
System.setProperty(InstallerPropertiesImpl.SEALER_PASSWORD, "p1");
+ System.setProperty(InstallerPropertiesImpl.HOST_NAME, "machine.org.uk");
+
final InstallerProperties ip = new InstallerPropertiesImpl(false);
ip.initialize();
final CurrentInstallState is = new CurrentInstallState(ip);
is.initialize();
-
+
final CopyDistribution dist = new CopyDistribution(ip, is);
+ dist.initialize();
dist.execute();
-
+
final V4Install inst = new V4Install(ip, is);
+ inst.setMetadataGenerator(new MetadataGeneratorImpl());
+ inst.initialize();
inst.execute();
-
+
final BuildWar bw = new BuildWar(ip, is);
+ bw.initialize();
bw.execute();
-
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list