[java-identity-provider] 01/02: IDP-1595 Add an IdP Home- aware command line class

Rod Widdowson rdw at steadingsoftware.com
Wed Aug 19 15:53:18 UTC 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=fa5cac96e84d0ddc7b01e4eec3c2de10250cabcf

commit fa5cac96e84d0ddc7b01e4eec3c2de10250cabcf
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Aug 19 15:19:10 2020 +0100

    IDP-1595 Add an IdP Home- aware command line class
    
    https://issues.shibboleth.net/jira/browse/IDP-1595
    
    This makes IdP home processing that the plugin installer uses
    avaiable to other command lines.
---
 .../idp/cli/AbstractIdPHomeAwareCommandLine.java   | 92 ++++++++++++++++++++++
 .../idp/installer/plugin/PluginInstallerCLI.java   | 57 +-------------
 2 files changed, 96 insertions(+), 53 deletions(-)

diff --git a/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLine.java b/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLine.java
new file mode 100644
index 000000000..a8d1fa485
--- /dev/null
+++ b/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLine.java
@@ -0,0 +1,92 @@
+/*
+ * 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.cli;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import net.shibboleth.ext.spring.cli.AbstractCommandLine;
+import net.shibboleth.ext.spring.cli.CommandLineArguments;
+import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/**
+ * An extension to {@link AbstractCommandLine} that understand that idp.home is set via a property
+ * when called inside the IdP.
+
+ * @param <T> argument object type
+ */
+public abstract class AbstractIdPHomeAwareCommandLine<T extends CommandLineArguments> extends AbstractCommandLine<T> {
+
+    /** Where the IdP is installed to. */
+    @Nullable private Path idpHome;
+    
+    /**
+     * Constructor.
+     */
+    protected AbstractIdPHomeAwareCommandLine() {
+        setIdpHome(StringSupport.trimOrNull(System.getProperty("net.shibboleth.idp.cli.idp.home")));
+        setContextInitializer(this.new Initializer());
+    }
+
+    /** Set where the IdP is installed to.
+     * @param home where
+     */
+    protected void setIdpHome(@Nullable final String home) {
+        if (home == null) {
+            getLogger().error("net.shibboleth.idp.cli.idp.home propert not send.  Could not find IdP Home directory");
+            return;
+        }
+        idpHome = Path.of(home);
+        
+        if (!Files.exists(idpHome) || !Files.isDirectory(idpHome)) {
+            getLogger().error("IdP Home Directory {} did not exist or was not a directory", idpHome);
+            idpHome = null;
+        }
+    }
+    
+    /** Return where the IdP is installed to.
+     * @return the home directory.
+     */
+    @Nullable protected Path getIdpHome() {
+        return idpHome;
+    }
+    
+    /**
+     * An {@link ApplicationContextInitializer} which knows about our idp.home.
+     */
+    private class Initializer extends IdPPropertiesApplicationContextInitializer {
+
+        /** {@inheritDoc} */
+        @Override @Nonnull public String selectSearchLocation(
+                @Nonnull final ConfigurableApplicationContext applicationContext) {
+            return idpHome.toString();
+        }
+
+        /** {@inheritDoc} */
+        @Override @Nonnull public String getSearchLocation() {
+            return idpHome.toString();
+        }
+    }
+}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
index e45caf29a..b8c3d390d 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
@@ -17,8 +17,6 @@
 
 package net.shibboleth.idp.installer.plugin;
 
-import java.nio.file.Files;
-import java.nio.file.Path;
 import java.security.Security;
 import java.util.List;
 import java.util.Map;
@@ -34,33 +32,27 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContextInitializer;
-import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 
 import net.shibboleth.ext.spring.cli.AbstractCommandLine;
 import net.shibboleth.idp.Version;
+import net.shibboleth.idp.cli.AbstractIdPHomeAwareCommandLine;
 import net.shibboleth.idp.installer.plugin.impl.PluginInstaller;
 import net.shibboleth.idp.plugin.PluginDescription;
 import net.shibboleth.idp.plugin.PluginVersion;
 import net.shibboleth.idp.plugin.impl.PluginState;
 import net.shibboleth.idp.plugin.impl.PluginState.VersionInfo;
-import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /**
  * Command line for Plugin Installation.
  */
-public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstallerArguments> {
+public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<PluginInstallerArguments> {
 
     /** Class logger. */
     @Nullable private Logger log;
     
-    /** Where the IdP is installed to. */
-    @Nullable private Path idpHome;
-
     /** A Plugin Installer to use. */
     private PluginInstaller installer;
     
@@ -71,34 +63,9 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
      * Constrained Constructor.
      */
     private PluginInstallerCLI() {
-        setIdpHome(StringSupport.trimOrNull(System.getProperty("net.shibboleth.idp.cli.idp.home")));
-        setContextInitializer(this.new Initializer());
-    }
-
-    /** Set where the IdP is installed to.
-     * @param home where
-     */
-    protected void setIdpHome(@Nullable final String home) {
-        if (home == null) {
-            getLogger().error("net.shibboleth.idp.cli.idp.home propert not send.  Could not find IdP Home directory");
-            return;
-        }
-        idpHome = Path.of(home);
-        
-        if (!Files.exists(idpHome) || !Files.isDirectory(idpHome)) {
-            getLogger().error("IdP Home Directory {} did not exist or was not a directory", idpHome);
-            idpHome = null;
-        }
-    }
-    
-    /** Return where the IdP is installed to.
-     * @return the home directory.
-     */
-    @Nullable protected Path getIdpHome() {
-        return idpHome;
+        super();
     }
 
-
     /** {@inheritDoc} */
     @Override
     @Nonnull protected Logger getLogger() {
@@ -191,7 +158,7 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
      * @throws ComponentInitializationException as required*/
     private void constructPluginInstaller() throws ComponentInitializationException {
         installer= new PluginInstaller();
-        installer.setIdpHome(idpHome);
+        installer.setIdpHome(getIdpHome());
         if (httpClient!= null) {
             installer.setHttpClient(httpClient);
         }
@@ -275,20 +242,4 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
         System.exit(runMain(args));
     }
 
-    /**
-     * An {@link ApplicationContextInitializer} which knows about our idp.home.
-     */
-    private class Initializer extends IdPPropertiesApplicationContextInitializer {
-
-        /** {@inheritDoc} */
-        @Override @Nonnull public String selectSearchLocation(
-                @Nonnull final ConfigurableApplicationContext applicationContext) {
-            return idpHome.toString();
-        }
-
-        /** {@inheritDoc} */
-        @Override @Nonnull public String getSearchLocation() {
-            return idpHome.toString();
-        }
-    }
 }

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


More information about the commits mailing list