[java-identity-provider] branch master updated: Move ByReference filter out of IdP.

Scott Cantor cantor.2 at osu.edu
Tue Oct 22 09:03:33 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=5f54650c3ffbf09759e5d2a2ccf4633f306fd535

The following commit(s) were added to refs/heads/master by this push:
       new  5f54650   Move ByReference filter out of IdP.
5f54650 is described below

commit 5f54650c3ffbf09759e5d2a2ccf4633f306fd535
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Oct 22 09:03:27 2019 -0400

    Move ByReference filter out of IdP.
---
 .../metadata/impl/ByReferenceMetadataFilter.java   |  98 -----------------
 .../impl/ByReferenceMetadataFilterTest.java        | 120 ---------------------
 2 files changed, 218 deletions(-)

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
deleted file mode 100644
index 111757d..0000000
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilter.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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
deleted file mode 100644
index a17c075..0000000
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/metadata/impl/ByReferenceMetadataFilterTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.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 ByReferenceMetadataFilter refFilter;
-    
-    private NameIDFormatFilter nameIDFilter;
-    
-    private Collection<String> formats;
-    
-    @BeforeMethod
-    protected void setUp() throws URISyntaxException, ResolverException {
-
-        final URL mdURL = ByReferenceMetadataFilterTest.class
-                .getResource("/net/shibboleth/idp/saml/impl/metadata/InCommon-metadata.xml");
-        final File 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