[java-identity-provider] 06/11: IDP-1499 New V4 Installer: Move away from using static
Rod Widdowson
rdw at steadingsoftware.com
Fri Oct 11 11:08:29 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=21e83f9bb62840ca19b22c9735f785128fc24203
commit 21e83f9bb62840ca19b22c9735f785128fc24203
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Oct 8 14:47:58 2019 +0100
IDP-1499 New V4 Installer: Move away from using static
https://issues.shibboleth.net/jira/browse/IDP-1499
---
.../shibboleth/idp/installer/impl/BuildWar.java | 56 +++++------
.../idp/installer/impl/CopyDistributions.java | 98 +++++++++---------
.../idp/installer/impl/KeyManagement.java | 111 +++++++++++----------
.../java/net/shibboleth/idp/installer/Test.java | 7 +-
4 files changed, 133 insertions(+), 139 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
index d3b5842..53ab077 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
@@ -36,49 +36,55 @@ import org.slf4j.LoggerFactory;
* <li>Deletes webapp.tmp</li>
* </ul>
*/
-public final class BuildWar {
+public class BuildWar {
/** Log. */
- public static final Logger LOG = LoggerFactory.getLogger(BuildWar.class);
-
- /** private Constructor. */
- private BuildWar() {}
+ private final Logger log = LoggerFactory.getLogger(BuildWar.class);
+
+ /** Properties for the job. */
+ private final InstallerProperties installerProps;
+
+ /** Constructor.
+ * @param props The environment for the work.
+ */
+ public BuildWar(final InstallerProperties props) {
+ installerProps = props;
+ }
/** Method to do the work of building the war.
- * @param installerProps The environment for the work.
* @throws BuildException if unexpected badness occurs.
*/
- public static void buildWar(final InstallerProperties installerProps) throws BuildException {
+ public void execute() throws BuildException {
final Path target = installerProps.getTargetDir();
final Path warFile = target.resolve("war").resolve("idp.war");
- LOG.info("Rebuilding {}", warFile.toAbsolutePath());
+ log.info("Rebuilding {}", warFile.toAbsolutePath());
try {
DeletingVisitor.deleteTree(target.resolve("webpapp"));
} catch (final IOException e) {
- LOG.warn("Deleting {} failed", target.resolve("webpapp").toAbsolutePath(), e);
+ log.warn("Deleting {} failed", target.resolve("webpapp").toAbsolutePath(), e);
}
final Path webAppTmp =target.resolve("webpapp.tmp");
try {
DeletingVisitor.deleteTree(webAppTmp);
} catch (final IOException e) {
- LOG.warn("Deleting {} failed", webAppTmp.toAbsolutePath(), e);
+ log.warn("Deleting {} failed", webAppTmp.toAbsolutePath(), e);
}
final Path distWebApp = target.resolve("dist").resolve("webapp");
final Copy initial = InstallerSupport.getCopyTask(distWebApp, webAppTmp);
initial.setPreserveLastModified(true);
initial.setFailOnError(true);
- initial.setVerbose(LOG.isDebugEnabled());
- LOG.info("Initial populate from {} to {}", distWebApp, webAppTmp);
+ initial.setVerbose(log.isDebugEnabled());
+ log.info("Initial populate from {} to {}", distWebApp, webAppTmp);
initial.execute();
-
- final Path editWebApp = target.resolve("edit-webapp");
+
+ final Path editWebApp = target.resolve("edit-webapp");
final Copy overlay = InstallerSupport.getCopyTask(editWebApp, webAppTmp);
overlay.setOverwrite(true);
overlay.setPreserveLastModified(true);
overlay.setFailOnError(true);
- overlay.setVerbose(LOG.isDebugEnabled());
- LOG.info("Overlay from {} to {}", editWebApp, webAppTmp);
+ overlay.setVerbose(log.isDebugEnabled());
+ log.info("Overlay from {} to {}", editWebApp, webAppTmp);
overlay.execute();
warFile.toFile().delete();
@@ -86,26 +92,12 @@ public final class BuildWar {
jarTask.setDestFile(warFile.toFile());
jarTask.setBasedir(webAppTmp.toFile());
jarTask.setProject(InstallerSupport.ANT_PROJECT);
- LOG.info("Creating war file {}", warFile);
+ log.info("Creating war file {}", warFile);
jarTask.execute();
try {
DeletingVisitor.deleteTree(webAppTmp);
} catch (final IOException e) {
- LOG.warn("Deleting {} failed", webAppTmp, e);
- }
- }
-
- /** Program entry to build war. Calls {@link #buildWar(InstallerProperties)}.
- * @param args input
- */
- public static void main(final String[] args) {
- try {
- LOG.error("Starting build");
- final InstallerProperties ip = new InstallerProperties(true);
- ip.initialize();
- buildWar(ip);
- } catch (final Throwable e) {
- LOG.error("Build WebApp failed", e);
+ log.warn("Deleting {} failed", webAppTmp, e);
}
}
}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistributions.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistributions.java
index 43079f5..48a377d 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistributions.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistributions.java
@@ -27,27 +27,34 @@ import org.apache.tools.ant.taskdefs.Copy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
+/**
* Copy the distribution to its final location.
*/
public final class CopyDistributions {
/** Log. */
- public static final Logger LOG = LoggerFactory.getLogger(CopyDistributions.class);
+ private final Logger log = LoggerFactory.getLogger(CopyDistributions.class);
- /** Private Constructor. */
- private CopyDistributions() { }
+ /** Properties for the job. */
+ private final InstallerProperties installerProps;
+
+ /** Constructor.
+ * @param props The environment for the work.
+ */
+ public CopyDistributions(final InstallerProperties props) {
+ installerProps = props;
+ }
/** Copy the distribution from the dstribution to its new location.
* @param ip what drives the install.
* @throws BuildException if badness occurs
*/
- public static void copyDistribution(final InstallerProperties ip) throws BuildException {
- backupOld(ip);
- deleteOld(ip);
- copyDist(ip);
- copyBinDocSystem(ip);
- createUserFolders(ip);
+ public void execute(final InstallerProperties ip) throws BuildException {
+ backupOld();
+ deleteOld();
+ copyDist();
+ copyBinDocSystem();
+ createUserFolders();
}
/** Helper for the {@link #backupOld(InstallerProperties)} method.
@@ -55,60 +62,58 @@ public final class CopyDistributions {
* @param to where to.
* @throws BuildException if badness occurs
*/
- private static void backup(final Path from, final Path to) throws BuildException {
- LOG.debug("Backing up From {} to {}", from, to);
+ private void backup(final Path from, final Path to) throws BuildException {
+ log.debug("Backing up From {} to {}", from, to);
final Copy copy = InstallerSupport.getCopyTask(from, to);
copy.setFailOnError(false);
copy.execute();
}
- /** Copy bin, edit-webapp, dist and doc to old-date-time.
- * @param ip The configuration for this install
+ /** Copy bin, edit-webapp, dist and doc to old-date-time.
* @throws BuildException if badness occurs
*/
- protected static void backupOld(final InstallerProperties ip) throws BuildException {
- final Path backup = ip.getTargetDir().resolve("Old-" + Instant.now().toString());
+ protected void backupOld() throws BuildException {
+ final Path backup = installerProps.getTargetDir().resolve("Old-" + Instant.now().toString());
InstallerSupport.createDirectory(backup);
- backup(ip.getTargetDir().resolve("edit-webapp"), backup.resolve("edit-webapp"));
- backup(ip.getTargetDir().resolve("doc"), backup.resolve("doc"));
- backup(ip.getTargetDir().resolve("system"), backup.resolve("system"));
+ backup(installerProps.getTargetDir().resolve("edit-webapp"), backup.resolve("edit-webapp"));
+ backup(installerProps.getTargetDir().resolve("doc"), backup.resolve("doc"));
+ backup(installerProps.getTargetDir().resolve("system"), backup.resolve("system"));
}
/** Helper for the delete {@link #deleteOld(InstallerProperties)} method.
* @param what what to delete
*/
- private static void delete(final Path what) {
+ private void delete(final Path what) {
if (!Files.exists(what)) {
- LOG.debug("{} doesn't exist, ignoring", what);
+ log.debug("{} doesn't exist, ignoring", what);
} else if (Files.isDirectory(what)) {
throw new BuildException("Corrupt install " + what + " is not a directory");
} else {
- LOG.debug("Deleteing {} ", what);
+ log.debug("Deleteing {} ", what);
try {
DeletingVisitor.deleteTree(what);
} catch (final IOException e) {
- LOG.warn("Deleting {} failed", what, e);
+ log.warn("Deleting {} failed", what, e);
}
}
}
-
+
/** Delete old copies of bin/lib (leaving bin for scripts), disty, doc and system.
* system has to be unprotected first which also means we need to create it too.
- * @param ip The configuration for this install
* @throws BuildException if badness occurs
*/
- protected static void deleteOld(final InstallerProperties ip) {
- delete(ip.getTargetDir().resolve("bin").resolve("lib"));
- delete(ip.getTargetDir().resolve("dist"));
- delete(ip.getTargetDir().resolve("doc"));
- final Path system = ip.getTargetDir().resolve("system");
+ protected void deleteOld() {
+ delete(installerProps.getTargetDir().resolve("bin").resolve("lib"));
+ delete(installerProps.getTargetDir().resolve("dist"));
+ delete(installerProps.getTargetDir().resolve("doc"));
+ final Path system = installerProps.getTargetDir().resolve("system");
if (Files.exists(system)) {
- LOG.debug("Clearing {} readonly (id Windows)", system);
+ log.debug("Clearing {} readonly (id Windows)", system);
InstallerSupport.setReadOnly(system, false);
}
delete(system);
}
-
+
/** Helper for the delete {@link #copyDist(InstallerProperties)} and
* {@link #copyBinDocSystem(InstallerProperties)} methods.
@@ -117,24 +122,23 @@ public final class CopyDistributions {
* @param to the subfolder name
* @throws BuildException if badness occurs
*/
- private static void distCopy(final Path srcDist, final Path dist, final String to) throws BuildException {
+ private void distCopy(final Path srcDist, final Path dist, final String to) throws BuildException {
final Path toPath = dist.resolve(to);
final Path fromPath = srcDist.resolve(to);
- LOG.debug("Copying distribution from {} to {}", fromPath, toPath);
+ log.debug("Copying distribution from {} to {}", fromPath, toPath);
final Copy copy = InstallerSupport.getCopyTask(fromPath, toPath);
copy.execute();
}
/** Populate the dist folder.
- * @param ip The configuration for this install
* @throws BuildException if badness occurs
*/
- protected static void copyDist(final InstallerProperties ip) {
- final Path dist = ip.getTargetDir().resolve("dist");
+ protected void copyDist() {
+ final Path dist = installerProps.getTargetDir().resolve("dist");
InstallerSupport.createDirectory(dist);
- final Path src = ip.getSourceDir().resolve("dist");
+ final Path src = installerProps.getSourceDir().resolve("dist");
if (!Files.exists(src)) {
- LOG.error("Source distribution {} not found", src);
+ log.error("Source distribution {} not found", src);
throw new BuildException("Source distribution not found");
}
distCopy(src, dist, "conf");
@@ -145,22 +149,20 @@ public final class CopyDistributions {
}
/** Populate the per distribution (but non dist) folders.
- * @param ip The configuration for this install
* @throws BuildException if badness occurs
*/
- protected static void copyBinDocSystem(final InstallerProperties ip) {
- distCopy(ip.getSourceDir(), ip.getTargetDir(), "bin");
- distCopy(ip.getSourceDir(), ip.getTargetDir(), "doc");
- distCopy(ip.getSourceDir(), ip.getTargetDir(), "system");
+ protected void copyBinDocSystem() {
+ distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "bin");
+ distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "doc");
+ distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "system");
}
-
+
/** Create (if they do not exist) the user editable folders, suitable for
* later population during update or install.
- * @param ip The configuration for this install
* @throws BuildException if badness occurs
*/
- protected static void createUserFolders(final InstallerProperties ip) {
- final Path target = ip.getTargetDir();
+ protected void createUserFolders() {
+ final Path target = installerProps.getTargetDir();
InstallerSupport.createDirectory(target.resolve("conf"));
InstallerSupport.createDirectory(target.resolve("credentials"));
InstallerSupport.createDirectory(target.resolve("flows"));
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/KeyManagement.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/KeyManagement.java
index 5f9d6ec..e97575b 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/KeyManagement.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/KeyManagement.java
@@ -31,136 +31,141 @@ import net.shibboleth.utilities.java.support.security.SelfSignedCertificateGener
/**
* Create (if needs be) all the keys needed by an install.
*/
-public final class KeyManagement {
+public class KeyManagement {
/** Log. */
- public static final Logger LOG = LoggerFactory.getLogger(KeyManagement.class);
+ private final Logger log = LoggerFactory.getLogger(KeyManagement.class);
- /** Private Constructor. */
- private KeyManagement() { }
+ /** Properties for the job. */
+ private final InstallerProperties installerProps;
+
+ /** Constructor.
+ * @param props The environment for the work.
+ */
+ public KeyManagement(final InstallerProperties props) {
+ installerProps = props;
+ }
/** Create any keys that are needed.
- * @param ip what drives the install.
* @throws BuildException if badness occurs
*/
- public static void manageKeys(final InstallerProperties ip) throws BuildException {
-
- generateKey(ip, "idp-signing");
- generateKey(ip, "idp-encryption");
- generateKeyStore(ip);
- generateSealer(ip);
+ public void execute() throws BuildException {
+ generateKey("idp-signing");
+ generateKey("idp-encryption");
+ generateKeyStore();
+ generateSealer();
}
/** Helper method for {@link #manageKeys(InstallerProperties)} to generate a crt and key file.
- * @param ip the Configuration
* @param fileBase the partial file name
* @throws BuildException if badness occurrs.
*/
- private static void generateKey(final InstallerProperties ip, final String fileBase) throws BuildException {
- final Path credentials = ip.getTargetDir().resolve("credentials");
+ private void generateKey(final String fileBase) throws BuildException {
+ final Path credentials = installerProps.getTargetDir().resolve("credentials");
final Path key = credentials.resolve(fileBase+".key");
final Path crt = credentials.resolve(fileBase+".crt");
if (Files.exists(key) && Files.exists(crt)) {
- if (!ip.isIdPPropertiesPresent()) {
- LOG.error("key files {} and {} exist but idp.properties does not", key, crt);
+ if (!installerProps.isIdPPropertiesPresent()) {
+ log.error("key files {} and {} exist but idp.properties does not", key, crt);
throw new BuildException("Invalid key file configuration");
}
- LOG.debug("keys files {} and {} exist. Not generating", key, crt);
- } else if (ip.isIdPPropertiesPresent()) {
- LOG.error("idp.properties exists but key files {} and/or {} do not", key, crt);
+ log.debug("keys files {} and {} exist. Not generating", key, crt);
+ } else if (installerProps.isIdPPropertiesPresent()) {
+ log.error("idp.properties exists but key files {} and/or {} do not", key, crt);
throw new BuildException("Invalid key file configuration");
} else if (Files.exists(key) || Files.exists(crt)) {
- LOG.error("One of two expected key files {} and {} exist", key, crt);
+ log.error("One of two expected key files {} and {} exist", key, crt);
throw new BuildException("Invalid key file configuration");
} else {
final SelfSignedCertificateGenerator generator = new SelfSignedCertificateGenerator();
generator.setCertificateFile(crt.toFile());
generator.setPrivateKeyFile(key.toFile());
- generator.setKeySize(ip.getKeySize());
- generator.setHostName(ip.getHostName());
- generator.setURISubjectAltNames(Collections.singletonList(ip.getSubjectAltName()));
- LOG.info("Creating {}, CN = {} URI = {}", fileBase, ip.getHostName(), ip.getSubjectAltName());
+ generator.setKeySize(installerProps.getKeySize());
+ generator.setHostName(installerProps.getHostName());
+ generator.setURISubjectAltNames(Collections.singletonList(installerProps.getSubjectAltName()));
+ log.info("Creating {}, CN = {} URI = {}", fileBase,
+ installerProps.getHostName(), installerProps.getSubjectAltName());
try {
generator.generate();
} catch (final Exception e) {
- LOG.error("Error building {} files", fileBase, e);
+ log.error("Error building {} files", fileBase, e);
throw new BuildException("Error Building Self Signed Cert", e);
}
}
}
/** Helper method for {@link #manageKeys(InstallerProperties)} to generate the backchannel keystore.
- * @param ip the Configuration
* @throws BuildException if badness occurrs.
*/
- private static void generateKeyStore(final InstallerProperties ip) {
- final Path credentials = ip.getTargetDir().resolve("credentials");
+ private void generateKeyStore() {
+ final Path credentials = installerProps.getTargetDir().resolve("credentials");
final Path keyStore = credentials.resolve("idp-backchannel.p12");
final Path crt = credentials.resolve("idp-backchannel.crt");
if (Files.exists(keyStore) && Files.exists(crt)) {
- if (!ip.isIdPPropertiesPresent()) {
- LOG.error("Key store files {} and {} exist but idp.properties does not", keyStore, crt);
+ if (!installerProps.isIdPPropertiesPresent()) {
+ log.error("Key store files {} and {} exist but idp.properties does not", keyStore, crt);
throw new BuildException("Invalid key file configuration");
}
- LOG.debug("Keys store files {} and {} exist. Not generating", keyStore, crt);
- } else if (ip.isIdPPropertiesPresent()) {
- LOG.error("idp.properties exists but key store files {} and/or {} do not", keyStore, crt);
+ log.debug("Keys store files {} and {} exist. Not generating", keyStore, crt);
+ } else if (installerProps.isIdPPropertiesPresent()) {
+ log.error("idp.properties exists but key store files {} and/or {} do not", keyStore, crt);
throw new BuildException("Invalid key file configuration");
} else if (Files.exists(keyStore) || Files.exists(crt)) {
- LOG.error("One of two expected key files {} and {} exist", keyStore, crt);
+ log.error("One of two expected key files {} and {} exist", keyStore, crt);
throw new BuildException("Invalid key file configuration");
} else {
final SelfSignedCertificateGenerator generator = new SelfSignedCertificateGenerator();
generator.setCertificateFile(crt.toFile());
generator.setKeystoreFile(keyStore.toFile());
- generator.setKeySize(ip.getKeySize());
- generator.setHostName(ip.getHostName());
- generator.setURISubjectAltNames(Collections.singletonList(ip.getSubjectAltName()));
- generator.setKeystorePassword(ip.getKeyStorePassword());
- LOG.info("Creating backchannel keystore, CN = {} URI = {}", ip.getHostName(), ip.getSubjectAltName());
+ generator.setKeySize(installerProps.getKeySize());
+ generator.setHostName(installerProps.getHostName());
+ generator.setURISubjectAltNames(Collections.singletonList(installerProps.getSubjectAltName()));
+ generator.setKeystorePassword(installerProps.getKeyStorePassword());
+ log.info("Creating backchannel keystore, CN = {} URI = {}",
+ installerProps.getHostName(), installerProps.getSubjectAltName());
try {
generator.generate();
} catch (final Exception e) {
- LOG.error("Error building backchannel ketsyore files", e);
+ log.error("Error building backchannel ketsyore files", e);
throw new BuildException("Error Building Backchannel Key Store", e);
}
}
}
/** Helper method for {@link #manageKeys(InstallerProperties)} to generate the Sealer.
- * @param ip the Configuration
* @throws BuildException if badness occurrs.
*/
- private static void generateSealer(final InstallerProperties ip) {
- final Path credentials = ip.getTargetDir().resolve("credentials");
+ private void generateSealer() {
+ final Path credentials = installerProps.getTargetDir().resolve("credentials");
final Path sealer = credentials.resolve("sealer.jks");
final Path versionFile = credentials.resolve("sealer.kver");
if (Files.exists(sealer) && Files.exists(versionFile)) {
- if (!ip.isIdPPropertiesPresent()) {
- LOG.error("Cookie encryption files {} and {} exist but idp.properties does not", sealer, versionFile);
+ if (!installerProps.isIdPPropertiesPresent()) {
+ log.error("Cookie encryption files {} and {} exist but idp.properties does not", sealer, versionFile);
throw new BuildException("Invalid Cookie encryption file configuration");
}
- LOG.debug("Cookie encryption files {} and {} exists. Not generating.", sealer, versionFile);
- } else if (ip.isIdPPropertiesPresent()) {
- LOG.error("idp.properties exists but cookie encryption files {} do not", sealer, versionFile);
+ log.debug("Cookie encryption files {} and {} exists. Not generating.", sealer, versionFile);
+ } else if (installerProps.isIdPPropertiesPresent()) {
+ log.error("idp.properties exists but cookie encryption files {} do not", sealer, versionFile);
throw new BuildException("Invalid key file configuration");
} else if (Files.exists(sealer) || Files.exists(versionFile)) {
- LOG.error("One of two expected cookie encryption file {} and {} exist", sealer, versionFile);
+ log.error("One of two expected cookie encryption file {} and {} exist", sealer, versionFile);
throw new BuildException("Invalid cookie encryption file configuration");
} else {
final BasicKeystoreKeyStrategyTool generator = new BasicKeystoreKeyStrategyTool();
generator.setKeystoreFile(sealer.toFile());
generator.setVersionFile(versionFile.toFile());
- generator.setKeyAlias(ip.getSealerAlias());
- generator.setKeystorePassword(ip.getSealerPassword());
- LOG.info("Creating backchannel keystore, CN = {} URI = {}", ip.getHostName(), ip.getSubjectAltName());
+ generator.setKeyAlias(installerProps.getSealerAlias());
+ generator.setKeystorePassword(installerProps.getSealerPassword());
+ log.info("Creating backchannel keystore, CN = {} URI = {}",
+ installerProps.getHostName(), installerProps.getSubjectAltName());
try {
generator.changeKey();
} catch (final Exception e) {
- LOG.error("Error building cookie encryption files", e);
+ log.error("Error building cookie encryption files", e);
throw new BuildException("Error Building Cookie Encryption", e);
}
}
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 7c6e1c0..0a9565e 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
@@ -17,10 +17,8 @@
package net.shibboleth.idp.installer;
-import java.nio.file.Path;
import java.io.IOException;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
+import java.nio.file.Path;
import javax.annotation.Nonnull;
@@ -30,9 +28,6 @@ import org.apache.tools.ant.types.FileSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.shibboleth.idp.installer.impl.CopyingVisitor;
-import net.shibboleth.idp.installer.impl.DeletingVisitor;
-import net.shibboleth.idp.installer.impl.InstallerProperties;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
/**
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list