[java-shib-shared] branch main updated: JSSH-34 - Process nested lists and sets
Ian Young
ian at iay.org.uk
Thu Jul 20 17:14:52 UTC 2023
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=a1a38ba6f195fb34a8639d35e7fad157657f8a01
The following commit(s) were added to refs/heads/main by this push:
new a1a38ba6 JSSH-34 - Process nested lists and sets
a1a38ba6 is described below
commit a1a38ba6f195fb34a8639d35e7fad157657f8a01
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Jul 20 18:12:36 2023 +0100
JSSH-34 - Process nested lists and sets
https://shibboleth.atlassian.net/browse/JSSH-34
---
.../config/RelocatedBeanFactoryPostProcessor.java | 19 +++++++++-
.../RelocatedBeanFactoryPostProcessorTest.java | 41 +++++++++++++++++++++-
.../shibboleth/shared/spring/config/relocated.xml | 21 +++++++++++
3 files changed, 79 insertions(+), 2 deletions(-)
diff --git a/shib-spring/src/main/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessor.java b/shib-spring/src/main/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessor.java
index 7839bacc..8c40f193 100644
--- a/shib-spring/src/main/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessor.java
+++ b/shib-spring/src/main/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessor.java
@@ -28,6 +28,8 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.ManagedList;
+import org.springframework.beans.factory.support.ManagedSet;
import net.shibboleth.shared.annotation.ParameterName;
import net.shibboleth.shared.collection.CollectionSupport;
@@ -107,9 +109,24 @@ public class RelocatedBeanFactoryPostProcessor implements BeanFactoryPostProcess
// Look recursively inside any property values for nested and potentially un-named bean definitions
for (final PropertyValue property : def.getPropertyValues()) {
- if (property.getValue() instanceof BeanDefinitionHolder defHolder) {
+ final var propValue = property.getValue();
+ if (propValue instanceof BeanDefinitionHolder defHolder) {
// Handle potentially unnamed bean definitions
processBeanDefinition(defHolder.getBeanDefinition(), defHolder.getBeanName());
+ } else if (propValue instanceof ManagedList<?> pv) {
+ for (final var value : pv) {
+ if (value instanceof BeanDefinitionHolder defHolder) {
+ // Handle potentially unnamed bean definitions within lists
+ processBeanDefinition(defHolder.getBeanDefinition(), defHolder.getBeanName());
+ }
+ }
+ } else if (propValue instanceof ManagedSet<?> pv) {
+ for (final var value : pv) {
+ if (value instanceof BeanDefinitionHolder defHolder) {
+ // Handle potentially unnamed bean definitions within sets
+ processBeanDefinition(defHolder.getBeanDefinition(), defHolder.getBeanName());
+ }
+ }
}
}
}
diff --git a/shib-spring/src/test/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessorTest.java b/shib-spring/src/test/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessorTest.java
index 49570269..91e25dcb 100644
--- a/shib-spring/src/test/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessorTest.java
+++ b/shib-spring/src/test/java/net/shibboleth/shared/spring/config/RelocatedBeanFactoryPostProcessorTest.java
@@ -17,6 +17,9 @@
package net.shibboleth.shared.spring.config;
+import java.util.List;
+import java.util.Set;
+
import javax.annotation.Nonnull;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
@@ -58,6 +61,32 @@ public class RelocatedBeanFactoryPostProcessorTest {
}
}
+ /**
+ * Wraps a list of strings.
+ */
+ public static class ListWrapper {
+ private List<String> list;
+ public void setList(@Nonnull final List<String> l) {
+ list = l;
+ }
+ public List<String> getList() {
+ return list;
+ }
+ }
+
+ /**
+ * Wraps a Set of strings.
+ */
+ public static class SetWrapper {
+ private Set<String> set;
+ public void setSet(@Nonnull final Set<String> s) {
+ set = s;
+ }
+ public Set<String> getSet() {
+ return set;
+ }
+ }
+
/**
* Test replacement of bean's class.
*/
@@ -78,9 +107,19 @@ public class RelocatedBeanFactoryPostProcessorTest {
final var layeredBeans = context.getBean("layeredBeans", OuterBeanWrapper.class);
Assert.assertEquals(layeredBeans.getBean().getInnerString(), "doubly-nested");
+
+ final var layeredList = context.getBean("layeredList", ListWrapper.class);
+ Assert.assertEquals(layeredList.getList().size(), 2);
+ Assert.assertEquals((String)layeredList.getList().get(0), "listentry");
+ Assert.assertEquals((String)layeredList.getList().get(1), "also a string");
+
+ final var layeredSet = context.getBean("layeredSet", SetWrapper.class);
+ Assert.assertEquals(layeredSet.getSet().size(), 2);
+ Assert.assertTrue(layeredSet.getSet().contains("setentry"));
+ Assert.assertTrue(layeredSet.getSet().contains("also a string"));
}
- private ApplicationContext getContext(final String config) {
+ private ApplicationContext getContext(final @Nonnull String config) {
final GenericApplicationContext context = new GenericApplicationContext();
final XmlBeanDefinitionReader beanDefinitionReader = new SchemaTypeAwareXMLBeanDefinitionReader(context);
diff --git a/shib-spring/src/test/resources/net/shibboleth/shared/spring/config/relocated.xml b/shib-spring/src/test/resources/net/shibboleth/shared/spring/config/relocated.xml
index 9ee0738c..154869e5 100644
--- a/shib-spring/src/test/resources/net/shibboleth/shared/spring/config/relocated.xml
+++ b/shib-spring/src/test/resources/net/shibboleth/shared/spring/config/relocated.xml
@@ -52,4 +52,25 @@
</bean>
</property>
</bean>
+
+ <!-- Dig into a property which is a list of relocated beans. -->
+ <bean id="layeredList" class="net.shibboleth.shared.spring.config.RelocatedBeanFactoryPostProcessorTest.ListWrapper">
+ <property name="list">
+ <list>
+ <bean parent="missing" c:_0="listentry"/>
+ <bean class="org.example.missing.Foo" c:_0="also a string"/>
+ </list>
+ </property>
+ </bean>
+
+ <!-- Dig into a property which is a set of relocated beans. -->
+ <bean id="layeredSet" class="net.shibboleth.shared.spring.config.RelocatedBeanFactoryPostProcessorTest.SetWrapper">
+ <property name="set">
+ <set>
+ <bean parent="missing" c:_0="setentry"/>
+ <bean class="org.example.missing.Foo" c:_0="also a string"/>
+ </set>
+ </property>
+ </bean>
+
</beans>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list