[java-identity-provider] branch main updated: Factor HTTP client support up to CLI base class.
Scott Cantor
cantor.2 at osu.edu
Tue Sep 8 21:19:55 UTC 2020
This is an automated email from the git hooks/post-receive script.
scantor 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=7b700a90e8265e19e8558664b076f93a82ddb7fb
The following commit(s) were added to refs/heads/main by this push:
new 7b700a90e Factor HTTP client support up to CLI base class.
7b700a90e is described below
commit 7b700a90e8265e19e8558664b076f93a82ddb7fb
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Sep 8 17:19:30 2020 -0400
Factor HTTP client support up to CLI base class.
---
.../idp/module/impl/ModuleManagerArguments.java | 37 +-------------
.../idp/module/impl/ModuleManagerCLI.java | 34 +------------
.../idp/cli/AbstractIdPHomeAwareCommandLine.java | 56 ++++++++++++++++++++--
.../AbstractIdPHomeAwareCommandLineArguments.java | 47 +++++++++++++++++-
.../installer/plugin/PluginInstallerArguments.java | 15 ------
.../idp/installer/plugin/PluginInstallerCLI.java | 47 ++++++------------
6 files changed, 118 insertions(+), 118 deletions(-)
diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java
index 3a3ba59f2..d104da316 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerArguments.java
@@ -25,8 +25,6 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.apache.http.client.HttpClient;
-import org.opensaml.security.httpclient.HttpClientSecurityParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,7 +33,6 @@ import com.beust.jcommander.Parameter;
import net.shibboleth.idp.cli.AbstractIdPHomeAwareCommandLineArguments;
import net.shibboleth.idp.module.IdPModule;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
@@ -67,14 +64,6 @@ public class ModuleManagerArguments extends AbstractIdPHomeAwareCommandLineArgum
@Parameter(names= {"-f", "--clean"})
@Nullable private boolean clean;
- /** Name for the {@link HttpClient} . */
- @Parameter(names= {"-h", "--http-client"})
- @Nullable @NotEmpty private String httpClientName;
-
- /** Name for the {@link HttpClientSecurityParameters} . */
- @Parameter(names= {"-s", "--http-security"})
- @Nullable @NotEmpty private String httpClientSecurityParametersName;
-
/** {@inheritDoc} */
@Nonnull public Logger getLog() {
if (log == null) {
@@ -128,24 +117,6 @@ public class ModuleManagerArguments extends AbstractIdPHomeAwareCommandLineArgum
return clean;
}
- /**
- * Get bean name for the {@link HttpClient} (if specified).
- *
- * @return the name or null
- */
- @Nullable @NotEmpty public String getHttpClientName() {
- return httpClientName;
- }
-
- /**
- * Get bean name for the {@link HttpClientSecurityParameters} (if specified).
- *
- * @return the name or null
- */
- @Nullable @NotEmpty public String getHttpClientSecurityParameterstName() {
- return httpClientSecurityParametersName;
- }
-
/** {@inheritDoc} */
@Override
public void validate() throws IllegalArgumentException {
@@ -177,15 +148,11 @@ public class ModuleManagerArguments extends AbstractIdPHomeAwareCommandLineArgum
out.println(String.format(" %-22s %s", "-al, --full-list",
"Full details on all installed modules"));
out.println(String.format(" %-22s %s", "-e, --enable <id>",
- "Enable module"));
+ "Enable module(s)"));
out.println(String.format(" %-22s %s", "-u, --disable <id>",
- "Disable module"));
+ "Disable module(s)"));
out.println(String.format(" %-22s %s", "-f, --clean",
"Clean disabled files instead of preserving them"));
- out.println(String.format(" %-22s %s", "-h, --http-client <bean name>",
- "Use the named bean for HTTP operations"));
- out.println(String.format(" %-22s %s", "-s, --http-security <bean name>",
- "Use the named bean for HTTP security"));
out.println();
}
}
\ No newline at end of file
diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java
index 379899636..e7f53685c 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java
@@ -29,11 +29,8 @@ import java.util.ServiceLoader;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.apache.http.client.HttpClient;
-import org.opensaml.security.httpclient.HttpClientSecurityParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -58,12 +55,6 @@ public final class ModuleManagerCLI extends AbstractIdPHomeAwareCommandLine<Modu
/** Class logger. */
@Nullable private Logger log;
- /** The injected HttpClient. */
- @Nullable private HttpClient httpClient;
-
- /** Injected security parameters. */
- @Nullable private HttpClientSecurityParameters httpClientSecurityParameters;
-
/** {@inheritDoc} */
@Override
@Nonnull protected Logger getLogger() {
@@ -99,32 +90,11 @@ public final class ModuleManagerCLI extends AbstractIdPHomeAwareCommandLine<Modu
return ret;
}
- final String clientName = args.getHttpClientName() != null ? args.getHttpClientName() :
- "shibboleth.InternalHttpClient";
- try {
- httpClient = getApplicationContext().getBean(clientName, HttpClient.class);
- } catch (final NoSuchBeanDefinitionException e) {
- log.error("Could not locate HttpClient '{}'", clientName);
- return RC_IO;
- }
-
- if (args.getHttpClientSecurityParameterstName() != null) {
- try {
- httpClientSecurityParameters =
- getApplicationContext().getBean(args.getHttpClientSecurityParameterstName(),
- HttpClientSecurityParameters.class);
- } catch (final NoSuchBeanDefinitionException e) {
- log.error("Could not locate HttpClientSecurityParameters '{}'",
- args.getHttpClientSecurityParameterstName());
- return RC_IO;
- }
- }
-
try {
final ModuleContext moduleContext =
new ModuleContext(getApplicationContext().getEnvironment().getProperty("idp.home"));
- moduleContext.setHttpClient(httpClient);
- moduleContext.setHttpClientSecurityParameters(httpClientSecurityParameters);
+ moduleContext.setHttpClient(getHttpClient());
+ moduleContext.setHttpClientSecurityParameters(getHttpClientSecurityParameters());
if (args.getList() || args.getFullList()) {
doList(moduleContext, args.getFullList());
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
index eb1ff6f38..3a708fe79 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLine.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLine.java
@@ -18,6 +18,11 @@
package net.shibboleth.idp.cli;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.http.client.HttpClient;
+import org.opensaml.security.httpclient.HttpClientSecurityParameters;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import net.shibboleth.ext.spring.cli.AbstractCommandLine;
import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
@@ -33,10 +38,28 @@ import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
public abstract class AbstractIdPHomeAwareCommandLine<T extends AbstractIdPHomeAwareCommandLineArguments>
extends AbstractCommandLine<T> {
+ /** The injected HttpClient. */
+ @Nullable private HttpClient httpClient;
+
+ /** Injected security parameters. */
+ @Nullable private HttpClientSecurityParameters httpClientSecurityParameters;
+
/**
- * Constructor.
+ * Gets the {@link HttpClient} to use.
+ *
+ * @return the HTTP client to use
*/
- protected AbstractIdPHomeAwareCommandLine() {
+ @Nullable public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ /**
+ * Gets the {@link HttpClientSecurityParameters} to use.
+ *
+ * @return the HTTP client security parameters to use
+ */
+ @Nullable public HttpClientSecurityParameters getHttpClientSecurityParameters() {
+ return httpClientSecurityParameters;
}
/** {@inheritDoc} */
@@ -46,7 +69,34 @@ public abstract class AbstractIdPHomeAwareCommandLine<T extends AbstractIdPHomeA
System.setProperty("idp.home", args.getIdPHome());
}
setContextInitializer(new IdPPropertiesApplicationContextInitializer());
- return super.doRun(args);
+
+ final int rc = super.doRun(args);
+ if (rc != RC_OK) {
+ return rc;
+ }
+
+ if (args.getHttpClientName() != null) {
+ try {
+ httpClient = getApplicationContext().getBean(args.getHttpClientName(), HttpClient.class);
+ } catch (final NoSuchBeanDefinitionException e) {
+ getLogger().error("Could not locate HttpClient '{}'", args.getHttpClientName());
+ return RC_IO;
+ }
+ }
+
+ if (args.getHttpClientSecurityParameterstName() != null) {
+ try {
+ httpClientSecurityParameters =
+ getApplicationContext().getBean(args.getHttpClientSecurityParameterstName(),
+ HttpClientSecurityParameters.class);
+ } catch (final NoSuchBeanDefinitionException e) {
+ getLogger().error("Could not locate HttpClientSecurityParameters '{}'",
+ args.getHttpClientSecurityParameterstName());
+ return RC_IO;
+ }
+ }
+
+ return RC_OK;
}
}
\ No newline at end of file
diff --git a/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLineArguments.java b/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLineArguments.java
index da088510d..a90c67c40 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLineArguments.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractIdPHomeAwareCommandLineArguments.java
@@ -21,11 +21,17 @@ import java.io.PrintStream;
import javax.annotation.Nullable;
+import org.apache.http.client.HttpClient;
+import org.opensaml.security.httpclient.HttpClientSecurityParameters;
+
import com.beust.jcommander.Parameter;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
/**
* An extension to {@link net.shibboleth.ext.spring.cli.AbstractCommandLineArguments}
- * that allows idp.home override.
+ * that allows idp.home override and includes HTTP client support.
*
* @since 4.1.0
*/
@@ -36,6 +42,14 @@ public abstract class AbstractIdPHomeAwareCommandLineArguments
@Parameter(names = "--home")
@Nullable private String idpHome;
+ /** Name for the {@link HttpClient} . */
+ @Parameter(names= {"-hc", "--http-client"})
+ @Nullable @NotEmpty private String httpClientName;
+
+ /** Name for the {@link HttpClientSecurityParameters} . */
+ @Parameter(names= {"-hs", "--http-security"})
+ @Nullable @NotEmpty private String httpClientSecurityParametersName;
+
/**
* Gets the configured home location.
*
@@ -45,12 +59,43 @@ public abstract class AbstractIdPHomeAwareCommandLineArguments
return idpHome;
}
+ /**
+ * Get bean name for the {@link HttpClient} (if specified).
+ *
+ * @return the name or null
+ */
+ @Nullable @NotEmpty public String getHttpClientName() {
+ return httpClientName;
+ }
+
+ /**
+ * Set bean name for the {@link HttpClient}.
+ *
+ * @param name bean name
+ */
+ public void setHttpClientName(@Nullable @NotEmpty final String name) {
+ httpClientName = StringSupport.trimOrNull(name);
+ }
+
+ /**
+ * Get bean name for the {@link HttpClientSecurityParameters} (if specified).
+ *
+ * @return the name or null
+ */
+ @Nullable @NotEmpty public String getHttpClientSecurityParameterstName() {
+ return httpClientSecurityParametersName;
+ }
+
/** {@inheritDoc} */
@Override
public void printHelp(final PrintStream out) {
super.printHelp(out);
out.println(String.format(" --%-20s %s", "home",
"Sets idp.home if not installed to default location."));
+ out.println(String.format(" %-22s %s", "-hc, --http-client",
+ "Use the named bean for HTTP operations"));
+ out.println(String.format(" %-22s %s", "-hs, --http-security",
+ "Use the named bean for HTTP security"));
out.println();
}
}
\ No newline at end of file
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
index 24b8f8548..e025ff24d 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
@@ -27,7 +27,6 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.apache.http.client.HttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,10 +67,6 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
@Parameter(names= {"-fu", "--force-update"})
@Nullable private String forceUpdateVersion;
- /** Name for the {@link HttpClient} . */
- @Parameter(names= {"-h", "--http-client"})
- @Nullable private String httpClientName;
-
/** The {@link #forceUpdateVersion} as a {@link PluginVersion}. */
@Nullable private PluginVersion updateVersion;
@@ -175,14 +170,6 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
return operation;
}
- /**
- * Get bean name for the httpClient (if specified).
- * @return the name or null
- */
- @Nullable public String getHttpClientName() {
- return httpClientName;
- }
-
/** {@inheritDoc} */
// Checkstyle: CyclomaticComplexity OFF
public void validate() throws IllegalArgumentException {
@@ -276,8 +263,6 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
out.println(String.format(" %-22s %s", "-u, --update <what>", "update (plugin id)"));
out.println(String.format(" %-22s %s", "-fu, --force-update <version>",
"force version to update to (requires -u)"));
- out.println(String.format(" %-22s %s", "-h, --http-client <bean ame>",
- "use the named bean for http operations"));
out.println();
}
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 f7315f68c..ddb1f46e6 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
@@ -28,13 +28,11 @@ import java.util.function.Predicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.apache.http.client.HttpClient;
import org.apache.tools.ant.BuildException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -47,6 +45,7 @@ import net.shibboleth.idp.plugin.PluginSupport.SupportLevel;
import net.shibboleth.idp.plugin.PluginVersion;
import net.shibboleth.idp.plugin.impl.PluginState;
import net.shibboleth.idp.plugin.impl.PluginState.VersionInfo;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -61,9 +60,6 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
/** A Plugin Installer to use. */
@Nullable private PluginInstaller installer;
-
- /** The injected HttpClient. */
- @Nullable private HttpClient httpClient;
/**
* Constrained Constructor.
@@ -83,18 +79,18 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
/** {@inheritDoc} */
@Override
- protected Class<PluginInstallerArguments> getArgumentClass() {
+ @Nonnull protected Class<PluginInstallerArguments> getArgumentClass() {
return PluginInstallerArguments.class;
}
/** {@inheritDoc} */
@Override
- protected String getVersion() {
+ @Nullable protected String getVersion() {
return Version.getVersion();
}
/** {@inheritDoc} */
- protected List<Resource> getAdditionalSpringResources() {
+ @Nonnull @NonnullElements protected List<Resource> getAdditionalSpringResources() {
return List.of(
new ClassPathResource("net/shibboleth/idp/conf/http-client.xml"));
}
@@ -102,6 +98,11 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
/** {@inheritDoc} */
//CheckStyle: CyclomaticComplexity OFF
protected int doRun(final PluginInstallerArguments args) {
+
+ if (args.getHttpClientName() == null) {
+ args.setHttpClientName("shibboleth.InternalHttpClient");
+ }
+
final int ret = super.doRun(args);
if (ret != RC_OK) {
return ret;
@@ -110,24 +111,6 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
Security.addProvider(new BouncyCastleProvider());
}
- String clientName = args.getHttpClientName();
- if (clientName == null) {
- clientName = "shibboleth.InternalHttpClient";
- }
- final Object client;
- try {
- client = getApplicationContext().getBean(clientName);
- } catch (final NoSuchBeanDefinitionException e) {
- log.error("Could not locate an Http Client '{}'", clientName);
- return RC_IO;
- }
- if (client instanceof HttpClient) {
- httpClient = (HttpClient) client;
- } else {
- log.error("Bean '{}' was a {}, not a {}", clientName, client.getClass(), HttpClient.class);
- return RC_IO;
- }
-
try {
constructPluginInstaller();
switch (args.getOperation()) {
@@ -176,8 +159,8 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
installer.setIdpHome(Path.of(getApplicationContext().getEnvironment().getProperty("idp.home")));
installer.setAcceptCert(new InstallerQuery("Accept this Certificate"));
installer.setAcceptDownload(new InstallerQuery("Download from"));
- if (httpClient!= null) {
- installer.setHttpClient(httpClient);
+ if (getHttpClient()!= null) {
+ installer.setHttpClient(getHttpClient());
}
installer.initialize();
}
@@ -267,8 +250,8 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
if (pluginId.equals(plugin.getPluginId())) {
log.debug("Interrogating {} ", plugin.getPluginId());
final PluginState state = new PluginState(plugin);
- if (httpClient != null) {
- state.setHttpClient(httpClient);
+ if (getHttpClient() != null) {
+ state.setHttpClient(getHttpClient());
}
try {
state.initialize();
@@ -306,8 +289,8 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
private void printDetails(final PluginDescription plugin) {
log.debug("Interrogating {} ", plugin.getPluginId());
final PluginState state = new PluginState(plugin);
- if (httpClient != null) {
- state.setHttpClient(httpClient);
+ if (getHttpClient() != null) {
+ state.setHttpClient(getHttpClient());
}
try {
state.initialize();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list