[java-identity-provider] branch master updated: IDP-1511 - Support referencing of non-inline MetadataFilters
Scott Cantor
cantor.2 at osu.edu
Mon Oct 21 11:20:06 EDT 2019
This is an automated email from the git hooks/post-receive script.
scantor 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=6d80530a5f70c61abb6653f6187b13f04f50141d
The following commit(s) were added to refs/heads/master by this push:
new 6d80530 IDP-1511 - Support referencing of non-inline MetadataFilters
6d80530 is described below
commit 6d80530a5f70c61abb6653f6187b13f04f50141d
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Oct 21 10:26:19 2019 -0400
IDP-1511 - Support referencing of non-inline MetadataFilters
https://issues.shibboleth.net/jira/browse/IDP-1511
Add initial filter implementation.
---
idp-saml-impl/pom.xml | 11 +-
.../metadata/impl/ByReferenceMetadataFilter.java | 98 ++++++++++++++++
.../impl/ByReferenceMetadataFilterTest.java | 123 +++++++++++++++++++++
3 files changed, 229 insertions(+), 3 deletions(-)
diff --git a/idp-saml-impl/pom.xml b/idp-saml-impl/pom.xml
index 2dc0143..8c2d7e8 100644
--- a/idp-saml-impl/pom.xml
+++ b/idp-saml-impl/pom.xml
@@ -80,6 +80,10 @@
</dependency>
<dependency>
<groupId>${opensaml.groupId}</groupId>
+ <artifactId>opensaml-saml-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${opensaml.groupId}</groupId>
<artifactId>opensaml-soap-api</artifactId>
</dependency>
<dependency>
@@ -182,18 +186,19 @@
</dependency>
<dependency>
<groupId>${opensaml.groupId}</groupId>
- <artifactId>opensaml-soap-impl</artifactId>
+ <artifactId>opensaml-saml-impl</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${opensaml.groupId}</groupId>
- <artifactId>opensaml-xmlsec-impl</artifactId>
+ <artifactId>opensaml-soap-impl</artifactId>
+ <type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${opensaml.groupId}</groupId>
- <artifactId>opensaml-saml-impl</artifactId>
+ <artifactId>opensaml-xmlsec-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilter.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilter.java
new file mode 100644
index 0000000..111757d
--- /dev/null
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilter.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.saml.metadata.impl;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.core.xml.XMLObject;
+import org.opensaml.saml.metadata.resolver.filter.FilterException;
+import org.opensaml.saml.metadata.resolver.filter.MetadataFilter;
+import org.opensaml.saml.metadata.resolver.filter.MetadataFilterContext;
+import org.opensaml.saml.metadata.resolver.filter.data.impl.MetadataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/**
+ * A Spring-aware {@link MetadataFilter} that associates other filters with specific
+ * {@link MetadataResolver} instances by ID.
+ *
+ * <p>The {@link MetadataFilterContext} is used to identify which resolver is actually
+ * running, to properly identify which filters to apply.</p>
+ *
+ * @since 4.0.0
+ */
+public class ByReferenceMetadataFilter implements MetadataFilter {
+
+ /** Class logger. */
+ @Nonnull private Logger log = LoggerFactory.getLogger(ByReferenceMetadataFilter.class);
+
+ /** Map of resolver names to filters. */
+ @Nonnull @NonnullElements private Map<String,MetadataFilter> filterMap;
+
+ /** Constructor. */
+ public ByReferenceMetadataFilter() {
+ filterMap = Collections.emptyMap();
+ }
+
+ /**
+ * Mapping of resolver names to filters to run.
+ *
+ * @param map filter mappings
+ */
+ public void setFilterMappings(@Nonnull @NonnullElements final Map<String,MetadataFilter> map) {
+ Constraint.isNotNull(map, "Filter mappings cannot be null");
+
+ filterMap = new HashMap<>(map.size());
+ for (final Map.Entry<String,MetadataFilter> entry : map.entrySet()) {
+ final String trimmed = StringSupport.trimOrNull(entry.getKey());
+ if (trimmed != null && entry.getValue() != null) {
+ filterMap.put(trimmed, entry.getValue());
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ public XMLObject filter(@Nullable final XMLObject metadata, @Nonnull final MetadataFilterContext context)
+ throws FilterException {
+
+ final MetadataSource source = context.get(MetadataSource.class);
+ if (source == null || source.getSourceId() == null) {
+ log.debug("No metadata source ID found in MetadataFilterContext");
+ return metadata;
+ }
+
+ final MetadataFilter filter = filterMap.get(source.getSourceId());
+ if (filter == null) {
+ log.debug("No filters defined for resolver '{}', by-reference filter inactive", source.getSourceId());
+ return metadata;
+ }
+
+ log.debug("Applying by-reference filter to metadata resolver '{}'", source.getSourceId());
+ return filter.filter(metadata, context);
+ }
+
+}
\ No newline at end of file
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilterTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilterTest.java
new file mode 100644
index 0000000..13ea395
--- /dev/null
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilterTest.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.saml.metadata.impl;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.function.Predicate;
+
+import org.opensaml.core.criterion.EntityIdCriterion;
+import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.metadata.resolver.MetadataResolver;
+import org.opensaml.saml.metadata.resolver.filter.impl.NameIDFormatFilter;
+import org.opensaml.saml.metadata.resolver.impl.FilesystemMetadataResolver;
+import org.opensaml.saml.metadata.resolver.impl.FilesystemMetadataResolverTest;
+import org.opensaml.saml.saml2.core.NameIDType;
+import org.opensaml.saml.saml2.metadata.EntityDescriptor;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+import net.shibboleth.utilities.java.support.resolver.ResolverException;
+
+/** Unit test for {@link ByReferenceMetadataFilter}. */
+public class ByReferenceMetadataFilterTest extends XMLObjectBaseTestCase implements Predicate<EntityDescriptor> {
+
+ protected MetadataResolver resolver;
+
+ private FilesystemMetadataResolver metadataProvider;
+
+ private File mdFile;
+
+ private ByReferenceMetadataFilter refFilter;
+
+ private NameIDFormatFilter nameIDFilter;
+
+ private Collection<String> formats;
+
+ @BeforeMethod
+ protected void setUp() throws URISyntaxException, ResolverException {
+
+ URL mdURL = FilesystemMetadataResolverTest.class
+ .getResource("/org/opensaml/saml/saml2/metadata/InCommon-metadata.xml");
+ mdFile = new File(mdURL.toURI());
+
+ metadataProvider = new FilesystemMetadataResolver(mdFile);
+ metadataProvider.setParserPool(parserPool);
+ metadataProvider.setId("ICMD");
+
+ refFilter = new ByReferenceMetadataFilter();
+ metadataProvider.setMetadataFilter(refFilter);
+
+ nameIDFilter = new NameIDFormatFilter();
+ formats = Arrays.asList(NameIDType.EMAIL, NameIDType.KERBEROS);
+ }
+
+ @Test
+ public void notApplicable() throws ComponentInitializationException, ResolverException {
+
+ nameIDFilter.setRules(Collections.<Predicate<EntityDescriptor>,Collection<String>>singletonMap(this, formats));
+ nameIDFilter.initialize();
+
+ refFilter.setFilterMappings(Collections.singletonMap("Foo", nameIDFilter));
+
+ metadataProvider.initialize();
+
+ validate(false);
+ }
+
+ @Test
+ public void applicable() throws ComponentInitializationException, ResolverException {
+
+ nameIDFilter.setRules(Collections.<Predicate<EntityDescriptor>,Collection<String>>singletonMap(this, formats));
+ nameIDFilter.initialize();
+
+ refFilter.setFilterMappings(Collections.singletonMap("ICMD", nameIDFilter));
+
+ metadataProvider.initialize();
+
+ validate(true);
+ }
+
+ /**
+ * Validate whether the filter was or wasn't applied.
+ */
+ private void validate(final boolean applied) throws ResolverException {
+ EntityIdCriterion key = new EntityIdCriterion("https://carmenwiki.osu.edu/shibboleth");
+ EntityDescriptor entity = metadataProvider.resolveSingle(new CriteriaSet(key));
+ Assert.assertNotNull(entity);
+ Assert.assertEquals(entity.getSPSSODescriptor(SAMLConstants.SAML20P_NS).getNameIDFormats().size(), applied ? 3 : 1);
+
+ key = new EntityIdCriterion("https://cms.psu.edu/Shibboleth");
+ entity = metadataProvider.resolveSingle(new CriteriaSet(key));
+ Assert.assertNotNull(entity);
+ Assert.assertEquals(entity.getSPSSODescriptor(SAMLConstants.SAML11P_NS).getNameIDFormats().size(), 1);
+ }
+
+ /** {@inheritDoc} */
+ public boolean test(EntityDescriptor input) {
+ return input.getEntityID().equals("https://carmenwiki.osu.edu/shibboleth");
+ }
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list