[java-metadata-aggregator] 01/03: MDA-182 - refactor Stage implementation class hierarchy

Ian Young ian at iay.org.uk
Thu Jun 29 12:52:52 EDT 2017


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

iay pushed a commit to branch master
in repository java-metadata-aggregator.

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

commit 6e120cc38e2ff89034bd6224097e3c5dbcf29659
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Jun 29 14:20:21 2017 +0100

    MDA-182 - refactor Stage implementation class hierarchy
    
    Phase 1: split BaseIteratingStage into BaseIteratingStage and BaseFilteringStage.
---
 .../metadata/dom/XMLSchemaValidationStage.java     | 28 ++++++++---------
 .../metadata/dom/XMLSignatureSigningStage.java     | 35 +++++++++++-----------
 .../metadata/dom/XMLSignatureValidationStage.java  | 30 +++++++++----------
 .../dom/saml/ContactPersonFilterStage.java         | 20 ++++++-------
 .../EntityDescriptorItemIdPopulationStage.java     | 12 ++++----
 .../metadata/dom/saml/EntityFilterStage.java       |  4 +--
 .../metadata/dom/saml/EntityRoleFilterStage.java   |  4 +--
 .../metadata/dom/saml/GenerateIdStage.java         | 16 +++++-----
 .../dom/saml/PullUpCacheDurationStage.java         | 13 ++++----
 .../metadata/dom/saml/PullUpValidUntilStage.java   | 13 ++++----
 .../metadata/dom/saml/RemoveOrganizationStage.java | 15 +++++-----
 .../metadata/dom/saml/SetCacheDurationStage.java   | 12 ++++----
 .../metadata/dom/saml/SetValidUntilStage.java      | 12 ++++----
 .../metadata/dom/saml/ValidateValidUntilStage.java | 12 ++++----
 .../EntityRegistrationAuthorityFilterStage.java    |  4 +--
 ...IteratingStage.java => BaseFilteringStage.java} | 24 ++++++++-------
 .../metadata/pipeline/BaseIteratingStage.java      | 26 ++++++----------
 .../metadata/pipeline/ItemIdTransformStage.java    |  2 +-
 .../metadata/pipeline/ItemMetadataAddingStage.java |  2 +-
 19 files changed, 131 insertions(+), 153 deletions(-)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSchemaValidationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSchemaValidationStage.java
index 57547ef..dd15244 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSchemaValidationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSchemaValidationStage.java
@@ -29,6 +29,16 @@ import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.Validator;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.Resource;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
 import net.shibboleth.metadata.ErrorStatus;
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.WarningStatus;
@@ -42,16 +52,6 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.xml.SchemaBuilder;
 import net.shibboleth.utilities.java.support.xml.SerializeSupport;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
 /**
  * A pipeline stage that XML schema validates the elements within the {@link DOMElementItem} collection.
  * 
@@ -122,8 +122,8 @@ public class XMLSchemaValidationStage extends BaseIteratingStage<Element> {
         elementRequiredToBeSchemaValid = isRequired;
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         log.debug("{} pipeline stage schema validating DOM Element collection elements", getId());
 
         final Validator validator = validationSchema.newValidator();
@@ -139,8 +139,6 @@ public class XMLSchemaValidationStage extends BaseIteratingStage<Element> {
                 item.getItemMetadata().put(new WarningStatus(getId(), e.getMessage()));
             }
         }
-
-        return true;
     }
 
     /** {@inheritDoc} */
