[java-identity-provider] branch master updated: IDP-1595 Logging, callbacks, failures

Rod Widdowson rdw at steadingsoftware.com
Tue Jul 14 09:54:24 UTC 2020


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=4b43d06beb992f009f25be95f3cfb569c1e46412

The following commit(s) were added to refs/heads/master by this push:
       new  4b43d06be IDP-1595 Logging, callbacks, failures
4b43d06be is described below

commit 4b43d06beb992f009f25be95f3cfb569c1e46412
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jul 14 10:52:50 2020 +0100

    IDP-1595 Logging, callbacks, failures
    
    https://issues.shibboleth.net/jira/browse/IDP-1595
    
    Better logging across the project (typos and indentation)
    A callback to decline downloads
    Fail the install on unsupported functions to do with property
    manipulation.
---
 .../idp/installer/plugin/impl/PluginInstaller.java | 31 ++++++++++++++++++--
 .../idp/installer/plugin/impl/TrustStore.java      |  4 +--
 .../installer/plugin/impl/PluginInstallerTest.java | 33 ++++++++++++++--------
 ...utilities.java.support.plugin.PluginDescription |  1 -
 .../idphome-test/edit-webapp/WEB-INF/lib/.gitkeep  |  0
 5 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
index abdcee379..7c3802967 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
@@ -98,6 +98,9 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
     /** The callback before we install a certificate into the TrustStore. */
     @Nonnull private Predicate<String> acceptCert = Predicates.alwaysFalse();
 
+    /** The callback before we download a file. */
+    @Nonnull private Predicate<Pair<URL,Path>> acceptDownload = Predicates.alwaysFalse();
+
     /** The actual distribution. */
     private Path distribution;
 
@@ -114,15 +117,22 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
     /** Set the plugin in.
      * @param id The pluginId to set.
      */
