[java-shib-metadata] branch main updated: Sigh, try another fix to re-enable test.

Scott Cantor cantor.2 at osu.edu
Thu Oct 24 14:37:03 UTC 2024


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

scantor pushed a commit to branch main
in repository java-shib-metadata.

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

The following commit(s) were added to refs/heads/main by this push:
     new cae3f1f4 Sigh, try another fix to re-enable test.
cae3f1f4 is described below

commit cae3f1f4f3ef1c01588fde8d9d0394297640a61f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Oct 24 10:37:00 2024 -0400

    Sigh, try another fix to re-enable test.
---
 .../filter/ByReferenceFilterBeanPostProcessor.java | 116 +++++++++++++++++++++
 .../filter/ByReferenceFilterParserTest.java        |   2 +-
 .../net/shibboleth/spring/parser.properties        |   2 +-
 .../metadata/filter/entityAttributesByRefBeans.xml |   3 +-
 4 files changed, 119 insertions(+), 4 deletions(-)

diff --git a/shib-metadata-spring/src/test/java/net/shibboleth/spring/metadata/filter/ByReferenceFilterBeanPostProcessor.java b/shib-metadata-spring/src/test/java/net/shibboleth/spring/metadata/filter/ByReferenceFilterBeanPostProcessor.java
new file mode 100644
index 00000000..e96868ce
--- /dev/null
+++ b/shib-metadata-spring/src/test/java/net/shibboleth/spring/metadata/filter/ByReferenceFilterBeanPostProcessor.java
@@ -0,0 +1,116 @@
+/*
+ * 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.spring.metadata.filter;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.saml.metadata.resolver.ChainingMetadataResolver;
+import org.opensaml.saml.metadata.resolver.MetadataResolver;
+import org.opensaml.saml.metadata.resolver.filter.MetadataFilter;
+import org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.Ordered;
+
+import net.shibboleth.idp.saml.metadata.impl.ByReferenceMetadataFilterBridge;
+import net.shibboleth.shared.collection.CollectionSupport;
+
+/**
+ * A {@link BeanPostProcessor} for {@link MetadataResolver} beans that ensures a {@link ByReferenceMetadataFilterBridge}
+ * is attached.
+ * 
+ * @since 4.0.0
+ */
+public class ByReferenceFilterBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered {
+
+    /** Whether to enable the processor. */
+    private boolean enabled;
+    
+    /** Spring context. */
+    @Nullable private ApplicationContext applicationContext;
+
+    /** Constructor. */
+    public ByReferenceFilterBeanPostProcessor() {
+        enabled = true;
+    }
+    
+    /**
+     * Set whether to enable the processor.
+     * 
+     * @param flag flag to set
+     */
+    public void setEnabled(final boolean flag) {
+        enabled = flag;
+    }
+    
+    /** {@inheritDoc} */
+    public int getOrder() {
+        return HIGHEST_PRECEDENCE;
+    }
+
+    /** {@inheritDoc} */
+    public void setApplicationContext(@Nullable final ApplicationContext context) throws BeansException {
+        applicationContext = context;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull public Object postProcessBeforeInitialization(@Nonnull final Object bean, @Nonnull final String beanName) {
+        
+        // Do not attach to beans which just include other ones.
+        if (!enabled || !(bean instanceof MetadataResolver) || bean instanceof ChainingMetadataResolver) {
+            return bean;
+        }
+
+        final MetadataResolver resolver = (MetadataResolver) bean;
+
+        boolean filterAttached = false;
+
+        final MetadataFilter filter = resolver.getMetadataFilter();
+        if (filter instanceof ByReferenceMetadataFilterBridge) {
+            filterAttached = true;
+        } else if (filter instanceof MetadataFilterChain) {
+            filterAttached = ((MetadataFilterChain) filter).getFilters().stream().anyMatch(
+                    f -> f instanceof ByReferenceMetadataFilterBridge);
+        }
+
+        if (!filterAttached) {
+            final ByReferenceMetadataFilterBridge filterToAttach = new ByReferenceMetadataFilterBridge();
+            filterToAttach.setApplicationContext(applicationContext);
+
+            if (filter == null) {
+                resolver.setMetadataFilter(filterToAttach);
+            } else if (filter instanceof MetadataFilterChain) {
+                ((MetadataFilterChain) filter).getFilters().add(filterToAttach);
+            } else {
+                final MetadataFilterChain chain = new MetadataFilterChain();
+                chain.setFilters(CollectionSupport.listOf(filter, filterToAttach));
+                resolver.setMetadataFilter(chain);
+            }
+        }
+
+        return resolver;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull public Object postProcessAfterInitialization(@Nonnull final Object bean, @Nonnull final String beanName) {
+        return bean;
+    }
+
+}
\ No newline at end of file
diff --git a/shib-metadata-spring/src/test/java/net/shibboleth/spring/metadata/filter/ByReferenceFilterParserTest.java b/shib-metadata-spring/src/test/java/net/shibboleth/spring/metadata/filter/ByReferenceFilterParserTest.java
index edc578b1..78ae2b37 100644
--- a/shib-metadata-spring/src/test/java/net/shibboleth/spring/metadata/filter/ByReferenceFilterParserTest.java
+++ b/shib-metadata-spring/src/test/java/net/shibboleth/spring/metadata/filter/ByReferenceFilterParserTest.java
@@ -33,7 +33,7 @@ import org.testng.annotations.Test;
 @SuppressWarnings("javadoc")
 public class ByReferenceFilterParserTest extends AbstractMetadataParserTest {
     
-    @Test(enabled=false)
+    @Test
     public void test() throws ResolverException, IOException {
         doTest("filter/entityAttributesMetadataOnly.xml", "filter/entityAttributesByRef.xml", "filter/entityAttributesByRefBeans.xml");
     }
diff --git a/shib-metadata-spring/src/test/resources/META-INF/net/shibboleth/spring/parser.properties b/shib-metadata-spring/src/test/resources/META-INF/net/shibboleth/spring/parser.properties
index 1fc31da1..97ff0b65 100644
--- a/shib-metadata-spring/src/test/resources/META-INF/net/shibboleth/spring/parser.properties
+++ b/shib-metadata-spring/src/test/resources/META-INF/net/shibboleth/spring/parser.properties
@@ -1,6 +1,6 @@
 # These are custom parser properties to inject higher layer class names, beans, etc. into lower layer parsers.
 
-net.shibboleth.spring.metadata.AbstractMetadataProviderParser.ByReferenceMetadataFilterBridge.bean = shibboleth.ByReferenceMetadataFilterBridge
+#net.shibboleth.spring.metadata.AbstractMetadataProviderParser.ByReferenceMetadataFilterBridge.bean = shibboleth.ByReferenceMetadataFilterBridge
 #net.shibboleth.spring.metadata.AbstractMetadataProviderParser.AutoWiredNodeProcessingMetadataFilter.bean = shibboleth.AutoWiredNodeProcessingMetadataFilter
 
 net.shibboleth.spring.metadata.AbstractReloadingMetadataProviderParser.ParserPool.bean = shibboleth.ParserPool
diff --git a/shib-metadata-spring/src/test/resources/net/shibboleth/spring/metadata/filter/entityAttributesByRefBeans.xml b/shib-metadata-spring/src/test/resources/net/shibboleth/spring/metadata/filter/entityAttributesByRefBeans.xml
index 6b087a8a..9b4ea681 100644
--- a/shib-metadata-spring/src/test/resources/net/shibboleth/spring/metadata/filter/entityAttributesByRefBeans.xml
+++ b/shib-metadata-spring/src/test/resources/net/shibboleth/spring/metadata/filter/entityAttributesByRefBeans.xml
@@ -11,7 +11,6 @@
     
     <bean id="predicate.AlwaysFalse" class="com.google.common.base.Predicates" factory-method="alwaysFalse" />
     
-    <bean id="shibboleth.ByReferenceMetadataFilterBridge"
-        class="net.shibboleth.idp.saml.metadata.impl.ByReferenceMetadataFilterBridge" />
+    <bean class="net.shibboleth.spring.metadata.filter.ByReferenceFilterBeanPostProcessor" />
                 
 </beans>
\ 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