[java-metadata-aggregator] branch master updated: MDA-192 - move SAML-specific methods down from AbstractDOMTraversalStage

Ian Young ian at iay.org.uk
Tue Jan 30 11:47:26 EST 2018


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=27bf40527c3fe6c250a93550961cfd0bfe785c5a

The following commit(s) were added to refs/heads/master by this push:
       new  27bf405   MDA-192 - move SAML-specific methods down from AbstractDOMTraversalStage
27bf405 is described below

commit 27bf40527c3fe6c250a93550961cfd0bfe785c5a
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Tue Jan 30 16:47:07 2018 +0000

    MDA-192 - move SAML-specific methods down from AbstractDOMTraversalStage
---
 .../metadata/dom/AbstractDOMTraversalStage.java    | 35 ++-------
 .../shibboleth/metadata/dom/CRDetectionStage.java  |  3 +-
 .../dom/saml/AbstractSAMLTraversalStage.java       | 88 ++++++++++++++++++++++
 3 files changed, 97 insertions(+), 29 deletions(-)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/AbstractDOMTraversalStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/AbstractDOMTraversalStage.java
index b4e24c2..a498266 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/AbstractDOMTraversalStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/AbstractDOMTraversalStage.java
@@ -22,13 +22,11 @@ import java.util.List;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.ThreadSafe;
 
-import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
 
 import net.shibboleth.metadata.ErrorStatus;
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.ItemMetadata;
-import net.shibboleth.metadata.dom.saml.SAMLMetadataSupport;
 import net.shibboleth.metadata.pipeline.AbstractIteratingStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
 import net.shibboleth.utilities.java.support.collection.ClassToInstanceMultiMap;
@@ -110,20 +108,13 @@ public abstract class AbstractDOMTraversalStage<C extends DOMTraversalContext>
     }
 
     /**
-     * Returns the {@link Element} representing the EntityDescriptor which is the
-     * closest-containing ancestor of the given element.
-     * 
-     * @param element {@link Element} to locate the ancestor Entity of.
-     * @return ancestor EntityDescriptor {@link Element}, or null.
+     * Computes a prefix to be put in front of the message in {@link #addError}.
+     *
+     * @param element {@link Element} forming the context for the prefix
+     * @return a prefix for the error message
      */
-    protected Element ancestorEntity(@Nonnull final Element element) {
-        assert element != null;
-        for (Element e = element; e != null; e = (Element) e.getParentNode()) {
-            if (SAMLMetadataSupport.isEntityDescriptor(e)) {
-                return e;
-            }
-        }
-        return null;
+    protected String errorPrefix(@Nonnull final Element element) {
+        return "";
     }
 
     /**
@@ -141,19 +132,7 @@ public abstract class AbstractDOMTraversalStage<C extends DOMTraversalContext>
         assert element != null;
         assert error != null;
         final ClassToInstanceMultiMap<ItemMetadata> metadata = item.getItemMetadata();
-        String prefix = "";
-        if (SAMLMetadataSupport.isEntitiesDescriptor(element)) {
-            final Element entity = ancestorEntity(element);
-            final Attr id = entity.getAttributeNode("ID");
-            if (id != null) {
-                prefix = id.getTextContent() + ": ";
-            } else {
-                final Attr entityID = entity.getAttributeNode("entityID");
-                if (entityID != null) {
-                    prefix = entityID.getTextContent() + ": ";
-                }
-            }
-        }
+        final String prefix = errorPrefix(element);
         metadata.put(new ErrorStatus(getId(), prefix + error));
     }
 
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/CRDetectionStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/CRDetectionStage.java
index 795bfd0..9f4da49 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/CRDetectionStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/CRDetectionStage.java
@@ -24,6 +24,7 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
 import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.dom.saml.AbstractSAMLTraversalStage;
 import net.shibboleth.metadata.pipeline.StageProcessingException;
 
 /**
@@ -36,7 +37,7 @@ import net.shibboleth.metadata.pipeline.StageProcessingException;
  * 
  * @see <a href="https://issues.shibboleth.net/jira/browse/SSPCPP-684">SSPCPP-684</a>
  */
-public class CRDetectionStage extends AbstractDOMTraversalStage<CRDetectionStage.Context> {
+public class CRDetectionStage extends AbstractSAMLTraversalStage<CRDetectionStage.Context> {
 
     /** Context class for this kind of traversal. */
     protected static class Context extends SimpleDOMTraversalContext {
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/AbstractSAMLTraversalStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/AbstractSAMLTraversalStage.java
new file mode 100644
index 0000000..486ba14
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/AbstractSAMLTraversalStage.java
@@ -0,0 +1,88 @@
+/*
+ * 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.metadata.dom.saml;
+
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
+import net.shibboleth.metadata.dom.AbstractDOMTraversalStage;
+import net.shibboleth.metadata.dom.DOMTraversalContext;
+import net.shibboleth.metadata.dom.SimpleDOMTraversalContext;
+
+/**
+ * An abstract SAML DOM metadata traversal class using the template method pattern.
+ *
+ * A context object, extending {@link DOMTraversalContext}, is created by the
+ * implementing subclass and passed to the {@link #visit} method when
+ * each applicable {@link Element} is visited. In very simple cases, the
+ * {@link SimpleDOMTraversalContext} may suffice, but more complicated
+ * behaviour can be built up by extending or re-implementing that class.
+ *
+ * At the end of the traversal, the context's {@link DOMTraversalContext#end()}
+ * method is called to perform any post-processing required.
+ *
+ * @param <C> the context to carry through the traversal
+ */
+ at ThreadSafe
+public abstract class AbstractSAMLTraversalStage <C extends DOMTraversalContext>
+    extends AbstractDOMTraversalStage<C> {
+
+    /**
+     * Returns the {@link Element} representing the EntityDescriptor which is the
+     * closest-containing ancestor of the given element.
+     * 
+     * @param element {@link Element} to locate the ancestor Entity of.
+     * @return ancestor EntityDescriptor {@link Element}, or null.
+     */
+    private Element ancestorEntity(@Nonnull final Element element) {
+        assert element != null;
+        for (Element e = element; e != null; e = (Element) e.getParentNode()) {
+            if (SAMLMetadataSupport.isEntityDescriptor(e)) {
+                return e;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Computes a prefix to be put in front of the message in {@link #addError}.
+     *
+     * @param element {@link Element} forming the context for the prefix
+     * @return a prefix for the error message
+     */
+    @Override
+    protected String errorPrefix(@Nonnull final Element element) {
+        if (SAMLMetadataSupport.isEntitiesDescriptor(element)) {
+            final Element entity = ancestorEntity(element);
+            final Attr id = entity.getAttributeNode("ID");
+            if (id != null) {
+                return id.getTextContent() + ": ";
+            } else {
+                final Attr entityID = entity.getAttributeNode("entityID");
+                if (entityID != null) {
+                    return entityID.getTextContent() + ": ";
+                }
+            }
+        }
+        return "";
+    }
+
+}

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


More information about the commits mailing list