-    public void setPluginId( @Nonnull @NotEmpty final String id) {
+    public void setPluginId(@Nonnull @NotEmpty final String id) {
         pluginId = Constraint.isNotNull(StringSupport.trimOrNull(id), "Plugin id should be be non-null");
     }
 
     /** Set the acceptCert predicate.
      * @param what what to set.
      */
-    public void setAcceptCert(final Predicate<String> what) {
-        acceptCert = Constraint.isNotNull(what, "Accept Cert Preducate should be non-null");
+    public void setAcceptCert(@Nonnull final Predicate<String> what) {
+        acceptCert = Constraint.isNotNull(what, "Accept Certificate Predicate should be non-null");
+    }
+
+    /** Set the acceptCert predicate.
+     * @param what what to set.
+     */
+    public void setAcceptDownload(@Nonnull final Predicate<Pair<URL,Path>> what) {
+        acceptDownload  = Constraint.isNotNull(what, "Accept Download Predicate should be non-null");
     }
 
     /** Set the httpClient.
@@ -167,6 +177,17 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         setupPluginId();
         checkSignature(base, fileName);
         getDescription();
+        log.info("Installing Plugin {} version {}.{}.{}", pluginId,
+                description.getMajorVersion(),description.getMinorVersion(), description.getPatchVersion());
+
+        if (!description.getAdditionalPropertyFiles().isEmpty()) {
+            log.error("Additional property files not supported");
+            throw new BuildException("Uninstallable plugin");
+        }
+        if (!description.getPropertyMerges().isEmpty()) {
+            log.error("Prroperty merges not supported");
+            throw new BuildException("Uninstallable plugin");
+        }
 
         final Path myWebApp = idpHome.resolve("dist").resolve("edit-webapp-" + pluginId);
         deleteTree(myWebApp);
@@ -194,6 +215,10 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
                     log.warn("{} exists, not copied", to);
                     continue;
                 }
+                if (!acceptDownload.test(new Pair<>(pair.getFirst(), to))) {
+                    log.info("Did not download {} to {}", pair.getFirst(), to);
+                    continue;
+                }
                 buildHttpClient();
                 createParent(to);
                 log.debug("Copying from {} to {}", pair.getFirst(), to);
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
index bd58f3887..965724cee 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
@@ -209,7 +209,7 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
                 log.info("Provided certificate stream did not contain a certificate for {}", sigForCert);
                 return;
             }
-            final StringBuilder builder = new StringBuilder("Certificate:\t").
+            final StringBuilder builder = new StringBuilder("Signature:\t").
                     append(sigForCert.toString()).
                     append("\nFingerPrint:\t").
                     append(new String(Hex.encode(cert.getFingerprint())));
@@ -219,7 +219,7 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
             }
             builder.append('\n');
             final String certInfo = builder.toString();
-            log.debug("Asking to import certificate\n {}", certInfo);
+            log.debug("Asking to import certificate\n{}", certInfo);
             if (!accept.test(certInfo)) {
                 log.info("Certificate import barred by user");
                 return;
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
index ff15e8b9b..4d86be1e9 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.file.Path;
 import java.security.Security;
 import java.util.List;
 import java.util.function.Predicate;
@@ -33,6 +34,7 @@ import org.springframework.core.io.ClassPathResource;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import net.shibboleth.utilities.java.support.collection.Pair;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.plugin.AbstractPluginDescription;
 import net.shibboleth.utilities.java.support.plugin.PluginDescription;
@@ -41,6 +43,20 @@ import net.shibboleth.utilities.java.support.plugin.PluginDescription;
 public class PluginInstallerTest {
 
     private final Logger log = LoggerFactory.getLogger(PluginInstallerTest.class);
+    
+    private final Predicate<String> loggingAcceptCert = new  Predicate<>() {
+        public boolean test(String what) {
+            log.debug("Accepting the certificate\n{}", what);
+            return true;
+        }
+    };
+
+    private final Predicate<Pair<URL, Path>> loggingAcceptDownLoad = new  Predicate<>() {
+        public boolean test(Pair<URL, Path> what) {
+            log.debug("Accepting the download from {} to {}", what.getFirst(), what.getSecond());
+            return true;
+        }
+    };
 
     @BeforeClass public void setup() throws IOException {
         if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
@@ -61,7 +77,8 @@ public class PluginInstallerTest {
     @Test(enabled = false) public void testUnpackZip() throws ComponentInitializationException, IOException {
         try (final PluginInstaller inst = new PluginInstaller()) {
             inst.setIdpHome(new ClassPathResource("idphome-test").getFile().toPath());
-            inst.setAcceptCert(new LoggingAcceptor());
+            inst.setAcceptCert(loggingAcceptCert);
+            inst.setAcceptDownload(loggingAcceptDownLoad);
             inst.initialize();
             final File f = new File("H:\\Perforce\\Juno\\New\\plugins\\java-idp-plugin-scripting\\rhino-dist\\target");
             inst.installPlugin(f.toPath(),"shibboleth-idp-plugin-rhino-0.0.1-SNAPSHOT.zip");
@@ -71,7 +88,8 @@ public class PluginInstallerTest {
     @Test(enabled = false) public void testUnpackTgz() throws ComponentInitializationException, IOException {
         try (final PluginInstaller inst = new PluginInstaller()) {
             inst.setIdpHome(new ClassPathResource("idphome-test").getFile().toPath());
-            inst.setAcceptCert(new LoggingAcceptor());
+            inst.setAcceptCert(loggingAcceptCert);
+            inst.setAcceptDownload(loggingAcceptDownLoad);
             inst.initialize();
             final File f = new File("H:\\Perforce\\Juno\\New\\plugins\\java-idp-plugin-scripting\\nashorn-dist\\target");
             inst.installPlugin(f.toPath(),"shibboleth-idp-plugin-nashorn-0.0.1-SNAPSHOT.tar.gz");
@@ -81,7 +99,8 @@ public class PluginInstallerTest {
     @Test(enabled = false) public void testDownload() throws ComponentInitializationException, IOException {
         try (final PluginInstaller inst = new PluginInstaller()) {
             inst.setIdpHome(new ClassPathResource("idphome-test").getFile().toPath());
-            inst.setAcceptCert(new LoggingAcceptor());
+            inst.setAcceptCert(loggingAcceptCert);
+            inst.setAcceptDownload(loggingAcceptDownLoad);
             inst.initialize();
             final URL url = new URL("http://iis.steadingsoftware.net/plugins/");
             inst.installPlugin(url,"shibboleth-idp-plugin-nashorn-0.0.1-SNAPSHOT.tar.gz");
@@ -113,12 +132,4 @@ public class PluginInstallerTest {
         
     }
 
-    public class LoggingAcceptor implements Predicate<String> {
-
-        /** {@inheritDoc} */
-        public boolean test(String what) {
-            log.debug("Accepting the cetrtificate {}", what);
-            return true;
-        }
-    }
 }
diff --git a/idp-installer/src/test/resources/idphome-test/dist/org.example.Plugin/WEB-INF/lib/RandomFileName/META-INF/services/net.shibboleth.utilities.java.support.plugin.PluginDescription b/idp-installer/src/test/resources/idphome-test/dist/org.example.Plugin/WEB-INF/lib/RandomFileName/META-INF/services/net.shibboleth.utilities.java.support.plugin.PluginDescription
deleted file mode 100644
index 0aeabcaf2..000000000
--- a/idp-installer/src/test/resources/idphome-test/dist/org.example.Plugin/WEB-INF/lib/RandomFileName/META-INF/services/net.shibboleth.utilities.java.support.plugin.PluginDescription
+++ /dev/null
@@ -1 +0,0 @@
-net.shibboleth.idp.installer.plugin.impl.PluginInstallerTest$Wibble
diff --git a/idp-installer/src/test/resources/idphome-test/edit-webapp/WEB-INF/lib/.gitkeep b/idp-installer/src/test/resources/idphome-test/edit-webapp/WEB-INF/lib/.gitkeep
new file mode 100644
index 000000000..e69de29bb

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


More information about the commits mailing list