[java-metadata-aggregator] 02/06: MDA-154 add X.509 certificate validation framework

Ian Young ian at iay.org.uk
Thu Dec 10 12:32:45 EST 2015


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

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

commit 002c3f50467003d70ee914e905788afa1988527c
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Dec 10 17:16:19 2015 +0000

    MDA-154 add X.509 certificate validation framework
    
    Import of X.509 certificate validator framework from ukf-mda project.
---
 .../validate/x509/AbstractX509Validator.java       | 30 ++++++++++++++
 .../metadata/validate/x509/package-info.java       | 22 ++++++++++
 .../validate/x509/BaseX509ValidatorTest.java       | 47 ++++++++++++++++++++++
 3 files changed, 99 insertions(+)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/x509/AbstractX509Validator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/x509/AbstractX509Validator.java
new file mode 100644
index 0000000..8017de6
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/x509/AbstractX509Validator.java
@@ -0,0 +1,30 @@
+/*
+ * 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.x509;
+
+import java.security.cert.X509Certificate;
+
+import net.shibboleth.metadata.validate.BaseValidator;
+import net.shibboleth.metadata.validate.Validator;
+
+/**
+ * Abstract class implementing validation on {@link X509Certificate} objects.
+ */
+public abstract class AbstractX509Validator extends BaseValidator implements Validator<X509Certificate> {
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/x509/package-info.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/x509/package-info.java
new file mode 100644
index 0000000..cd84e02
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/x509/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * Validation classes for X.509 certificate objects.
+ */
+
+package net.shibboleth.metadata.validate.x509;
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/x509/BaseX509ValidatorTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/x509/BaseX509ValidatorTest.java
new file mode 100644
index 0000000..a8341e8
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/validate/x509/BaseX509ValidatorTest.java
@@ -0,0 +1,47 @@
+
+package net.shibboleth.metadata.validate.x509;
+
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.Collection;
+
+import org.springframework.core.io.Resource;
+import org.testng.Assert;
+
+import net.shibboleth.metadata.BaseTest;
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.WarningStatus;
+
+public abstract class BaseX509ValidatorTest extends BaseTest {
+    
+    private CertificateFactory factory;
+
+    public BaseX509ValidatorTest(final Class<?> clazz) throws Exception {
+        super(clazz);
+        factory = CertificateFactory.getInstance("X.509");
+    }
+
+    protected X509Certificate getCertificate(final String id) throws Exception {
+        final Resource certResource = getClasspathResource(id);
+        final X509Certificate cert =
+                (X509Certificate) factory.generateCertificate(certResource.getInputStream());
+        return cert;
+    }
+
+    protected void errorsAndWarnings(final Item<?> item,
+            final int expectedErrors, final int expectedWarnings) {
+        final Collection<ErrorStatus> errors = item.getItemMetadata().get(ErrorStatus.class);
+        final Collection<WarningStatus> warnings = item.getItemMetadata().get(WarningStatus.class);
+        //System.out.println("Errors and warnings:");
+        //for (ErrorStatus err: errors) {
+        //    System.out.println("Error: " + err.getComponentId() + ": " + err.getStatusMessage());
+        //}
+        //for (WarningStatus warn: warnings) {
+        //    System.out.println("Warning: " + warn.getComponentId() + ": " + warn.getStatusMessage());
+        //}
+        Assert.assertEquals(errors.size(), expectedErrors, "wrong number of errors");
+        Assert.assertEquals(warnings.size(), expectedWarnings, "wrong number of warnings");
+    }
+
+}

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


More information about the commits mailing list