[java-shib-profile] branch main updated: IDP-2156: Wire in support for feeding properties from the IdP ...

Brent Putman putmanb at georgetown.edu
Fri Aug 25 03:15:44 UTC 2023


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

putmanb pushed a commit to branch main
in repository java-shib-profile.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-profile.git;a=commit;h=ab5d1796a2562ae8d5f61720b1ec8955b838911c

The following commit(s) were added to refs/heads/main by this push:
     new ab5d179  IDP-2156: Wire in support for feeding properties from the IdP ...
ab5d179 is described below

commit ab5d1796a2562ae8d5f61720b1ec8955b838911c
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Thu Aug 24 00:09:33 2023 -0400

    IDP-2156: Wire in support for feeding properties from the IdP ...
    
    Wire in support for feeding properties from the IdP into OpenSAML's
    configuration
---
 shib-profile-impl/pom.xml                          |  6 +++
 .../profile/spring/impl/OpenSAMLConfigBean.java    | 19 ++++++++-
 .../spring/impl/OpenSAMLConfigBeanTest.java        | 48 ++++++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/shib-profile-impl/pom.xml b/shib-profile-impl/pom.xml
index a093f93..9fe7734 100644
--- a/shib-profile-impl/pom.xml
+++ b/shib-profile-impl/pom.xml
@@ -83,6 +83,12 @@
         <!-- Runtime Dependencies -->
 
         <!-- Test Dependencies -->
+        <dependency>
+            <groupId>${spring.groupId}</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>shib-profile-testing</artifactId>
diff --git a/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBean.java b/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBean.java
index 92a587d..8df527c 100644
--- a/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBean.java
+++ b/shib-profile-impl/src/main/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBean.java
@@ -24,8 +24,11 @@ import org.opensaml.core.config.InitializationException;
 import org.opensaml.core.config.InitializationService;
 import org.opensaml.core.xml.config.XMLObjectProviderRegistry;
 import org.opensaml.messaging.context.BaseContext;
+import org.opensaml.spring.config.SpringConfigurationPropertiesSource;
 import org.opensaml.xmlsec.config.DecryptionParserPool;
 import org.slf4j.Logger;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.core.env.Environment;
 
 import com.codahale.metrics.MetricRegistry;
 
@@ -39,11 +42,14 @@ import net.shibboleth.shared.xml.ParserPool;
  * A simple bean that may be used with Spring to initialize the OpenSAML library
  * with injected instances of some critical objects.
  */
-public class OpenSAMLConfigBean extends AbstractInitializableComponent {
+public class OpenSAMLConfigBean extends AbstractInitializableComponent implements EnvironmentAware {
 
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(OpenSAMLConfigBean.class);
     
+    /** The Spring environment instance. */
+    @Nullable private Environment springEnvironment;
+    
     /** Optional {@link ParserPool} to configure. */
     @Nullable private ParserPool parserPool;
     
@@ -56,6 +62,13 @@ public class OpenSAMLConfigBean extends AbstractInitializableComponent {
     /** Optional map of renamed classes for string-based context navigation. */
     @Nullable private Map<String,Class<? extends BaseContext>> contextLookAsideMap;
     
+    /** {@inheritDoc} */
+    @Override
+    public void setEnvironment(@Nullable final Environment environment) {
+        checkSetterPreconditions();
+        springEnvironment = environment;
+    }
+    
     /**
      * Get the global {@link ParserPool} to configure.
      * 
@@ -134,6 +147,10 @@ public class OpenSAMLConfigBean extends AbstractInitializableComponent {
     
     /** {@inheritDoc} */
     protected void doInitialize() throws ComponentInitializationException {
+        if (springEnvironment != null) {
+            ConfigurationService.setDefaultConfigurationPropertiesSource(
+                    new SpringConfigurationPropertiesSource(springEnvironment));
+        }
 
         // Initialize OpenSAML.
         try {
diff --git a/shib-profile-impl/src/test/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBeanTest.java b/shib-profile-impl/src/test/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBeanTest.java
new file mode 100644
index 0000000..10846da
--- /dev/null
+++ b/shib-profile-impl/src/test/java/net/shibboleth/profile/spring/impl/OpenSAMLConfigBeanTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed 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.profile.spring.impl;
+
+import org.opensaml.core.config.ConfigurationProperties;
+import org.opensaml.core.config.ConfigurationService;
+import org.opensaml.spring.config.SpringConfigurationPropertiesSource;
+import org.springframework.mock.env.MockEnvironment;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.shared.component.ComponentInitializationException;
+
+public class OpenSAMLConfigBeanTest {
+    
+    @Test
+    public void testConfigurationProperties() throws ComponentInitializationException {
+        try {
+            MockEnvironment env = new MockEnvironment();
+            env.setProperty("test.property", "abc123");
+
+            final OpenSAMLConfigBean configBean = new OpenSAMLConfigBean();
+            configBean.setEnvironment(env);
+            configBean.initialize();
+            
+            Assert.assertTrue(SpringConfigurationPropertiesSource.class.isInstance(
+                    ConfigurationService.getDefaultConfigurationPropertiesSource()));
+
+            ConfigurationProperties props = ConfigurationService.getConfigurationProperties();
+            Assert.assertEquals(props.getProperty("test.property"), "abc123");
+        } finally {
+            ConfigurationService.setDefaultConfigurationPropertiesSource(null);
+        }
+    }
+
+}

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


More information about the commits mailing list