[java-metadata-aggregator] branch master updated: MDA-201 - Add AcceptAll/RejectAll validator components

Ian Young ian at iay.org.uk
Tue Jan 30 10:11:06 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=42730675033f6405a3505166a40a3b9a068fadaf

The following commit(s) were added to refs/heads/master by this push:
       new  4273067   MDA-201 - Add AcceptAll/RejectAll validator components
4273067 is described below

commit 42730675033f6405a3505166a40a3b9a068fadaf
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Tue Jan 30 15:11:01 2018 +0000

    MDA-201 - Add AcceptAll/RejectAll validator components
---
 .../metadata/validate/AcceptAllValidator.java      | 38 +++++++++++++++
 .../metadata/validate/RejectAllValidator.java      | 42 +++++++++++++++++
 .../resources/net/shibboleth/metadata/beans.xml    |  6 +++
 .../metadata/validate/AcceptAllValidatorTest.java  | 31 +++++++++++++
 .../metadata/validate/RejectAllValidatorTest.java  | 54 ++++++++++++++++++++++
 5 files changed, 171 insertions(+)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/AcceptAllValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/AcceptAllValidator.java
new file mode 100644
index 0000000..995ec82
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/AcceptAllValidator.java
@@ -0,0 +1,38 @@
+/*
+ * 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.validate;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+
+/**
+ * A {@link Validator} which accepts any value, returning
+ * {@link net.shibboleth.metadata.validate.Validator.Action#DONE}
+ * to terminate any validator sequence.
+ *
+ * @param <V> type of the object to be validated
+ */
+public class AcceptAllValidator<V> extends BaseValidator implements Validator<V> {
+
+    @Override
+    public Action validate(@Nonnull final V e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
+        return Action.DONE;
+    }
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/RejectAllValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/RejectAllValidator.java
new file mode 100644
index 0000000..bdde905
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/RejectAllValidator.java
@@ -0,0 +1,42 @@
+/*
+ * 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.validate;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+
+/**
+ * A {@link Validator} which rejects any value, returning
+ * {@link net.shibboleth.metadata.validate.Validator.Action#DONE}
+ * to terminate any validator sequence.
+ *
+ * An error status is added using the value of the given property as a format string.
+ * The message defaults to a simple rejection message including the object's string value.
+ *
+ * @param <V> type of the object to be validated
+ */
+public class RejectAllValidator<V> extends BaseValidator implements Validator<V> {
+
+    @Override
+    public Action validate(@Nonnull final V e, @Nonnull final Item<?> item, @Nonnull final String stageId) {
+        addErrorMessage(e, item, stageId);
+        return Action.DONE;
+    }
+
+}
diff --git a/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml b/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
index 8fe1cee..180500b 100644
--- a/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
+++ b/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
@@ -265,6 +265,12 @@
 
     <bean id="mda.validator_parent" abstract="true" parent="mda.component_parent"/>
 
+    <bean id="mda.AcceptAllValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.AcceptAllValidator"/>
+
+    <bean id="mda.RejectAllValidator" abstract="true" parent="mda.validator_parent"
+        class="net.shibboleth.metadata.validate.RejectAllValidator"/>
+
     <!--
         net.shibboleth.metadata.validate.x509
     -->
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/AcceptAllValidatorTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/AcceptAllValidatorTest.java
new file mode 100644
index 0000000..2ff56c1
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/AcceptAllValidatorTest.java
@@ -0,0 +1,31 @@
+
+package net.shibboleth.metadata.validate;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.metadata.validate.Validator;
+import net.shibboleth.metadata.validate.Validator.Action;
+
+public class AcceptAllValidatorTest {
+
+    @Test
+    public void validate() throws Exception {
+        final AcceptAllValidator<String> v = new AcceptAllValidator<>();
+        v.setId("comp");
+        v.initialize();
+
+        final Item<String> item = new MockItem("test");
+        final Validator.Action action = v.validate("foo", item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 0);
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/RejectAllValidatorTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/RejectAllValidatorTest.java
new file mode 100644
index 0000000..26fff1a
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/RejectAllValidatorTest.java
@@ -0,0 +1,54 @@
+
+package net.shibboleth.metadata.validate;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.metadata.validate.Validator;
+import net.shibboleth.metadata.validate.Validator.Action;
+
+public class RejectAllValidatorTest {
+
+    @Test
+    public void validate() throws Exception {
+        final RejectAllValidator<String> v = new RejectAllValidator<>();
+        v.setId("comp");
+        v.initialize();
+
+        final Item<String> item = new MockItem("test");
+        final Validator.Action action = v.validate("foo", item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 1);
+
+        final ErrorStatus err = errs.get(0);
+        Assert.assertEquals(err.getComponentId(), "stage/comp");
+        Assert.assertEquals(err.getStatusMessage(), "value rejected: 'foo'");
+    }
+
+    @Test
+    public void validateWithMessage() throws Exception {
+        final RejectAllValidator<Double> v = new RejectAllValidator<>();
+        v.setId("comp");
+        v.setMessage("decimal %.2f");
+        v.initialize();
+
+        final Item<String> item = new MockItem("test");
+        final Validator.Action action = v.validate(new Double(1.25), item, "stage");
+        Assert.assertEquals(action, Action.DONE);
+
+        final List<ErrorStatus> errs = item.getItemMetadata().get(ErrorStatus.class);
+        Assert.assertEquals(errs.size(), 1);
+
+        final ErrorStatus err = errs.get(0);
+        Assert.assertEquals(err.getComponentId(), "stage/comp");
+        Assert.assertEquals(err.getStatusMessage(), "decimal 1.25");
+    }
+
+}

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


More information about the commits mailing list