[java-metadata-aggregator] branch main updated: MDA-208 - XMLSignatureSigningStage.ShaVariant should be SHAVariant

Ian Young ian at iay.org.uk
Fri May 26 10:43:44 UTC 2023


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

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

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

The following commit(s) were added to refs/heads/main by this push:
     new a5c8f8c  MDA-208 - XMLSignatureSigningStage.ShaVariant should be SHAVariant
a5c8f8c is described below

commit a5c8f8cdf94bbe3936e1178c250fc28a1a086510
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Fri May 26 11:43:40 2023 +0100

    MDA-208 - XMLSignatureSigningStage.ShaVariant should be SHAVariant
    
    https://shibboleth.atlassian.net/browse/MDA-208
---
 .../metadata/dom/XMLSignatureSigningStage.java     | 48 +++++++++++++++++++---
 .../metadata/dom/impl/XMLSignatureSigner.java      |  2 +-
 .../dom/XMLSignatureSigningStageSpringTest.java    | 39 ++++++++++++++++++
 .../dom/XMLSignatureSigningStageSpringTestOld.java | 43 +++++++++++++++++++
 .../metadata/dom/XMLSignatureSigningStageTest.java |  2 +-
 .../XMLSignatureSigningStageSpringTest-config.xml  | 23 +++++++++++
 ...MLSignatureSigningStageSpringTestOld-config.xml | 23 +++++++++++
 7 files changed, 172 insertions(+), 8 deletions(-)

diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java b/mda-framework/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java
index e17cb6e..6e25ca5 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/dom/XMLSignatureSigningStage.java
@@ -43,6 +43,8 @@ import net.shibboleth.shared.annotation.constraint.Unmodifiable;
 import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.DeprecationSupport;
