[java-identity-provider] 02/02: IDP-1595 Teach Plugin Installer to use the IdP's property Initializer
Rod Widdowson
rdw at steadingsoftware.com
Fri Aug 7 10:25:07 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=280907e3f79038b6ef97e7ec4ec227c233a62fbb
commit 280907e3f79038b6ef97e7ec4ec227c233a62fbb
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Aug 6 17:20:44 2020 +0100
IDP-1595 Teach Plugin Installer to use the IdP's property Initializer
https://issues.shibboleth.net/jira/browse/IDP-1595
---
.../shibboleth/idp/plugin/impl/PluginState.java | 2 +-
.../idp/installer/plugin/PluginInstallerCLI.java | 33 +++++++++++++++++-----
.../idp/installer/plugin/PluginCLITest.java | 9 +-----
.../idphome-test/conf/admin/plugin-installer.xml | 15 ++++++++++
.../resources/idphome-test/conf/idp.properties | 2 ++
.../idphome-test/conf/services.properties | 1 +
6 files changed, 46 insertions(+), 16 deletions(-)
diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/PluginState.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/PluginState.java
index 42dfdb5af..6ff60cf33 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/PluginState.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/plugin/impl/PluginState.java
@@ -223,7 +223,7 @@ public class PluginState extends AbstractInitializableComponent {
try {
final Properties props = new Properties();
- log.info("Loading properties from {}", propertyResource.getDescription());
+ log.debug("Loading properties from {}", propertyResource.getDescription());
props.load(propertyResource.getInputStream());
final String name = plugin.getPluginId() + PluginSupport.AVAILABLE_VERSIONS_PROPERTY_SUFFIX;
final String availableVersions = StringSupport.trim(props.getProperty(name));
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 8cc6a43fc..e45caf29a 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
@@ -20,7 +20,6 @@ package net.shibboleth.idp.installer.plugin;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.Security;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -35,6 +34,9 @@ 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;
@@ -44,6 +46,7 @@ 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;
@@ -68,6 +71,8 @@ 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.
@@ -117,9 +122,8 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
/** {@inheritDoc} */
protected List<Resource> getAdditionalSpringResources() {
- return Collections.emptyList();
- // return List.of(
- // new ClassPathResource("net/shibboleth/idp/conf/http-client.xml"));
+ return List.of(
+ new ClassPathResource("net/shibboleth/idp/conf/http-client.xml"));
}
/** {@inheritDoc} */
@@ -257,12 +261,10 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
*/
public static int runMain(@Nonnull final String[] args) {
final PluginInstallerCLI cli = new PluginInstallerCLI();
- cli.setIdpHome(StringSupport.trimOrNull(System.getProperty("net.shibboleth.idp.cli.idp.home")));
if (cli.getIdpHome() == null) {
return RC_INIT;
- } else {
- return cli.run(args);
}
+ return cli.run(args);
}
/**
@@ -272,4 +274,21 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
public static void main(@Nonnull final String[] args) {
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();
+ }
+ }
}
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/PluginCLITest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/PluginCLITest.java
index 78355e6a8..6c2577093 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/PluginCLITest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/PluginCLITest.java
@@ -50,18 +50,11 @@ public class PluginCLITest extends BasePluginTest {
@BeforeSuite public void setUp() throws IOException
{
System.setProperty("net.shibboleth.idp.cli.idp.home",getIdpHome().toString());
- final Resource pluginInstaller = new ClassPathResource("conf/admin/plugin-installer.xml");
plugin = getIdpHome().resolve("conf").resolve("admin").resolve("plugin-installer.xml").toFile();
- plugin.createNewFile();
-
- try (final InputStream is = pluginInstaller.getInputStream();
- final BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(plugin))) {
- is.transferTo(os);
- }
}
@Test(enabled = true) public void testList() throws IOException {
- assertEquals(PluginInstallerCLI.runMain(new String[] { plugin.getAbsolutePath(), "-fl"}),
+ assertEquals(PluginInstallerCLI.runMain(new String[] { plugin.getAbsolutePath(), "-fl", } ),
AbstractCommandLine.RC_OK);
}
diff --git a/idp-installer/src/test/resources/idphome-test/conf/admin/plugin-installer.xml b/idp-installer/src/test/resources/idphome-test/conf/admin/plugin-installer.xml
new file mode 100644
index 000000000..ab93e1f31
--- /dev/null
+++ b/idp-installer/src/test/resources/idphome-test/conf/admin/plugin-installer.xml
@@ -0,0 +1,15 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
+ 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"
+
+ default-init-method="initialize"
+ default-destroy-method="destroy">
+
+ <!--
+ <bean id="MyHttpClient" parent="shibboleth.HttpClientFactory"/>
+ -->
+</beans>
\ No newline at end of file
diff --git a/idp-installer/src/test/resources/idphome-test/conf/idp.properties b/idp-installer/src/test/resources/idphome-test/conf/idp.properties
new file mode 100644
index 000000000..47b62e66f
--- /dev/null
+++ b/idp-installer/src/test/resources/idphome-test/conf/idp.properties
@@ -0,0 +1,2 @@
+# Load any additional property resources from a comma-delimited list
+idp.additionalProperties = /conf/services.properties
diff --git a/idp-installer/src/test/resources/idphome-test/conf/services.properties b/idp-installer/src/test/resources/idphome-test/conf/services.properties
new file mode 100644
index 000000000..5a41fdef7
--- /dev/null
+++ b/idp-installer/src/test/resources/idphome-test/conf/services.properties
@@ -0,0 +1 @@
+idp.httpclient.filecaching.cacheDirectory = %{idp.home}/tmp/httpClientCache
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list