@@ -177,4 +175,4 @@ public class XMLSchemaValidationStage extends BaseIteratingStage<Element> {
             throw new ComponentInitializationException("Unable to generate schema", e);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java
index 6879e3a..ed55614 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java
@@ -50,6 +50,18 @@ import javax.xml.crypto.dsig.spec.ExcC14NParameterSpec;
 import javax.xml.crypto.dsig.spec.TransformParameterSpec;
 import javax.xml.namespace.QName;
 
+import org.apache.xml.security.Init;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.io.CharStreams;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
@@ -63,18 +75,6 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 import net.shibboleth.utilities.java.support.xml.QNameSupport;
 
-import org.apache.xml.security.Init;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.io.CharStreams;
-
 /**
  * A pipeline stage that creates, and adds, an enveloped signature for each element in the given {@link DOMElementItem}
  * collection.
@@ -639,8 +639,8 @@ public class XMLSignatureSigningStage extends BaseIteratingStage<Element> {
         return digestAlgo;
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element element = item.unwrap();
         final XMLSignature signature = xmlSigFactory.newXMLSignature(buildSignedInfo(element), buildKeyInfo());
         try {
@@ -657,15 +657,14 @@ public class XMLSignatureSigningStage extends BaseIteratingStage<Element> {
             // Log the pre-digest data for debugging
             if (isDebugPreDigest() && log.isDebugEnabled()) {
                 final Reference ref = (Reference) signature.getSignedInfo().getReferences().get(0);
-                final String preDigest = CharStreams.toString(new InputStreamReader(ref.getDigestInputStream(), "UTF-8"));
+                final String preDigest =
+                        CharStreams.toString(new InputStreamReader(ref.getDigestInputStream(), "UTF-8"));
                 log.debug("pre digest: {}", preDigest);
             }
         } catch (final Exception e) {
             log.error("Unable to create signature for element", e);
             throw new StageProcessingException("Unable to create signature for element", e);
         }
-
-        return true;
     }
 
     /**
@@ -982,4 +981,4 @@ public class XMLSignatureSigningStage extends BaseIteratingStage<Element> {
         }
 
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureValidationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureValidationStage.java
index d960096..fa8668b 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureValidationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/XMLSignatureValidationStage.java
@@ -27,6 +27,13 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.apache.xml.security.Init;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+
+import com.google.common.collect.ImmutableSet;
+
 import net.shibboleth.metadata.ErrorStatus;
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.WarningStatus;
@@ -39,13 +46,6 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.xml.SerializeSupport;
 
-import org.apache.xml.security.Init;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Element;
-
-import com.google.common.collect.ImmutableSet;
-
 /**
  * A pipeline stage which validates the XML digital signature found on DOM Elements.
  * 
@@ -241,9 +241,9 @@ public class XMLSignatureValidationStage extends BaseIteratingStage<Element> {
 
         permittingEmptyReferences = permit;
     }
-    
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         
         final Element docElement = item.unwrap();
         
@@ -259,13 +259,13 @@ public class XMLSignatureValidationStage extends BaseIteratingStage<Element> {
                 } else {
                     log.debug("DOM Element is not signed, no verification performed");
                 }
-                return true;
+                return;
             }
         } catch (final ValidationException e) {
             // pass on an error from signature location (e.g., multiple signatures)
             log.debug("setting status: ", e.getMessage());
             item.getItemMetadata().put(new ErrorStatus(getId(), e.getMessage()));
-            return true;
+            return;
         }
 
         if (log.isDebugEnabled()) {
@@ -281,10 +281,8 @@ public class XMLSignatureValidationStage extends BaseIteratingStage<Element> {
                 item.getItemMetadata().put(new ErrorStatus(getId(), message));
             } else {
                 item.getItemMetadata().put(new WarningStatus(getId(), message));
-            }            
+            }
         }
-
-        return true;
     }
 
     /** {@inheritDoc} */
@@ -314,4 +312,4 @@ public class XMLSignatureValidationStage extends BaseIteratingStage<Element> {
             Init.init();
         }
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ContactPersonFilterStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ContactPersonFilterStage.java
index 09612e3..0c8e0bb 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ContactPersonFilterStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ContactPersonFilterStage.java
@@ -27,6 +27,12 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+
+import com.google.common.collect.ImmutableSet;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
@@ -40,12 +46,6 @@ import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 import net.shibboleth.utilities.java.support.xml.ElementSupport;
 import net.shibboleth.utilities.java.support.xml.SerializeSupport;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Element;
-
-import com.google.common.collect.ImmutableSet;
-
 /**
  * Filtering stage that removes ContactPerson elements from EntityDescriptors.
  * 
@@ -153,15 +153,14 @@ public class ContactPersonFilterStage extends BaseIteratingStage<Element> {
         whitelistingTypes = whitelisting;
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element descriptor = item.unwrap();
         if (SAMLMetadataSupport.isEntitiesDescriptor(descriptor)) {
             processEntitiesDescriptor(descriptor);
         } else if (SAMLMetadataSupport.isEntityDescriptor(descriptor)) {
             processEntityDescriptor(descriptor);
         }
-        return true;
     }
 
     /**
@@ -212,7 +211,8 @@ public class ContactPersonFilterStage extends BaseIteratingStage<Element> {
     protected boolean isRetainedContactPersonType(@Nonnull final Element contactPerson) {
         Constraint.isNotNull(contactPerson, "Contact person element can not be null");
 
-        final String type = StringSupport.trimOrNull(AttributeSupport.getAttributeValue(contactPerson, null, "contactType"));
+        final String type =
+                StringSupport.trimOrNull(AttributeSupport.getAttributeValue(contactPerson, null, "contactType"));
 
         if (type == null) {
             log.debug(
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityDescriptorItemIdPopulationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityDescriptorItemIdPopulationStage.java
index 354bb81..a673e9f 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityDescriptorItemIdPopulationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityDescriptorItemIdPopulationStage.java
@@ -20,14 +20,14 @@ package net.shibboleth.metadata.dom.saml;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.ItemId;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 
-import org.w3c.dom.Element;
-
 /**
  * A stage which, for each EntityDescriptor collection element, adds an {@link ItemId}, with the entity's entity ID, to
  * the metadata item.
@@ -35,15 +35,13 @@ import org.w3c.dom.Element;
 @ThreadSafe
 public class EntityDescriptorItemIdPopulationStage extends BaseIteratingStage<Element> {
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element metadataElement = item.unwrap();
 
         if (SAMLMetadataSupport.isEntityDescriptor(metadataElement)) {
             final String entityId = AttributeSupport.getAttributeValue(metadataElement, null, "entityID");
             item.getItemMetadata().put(new ItemId(entityId));
         }
-
-        return true;
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityFilterStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityFilterStage.java
index 92f641a..cd50341 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityFilterStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityFilterStage.java
@@ -27,7 +27,7 @@ import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
 import net.shibboleth.metadata.Item;
-import net.shibboleth.metadata.pipeline.BaseIteratingStage;
+import net.shibboleth.metadata.pipeline.BaseFilteringStage;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
@@ -44,7 +44,7 @@ import com.google.common.collect.Iterables;
 
 /** A pipeline stage that will remove SAML EntityDescriptior elements which do meet specified filtering criteria. */
 @ThreadSafe
-public class EntityFilterStage extends BaseIteratingStage<Element> {
+public class EntityFilterStage extends BaseFilteringStage<Element> {
 
     /** Class logger. */
     private final Logger log = LoggerFactory.getLogger(EntityFilterStage.class);
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityRoleFilterStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityRoleFilterStage.java
index cf08109..8dddaa4 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityRoleFilterStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/EntityRoleFilterStage.java
@@ -30,7 +30,7 @@ import javax.annotation.concurrent.ThreadSafe;
 import javax.xml.namespace.QName;
 
 import net.shibboleth.metadata.Item;
-import net.shibboleth.metadata.pipeline.BaseIteratingStage;
+import net.shibboleth.metadata.pipeline.BaseFilteringStage;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
@@ -55,7 +55,7 @@ import com.google.common.collect.Iterables;
  * EntitiesDescriptors the role filter will effect all descendant EntityDescriptors.
  */
 @ThreadSafe
-public class EntityRoleFilterStage extends BaseIteratingStage<Element> {
+public class EntityRoleFilterStage extends BaseFilteringStage<Element> {
 
     /** QName of the RoleDescriptor element. */
     public static final QName ROLE_DESCRIPTOR_NAME = new QName(SAMLMetadataSupport.MD_NS, "RoleDescriptor");
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/GenerateIdStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/GenerateIdStage.java
index 88799a7..fc8c646 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/GenerateIdStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/GenerateIdStage.java
@@ -20,6 +20,9 @@ package net.shibboleth.metadata.dom.saml;
 import javax.annotation.Nonnull;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
@@ -28,9 +31,6 @@ import net.shibboleth.utilities.java.support.security.IdentifierGenerationStrate
 import net.shibboleth.utilities.java.support.security.Type4UUIDIdentifierGenerationStrategy;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-
 /** A stage that populates the ID attribute of an EntitiesDescriptor or EntityDescriptor. */
 public class GenerateIdStage extends BaseIteratingStage<Element> {
 
@@ -54,11 +54,11 @@ public class GenerateIdStage extends BaseIteratingStage<Element> {
         idGenerator = Constraint.isNotNull(generator, "ID generation strategy can not be null");
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element element = item.unwrap();
         if (!SAMLMetadataSupport.isEntityOrEntitiesDescriptor(element)) {
-            return true;
+            return;
         }
 
         Attr idAttribute = AttributeSupport.getAttribute(element, ID_ATTRIB);
@@ -68,7 +68,5 @@ public class GenerateIdStage extends BaseIteratingStage<Element> {
         }
 
         idAttribute.setValue(idGenerator.generateIdentifier());
-
-        return true;
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpCacheDurationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpCacheDurationStage.java
index 293c913..3d5b7f6 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpCacheDurationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpCacheDurationStage.java
@@ -23,6 +23,9 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
@@ -31,9 +34,6 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 import net.shibboleth.utilities.java.support.xml.ElementSupport;
 
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-
 /**
  * For each Item collection element that is a SAML EntitiesDescriptor this stage will scan all descendant
  * EntitiesDescriptors and EntityDescriptors, determine the shortest cache duration, set that on the root
@@ -95,12 +95,11 @@ public class PullUpCacheDurationStage extends BaseIteratingStage<Element> {
         maxCacheDuration = duration;
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element descriptor = item.unwrap();
         final Long cacheDuration = getShortestCacheDuration(descriptor);
         setCacheDuration(descriptor, cacheDuration);
-        return true;
     }
 
     /**
@@ -175,4 +174,4 @@ public class PullUpCacheDurationStage extends BaseIteratingStage<Element> {
                     cacheDuration);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpValidUntilStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpValidUntilStage.java
index d0d8934..63e3164 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpValidUntilStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/PullUpValidUntilStage.java
@@ -23,6 +23,9 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
@@ -31,9 +34,6 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 import net.shibboleth.utilities.java.support.xml.ElementSupport;
 
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-
 /**
  * For each Item collection element that is a SAML EntitiesDescriptor this stage will scan all descendant
  * EntitiesDescriptors and EntityDescriptors, determine the earliest valid until date, set that on the root
@@ -98,12 +98,11 @@ public class PullUpValidUntilStage extends BaseIteratingStage<Element> {
         maxValidityDuration = duration;
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element descriptor = item.unwrap();
         final Long nearestValidUntil = getNearestValidUntil(descriptor);
         setValidUntil(descriptor, nearestValidUntil);
-        return true;
     }
 
     /**
@@ -186,4 +185,4 @@ public class PullUpValidUntilStage extends BaseIteratingStage<Element> {
         AttributeSupport.appendDateTimeAttribute(descriptor, SAMLMetadataSupport.VALID_UNTIL_ATTRIB_NAME,
                 boundedValidUntil);
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/RemoveOrganizationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/RemoveOrganizationStage.java
index 3d0bf89..5415366 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/RemoveOrganizationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/RemoveOrganizationStage.java
@@ -22,15 +22,15 @@ import java.util.List;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
 import net.shibboleth.utilities.java.support.xml.ElementSupport;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Element;
-
 /** Filtering stage that removes Organization elements from EntityDescriptors. */
 @ThreadSafe
 public class RemoveOrganizationStage extends BaseIteratingStage<Element> {
@@ -38,15 +38,14 @@ public class RemoveOrganizationStage extends BaseIteratingStage<Element> {
     /** Class logger. */
     private final Logger log = LoggerFactory.getLogger(ContactPersonFilterStage.class);
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element descriptor = item.unwrap();
         if (SAMLMetadataSupport.isEntitiesDescriptor(descriptor)) {
             processEntitiesDescriptor(descriptor);
         } else if (SAMLMetadataSupport.isEntityDescriptor(descriptor)) {
             processEntityDescriptor(descriptor);
         }
-        return true;
     }
 
     /**
@@ -83,4 +82,4 @@ public class RemoveOrganizationStage extends BaseIteratingStage<Element> {
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetCacheDurationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetCacheDurationStage.java
index 9bb206d..091934d 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetCacheDurationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetCacheDurationStage.java
@@ -20,6 +20,8 @@ package net.shibboleth.metadata.dom.saml;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
@@ -30,8 +32,6 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 
-import org.w3c.dom.Element;
-
 /**
  * Sets a cacheDuration attribute for every EntityDescriptor and EntitiesDescriptor element in the collection.
  * 
@@ -69,16 +69,14 @@ public class SetCacheDurationStage extends BaseIteratingStage<Element> {
         cacheDuration = Constraint.isGreaterThan(0, duration, "cache duration must be greater than 0");
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element descriptor = item.unwrap();
         if (SAMLMetadataSupport.isEntityOrEntitiesDescriptor(descriptor)) {
             AttributeSupport.removeAttribute(descriptor, SAMLMetadataSupport.CACHE_DURATION_ATTRIB_NAME);
             AttributeSupport.appendDurationAttribute(descriptor, SAMLMetadataSupport.CACHE_DURATION_ATTRIB_NAME,
                     cacheDuration);
         }
-
-        return true;
     }
 
     /** {@inheritDoc} */
@@ -89,4 +87,4 @@ public class SetCacheDurationStage extends BaseIteratingStage<Element> {
             throw new ComponentInitializationException("cache duration must be greater than 0");
         }
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetValidUntilStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetValidUntilStage.java
index 5d9d176..30cf608 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetValidUntilStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/SetValidUntilStage.java
@@ -20,6 +20,8 @@ package net.shibboleth.metadata.dom.saml;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
@@ -30,8 +32,6 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 
-import org.w3c.dom.Element;
-
 /**
  * Sets a validUntil attribute for every EntityDescriptor and EntitiesDescriptor element in the collection.
  * 
@@ -69,16 +69,14 @@ public class SetValidUntilStage extends BaseIteratingStage<Element> {
         validityDuration = Constraint.isGreaterThan(0, duration, "validity duration must be greater than 0");
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element descriptor = item.unwrap();
         if (SAMLMetadataSupport.isEntityOrEntitiesDescriptor(descriptor)) {
             AttributeSupport.removeAttribute(descriptor, SAMLMetadataSupport.VALID_UNTIL_ATTRIB_NAME);
             AttributeSupport.appendDateTimeAttribute(descriptor, SAMLMetadataSupport.VALID_UNTIL_ATTRIB_NAME,
                     System.currentTimeMillis() + validityDuration);
         }
-
-        return true;
     }
 
     /** {@inheritDoc} */
@@ -89,4 +87,4 @@ public class SetValidUntilStage extends BaseIteratingStage<Element> {
             throw new ComponentInitializationException("validity duration must be greater than 0");
         }
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ValidateValidUntilStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ValidateValidUntilStage.java
index 63dd1df..3701040 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ValidateValidUntilStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/ValidateValidUntilStage.java
@@ -20,6 +20,8 @@ package net.shibboleth.metadata.dom.saml;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.w3c.dom.Element;
+
 import net.shibboleth.metadata.ErrorStatus;
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.pipeline.BaseIteratingStage;
@@ -28,8 +30,6 @@ import net.shibboleth.utilities.java.support.component.ComponentInitializationEx
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.xml.AttributeSupport;
 
-import org.w3c.dom.Element;
-
 /**
  * Checks that a SAML EntitiesDescriptor or EntityDescriptor's validUntil is (optionally) present and is within a given
  * range. Items which are not a SAML EntitiesDescriptor or EntityDescriptor are ignored.
@@ -90,12 +90,12 @@ public class ValidateValidUntilStage extends BaseIteratingStage<Element> {
         maxValidityInterval = interval;
     }
 
-    /** {@inheritDoc} */
-    @Override protected boolean doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
+    @Override
+    protected void doExecute(@Nonnull final Item<Element> item) throws StageProcessingException {
         final Element element = item.unwrap();
 
         if (!SAMLMetadataSupport.isEntitiesDescriptor(element)) {
-            return true;
+            return;
         }
 
         final Long validUntil =
@@ -119,8 +119,6 @@ public class ValidateValidUntilStage extends BaseIteratingStage<Element> {
                 }
             }
         }
-
-        return true;
     }
 
     /** {@inheritDoc} */
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdrpi/EntityRegistrationAuthorityFilterStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdrpi/EntityRegistrationAuthorityFilterStage.java
index ad77876..3979e20 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdrpi/EntityRegistrationAuthorityFilterStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdrpi/EntityRegistrationAuthorityFilterStage.java
@@ -36,7 +36,7 @@ import com.google.common.collect.Iterables;
 
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.dom.saml.SAMLMetadataSupport;
-import net.shibboleth.metadata.pipeline.BaseIteratingStage;
+import net.shibboleth.metadata.pipeline.BaseFilteringStage;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
@@ -46,7 +46,7 @@ import net.shibboleth.utilities.java.support.xml.ElementSupport;
 
 /** A pipeline stage that will filter EntityDescriptor or EntityDescriptors based on their registration authority. */
 @ThreadSafe
-public class EntityRegistrationAuthorityFilterStage extends BaseIteratingStage<Element> {
+public class EntityRegistrationAuthorityFilterStage extends BaseFilteringStage<Element> {
 
     /** Class logger. */
     private final Logger log = LoggerFactory.getLogger(EntityRegistrationAuthorityFilterStage.class);
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseIteratingStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseFilteringStage.java
similarity index 73%
copy from aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseIteratingStage.java
copy to aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseFilteringStage.java
index d693db2..b9416b3 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseIteratingStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseFilteringStage.java
@@ -27,26 +27,30 @@ import net.shibboleth.metadata.Item;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 
 /**
- * Base class for {@link Stage} implementations that iterate over each {@link Item} in a collection and do something.
+ * Base class for {@link Stage} implementations that iterate over each {@link Item} in a collection and do something,
+ * then optionally remove the item being processed.
  * 
  * @param <T> type of metadata this stage operates upon
  */
 @ThreadSafe
-public abstract class BaseIteratingStage<T> extends BaseStage<T> {
+public abstract class BaseFilteringStage<T> extends BaseStage<T> {
 
     /**
      * Iterates over each element of the Item collection and delegates the processing of that element to
      * {@link #doExecute(Item)}.
-     * 
+     *
+     * {@link #doExecute(Item)} can request that the {@link Item} be dropped from the collection by
+     * returning <code>false</code>.
+     *
      * {@inheritDoc}
      */
-     @Override protected void doExecute(@Nonnull @NonnullElements final Collection<Item<T>> itemCollection)
+    @Override
+    protected void doExecute(@Nonnull @NonnullElements final Collection<Item<T>> itemCollection)
             throws StageProcessingException {
         final Iterator<Item<T>> itemIterator = itemCollection.iterator();
 
-        Item<T> item;
         while (itemIterator.hasNext()) {
-            item = itemIterator.next();
+            final Item<T> item = itemIterator.next();
             if (!doExecute(item)) {
                 itemIterator.remove();
             }
@@ -54,13 +58,13 @@ public abstract class BaseIteratingStage<T> extends BaseStage<T> {
     }
 
     /**
-     * Processes a given Item.
+     * Processes a given {@link Item}.
      * 
-     * @param item Item on which to operate
+     * @param item {@link Item} on which to operate
      * 
-     * @return true if the Item should be retained in the collection, false if not
+     * @return <code>true</code> if the {@link Item} should be retained in the collection, <code>false</code> if not
      * 
      * @throws StageProcessingException thrown if there is a problem with the stage processing
      */
     protected abstract boolean doExecute(@Nonnull final Item<T> item) throws StageProcessingException;
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseIteratingStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseIteratingStage.java
index d693db2..f8dd17a 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseIteratingStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/BaseIteratingStage.java
@@ -18,7 +18,6 @@
 package net.shibboleth.metadata.pipeline;
 
 import java.util.Collection;
-import java.util.Iterator;
 
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.ThreadSafe;
@@ -37,30 +36,23 @@ public abstract class BaseIteratingStage<T> extends BaseStage<T> {
     /**
      * Iterates over each element of the Item collection and delegates the processing of that element to
      * {@link #doExecute(Item)}.
-     * 
+     *
      * {@inheritDoc}
      */
-     @Override protected void doExecute(@Nonnull @NonnullElements final Collection<Item<T>> itemCollection)
+    @Override
+    protected void doExecute(@Nonnull @NonnullElements final Collection<Item<T>> itemCollection)
             throws StageProcessingException {
-        final Iterator<Item<T>> itemIterator = itemCollection.iterator();
-
-        Item<T> item;
-        while (itemIterator.hasNext()) {
-            item = itemIterator.next();
-            if (!doExecute(item)) {
-                itemIterator.remove();
-            }
+        for (final Item<T> item : itemCollection) {
+            doExecute(item);
         }
     }
 
     /**
-     * Processes a given Item.
-     * 
-     * @param item Item on which to operate
+     * Processes a given {@link Item}.
      * 
-     * @return true if the Item should be retained in the collection, false if not
+     * @param item {@link Item} on which to operate
      * 
      * @throws StageProcessingException thrown if there is a problem with the stage processing
      */
-    protected abstract boolean doExecute(@Nonnull final Item<T> item) throws StageProcessingException;
-}
\ No newline at end of file
+    protected abstract void doExecute(@Nonnull final Item<T> item) throws StageProcessingException;
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemIdTransformStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemIdTransformStage.java
index 07de915..fccb40e 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemIdTransformStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemIdTransformStage.java
@@ -41,7 +41,7 @@ import net.shibboleth.utilities.java.support.component.ComponentSupport;
  * @param <T> type of {@link Item} this stage operates upon
  */
 @ThreadSafe
-public class ItemIdTransformStage<T> extends BaseIteratingStage<T> {
+public class ItemIdTransformStage<T> extends BaseFilteringStage<T> {
 
     /** Transformers used on IDs. */
     private Collection<Function<String, String>> idTransformers = new LazyList<>();
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataAddingStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataAddingStage.java
index c8ca764..7c377e4 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataAddingStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataAddingStage.java
@@ -37,7 +37,7 @@ import com.google.common.base.Predicates;
  * @param <T> type of {@link Item} this stage operates upon
  */
 @ThreadSafe
-public class ItemMetadataAddingStage<T> extends BaseIteratingStage<T> {
+public class ItemMetadataAddingStage<T> extends BaseFilteringStage<T> {
 
     /** {@link ItemMetadata} objects to add to each {@link Item}'s item metadata. */
     private Collection<ItemMetadata> additionalItemMetadata = new LazyList<>();

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


More information about the commits mailing list