+import net.shibboleth.shared.primitive.DeprecationSupport.ObjectType;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
@@ -58,8 +60,12 @@ import net.shibboleth.shared.primitive.LoggerFactory;
 @ThreadSafe
 public class XMLSignatureSigningStage extends AbstractStage<Element> {
 
-    /** The variant of SHA to use in the various signature algorithms. */
-    public static enum ShaVariant {
+    /**
+     * The variant of SHA to use in the various signature algorithms.
+     * 
+     * @since 0.10.0
+     */
+    public static enum SHAVariant {
         /** 160-bit SHA-1. */
         SHA1,
         /** 256-bit SHA-2. */
@@ -73,9 +79,9 @@ public class XMLSignatureSigningStage extends AbstractStage<Element> {
     /** Class logger. */
     private static final @Nonnull Logger LOG = LoggerFactory.getLogger(XMLSignatureSigningStage.class);
 
-    /** SHA algorithm variant used in signature and digest algorithms. Default value: <code>ShaVariant.SHA256</code> */
+    /** SHA algorithm variant used in signature and digest algorithms. Default value: <code>SHAVariant.SHA256</code> */
     @Nonnull @GuardedBy("this")
-    private ShaVariant shaVariant = ShaVariant.SHA256;
+    private SHAVariant shaVariant = SHAVariant.SHA256;
 
     /** Private key used to sign data. */
     @NonnullAfterInit @GuardedBy("this")
@@ -160,8 +166,10 @@ public class XMLSignatureSigningStage extends AbstractStage<Element> {
      * Gets the SHA algorithm variant used when computing the signature and digest.
      * 
      * @return SHA algorithm variant used when computing the signature and digest
+     *
+     * @since 0.10.0
      */
-    @Nonnull public final synchronized ShaVariant getShaVariant() {
+    public final synchronized @Nonnull SHAVariant getSHAVariant() {
         return shaVariant;
     }
 
@@ -169,12 +177,40 @@ public class XMLSignatureSigningStage extends AbstractStage<Element> {
      * Sets the SHA algorithm variant used when computing the signature and digest.
      * 
      * @param variant SHA algorithm variant used when computing the signature and digest
+     *
+     * @since 0.10.0
      */
-    public synchronized void setShaVariant(@Nonnull final ShaVariant variant) {
+    public synchronized void setSHAVariant(@Nonnull final SHAVariant variant) {
         checkSetterPreconditions();
         shaVariant = Constraint.isNotNull(variant, "SHA variant can not be null");
     }
 
+    /**
+     * Gets the SHA algorithm variant used when computing the signature and digest.
+     * 
+     * @return SHA algorithm variant used when computing the signature and digest
+     *
+     * @deprecated Use {@link #getSHAVariant}.
+     */
+    @Deprecated(forRemoval = true)
+    public final @Nonnull SHAVariant getShaVariant() {
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "getShaVariant", "XMLSignatureSigningStage", "getSHAVariant");
+        return getSHAVariant();
+    }
+
+    /**
+     * Sets the SHA algorithm variant used when computing the signature and digest.
+     * 
+     * @param variant SHA algorithm variant used when computing the signature and digest
+     *
+     * @deprecated Use {@link #setSHAVariant}.
+     */
+    @Deprecated(forRemoval = true)
+    public synchronized void setShaVariant(@Nonnull final SHAVariant variant) {
+        DeprecationSupport.warnOnce(ObjectType.METHOD, "setShaVariant", "XMLSignatureSigningStage", "setSHAVariant");
+        setSHAVariant(variant);
+    }
+
     /**
      * Gets the private key used to sign the content.
      * 
diff --git a/mda-framework/src/main/java/net/shibboleth/metadata/dom/impl/XMLSignatureSigner.java b/mda-framework/src/main/java/net/shibboleth/metadata/dom/impl/XMLSignatureSigner.java
index fe0555e..c702538 100644
--- a/mda-framework/src/main/java/net/shibboleth/metadata/dom/impl/XMLSignatureSigner.java
+++ b/mda-framework/src/main/java/net/shibboleth/metadata/dom/impl/XMLSignatureSigner.java
@@ -203,7 +203,7 @@ public class XMLSignatureSigner {
                 }
             }
 
-            switch (stage.getShaVariant()) {
+            switch (stage.getSHAVariant()) {
                 case SHA1:
                     sigAlgo = SignatureMethod.RSA_SHA1;
                     digestAlgo = DigestMethod.SHA1;
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTest.java
new file mode 100644
index 0000000..c47b754
--- /dev/null
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.dom.XMLSignatureSigningStage.SHAVariant;
+
+ at ContextConfiguration({"XMLSignatureSigningStageSpringTest-config.xml"})
+public class XMLSignatureSigningStageSpringTest extends AbstractTestNGSpringContextTests {
+    
+    @Autowired
+    XMLSignatureSigningStage stage;
+    
+    @Test
+    public void testSetSHAVariant() throws Exception {
+        Assert.assertEquals(stage.getSHAVariant(), SHAVariant.SHA384);
+    }
+
+}
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTestOld.java b/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTestOld.java
new file mode 100644
index 0000000..ea8dcf1
--- /dev/null
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTestOld.java
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.dom.XMLSignatureSigningStage.SHAVariant;
+
+ at ContextConfiguration({"XMLSignatureSigningStageSpringTestOld-config.xml"})
+public class XMLSignatureSigningStageSpringTestOld extends AbstractTestNGSpringContextTests {
+    
+    @Autowired
+    XMLSignatureSigningStage stage;
+    
+    @SuppressWarnings("removal")
+    @Test
+    public void testSetSHAVariant() throws Exception {
+        // Check use of the old deprecated getter.
+        // The deprecated setter is used in the configuration file.
+        // We should see deprecation warnings for both in the logs.
+        Assert.assertEquals(stage.getShaVariant(), SHAVariant.SHA384);
+    }
+
+}
diff --git a/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageTest.java b/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageTest.java
index 4c5bfa5..f9c85fa 100644
--- a/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageTest.java
+++ b/mda-framework/src/test/java/net/shibboleth/metadata/dom/XMLSignatureSigningStageTest.java
@@ -318,7 +318,7 @@ public class XMLSignatureSigningStageTest extends BaseDOMTest {
     @Test
     public final void testDefaultHash() {
         final var stage = new XMLSignatureSigningStage();
-        Assert.assertEquals(stage.getShaVariant(), XMLSignatureSigningStage.ShaVariant.SHA256);
+        Assert.assertEquals(stage.getSHAVariant(), XMLSignatureSigningStage.SHAVariant.SHA256);
     }
 
     private boolean hasChildNamed(@Nonnull final Element element, @Nonnull final QName name) {
diff --git a/mda-framework/src/test/resources/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTest-config.xml b/mda-framework/src/test/resources/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTest-config.xml
new file mode 100644
index 0000000..9e21749
--- /dev/null
+++ b/mda-framework/src/test/resources/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTest-config.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:c="http://www.springframework.org/schema/c"
+    xmlns:context="http://www.springframework.org/schema/context"
+    xmlns:mvc="http://www.springframework.org/schema/mvc"
+    xmlns:p="http://www.springframework.org/schema/p"
+    xmlns:util="http://www.springframework.org/schema/util"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
+        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+    <import resource="classpath:net/shibboleth/metadata/beans.xml"/>
+
+    <bean id="stage" parent="mda.XMLSignatureSigningStage"
+        p:id="stage"
+        p:SHAVariant="SHA384"
+        init-method="initialize"
+        destroy-method="destroy"/>
+
+</beans>
diff --git a/mda-framework/src/test/resources/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTestOld-config.xml b/mda-framework/src/test/resources/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTestOld-config.xml
new file mode 100644
index 0000000..61ab4ea
--- /dev/null
+++ b/mda-framework/src/test/resources/net/shibboleth/metadata/dom/XMLSignatureSigningStageSpringTestOld-config.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:c="http://www.springframework.org/schema/c"
+    xmlns:context="http://www.springframework.org/schema/context"
+    xmlns:mvc="http://www.springframework.org/schema/mvc"
+    xmlns:p="http://www.springframework.org/schema/p"
+    xmlns:util="http://www.springframework.org/schema/util"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
+        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+    <import resource="classpath:net/shibboleth/metadata/beans.xml"/>
+
+    <bean id="stage" parent="mda.XMLSignatureSigningStage"
+        p:id="stage"
+        p:ShaVariant="SHA384"
+        init-method="initialize"
+        destroy-method="destroy"/>
+
+</beans>

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


More information about the commits mailing list