[java-opensaml] 01/03: OSJ-224: KeyDescriptorUnmarshaller is Locale dependent

Brent Putman putmanb at georgetown.edu
Fri Sep 28 22:52:59 EDT 2018


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

putmanb pushed a commit to branch master
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=36b485ab703eb89e4d9f20f2fef36e509ee87b6b

commit 36b485ab703eb89e4d9f20f2fef36e509ee87b6b
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Fri Sep 28 20:07:32 2018 -0400

    OSJ-224: KeyDescriptorUnmarshaller is Locale dependent
---
 .../metadata/impl/KeyDescriptorUnmarshaller.java   | 13 ++++------
 .../saml2/metadata/impl/KeyDescriptorTest.java     | 26 ++++++++++++++++---
 ...utes2.xml => KeyDescriptorUnknownAttribute.xml} |  2 +-
 ...ributes1.xml => KeyDescriptorUseEncryption.xml} |  2 +-
 ...ributes2.xml => KeyDescriptorUseNotPresent.xml} |  2 +-
 ...Attributes2.xml => KeyDescriptorUseSigning.xml} |  2 +-
 ...ibutes2.xml => KeyDescriptorUseUnspecified.xml} |  2 +-
 ...butes2.xml => KeyDescriptorUseValueIllegal.xml} |  2 +-
 .../opensaml/security/credential/UsageType.java    | 30 +++++++++++++++++++---
 9 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnmarshaller.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnmarshaller.java
index 8f2db8b..99a6465 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnmarshaller.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnmarshaller.java
@@ -50,14 +50,11 @@ public class KeyDescriptorUnmarshaller extends AbstractSAMLObjectUnmarshaller {
         final KeyDescriptor keyDescriptor = (KeyDescriptor) samlObject;
 
         if (attribute.getName().equals(KeyDescriptor.USE_ATTRIB_NAME) && attribute.getNamespaceURI() == null) {
-            try {
-                final UsageType usageType = UsageType.valueOf(UsageType.class, attribute.getValue().toUpperCase());
-                // Only allow the enum values specified in the schema.
-                if (usageType != UsageType.SIGNING && usageType != UsageType.ENCRYPTION) {
-                    throw new UnmarshallingException("Invalid key usage type: " + attribute.getValue());
-                }
-                keyDescriptor.setUse(usageType);
-            } catch (final IllegalArgumentException e) {
+            if (UsageType.SIGNING.getValue().equals(attribute.getValue())) {
+                keyDescriptor.setUse(UsageType.SIGNING);
+            } else if (UsageType.ENCRYPTION.getValue().equals(attribute.getValue())) {
+                keyDescriptor.setUse(UsageType.ENCRYPTION);
+            } else {
                 throw new UnmarshallingException("Invalid key usage type: " + attribute.getValue());
             }
         } else {
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorTest.java
index cfeea2b..2a258a8 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorTest.java
@@ -77,20 +77,38 @@ public class KeyDescriptorTest extends XMLObjectProviderBaseTestCase {
     }
     
     @Test
-    public void testSingleElementBadAttributesUnmarshall() {
+    public void testSingleElementUnknownAttribute() {
+        unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnknownAttribute.xml");
+    }
+    
+    @Test
+    public void testUsageEnum() {
+        KeyDescriptor keyDescriptor = null;
+        
+        keyDescriptor = unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseNotPresent.xml");
+        Assert.assertEquals(keyDescriptor.getUse(), UsageType.UNSPECIFIED);
+            
+        keyDescriptor = unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseSigning.xml");
+        Assert.assertEquals(keyDescriptor.getUse(), UsageType.SIGNING);
+        
+        keyDescriptor = unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseEncryption.xml");
+        Assert.assertEquals(keyDescriptor.getUse(), UsageType.ENCRYPTION);
+        
         try {
-            unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes1.xml");
+            keyDescriptor = unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseUnspecified.xml");
             Assert.fail();
         } catch (AssertionError e) {
+            //Expected
         }
+        
         try {
-            unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml");
+            keyDescriptor = unmarshallElement("/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseValueIllegal.xml");
             Assert.fail();
         } catch (AssertionError e) {
+            //Expected
         }
        
     }
-    
 
     /** {@inheritDoc} */
     @Test
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnknownAttribute.xml
similarity index 85%
copy from opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
copy to opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnknownAttribute.xml
index 2dfcb78..c2712b7 100644
--- a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUnknownAttribute.xml
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="rabbit"/>
+<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" foo="bar"/>
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes1.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseEncryption.xml
similarity index 76%
rename from opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes1.xml
rename to opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseEncryption.xml
index dd463de..fe23428 100644
--- a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes1.xml
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseEncryption.xml
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="unspecified" foo="bar"/>
+<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="encryption"/>
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseNotPresent.xml
similarity index 85%
copy from opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
copy to opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseNotPresent.xml
index 2dfcb78..46334e7 100644
--- a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseNotPresent.xml
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="rabbit"/>
+<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" />
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseSigning.xml
similarity index 85%
copy from opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
copy to opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseSigning.xml
index 2dfcb78..12365a4 100644
--- a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseSigning.xml
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="rabbit"/>
+<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="signing"/>
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseUnspecified.xml
similarity index 82%
copy from opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
copy to opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseUnspecified.xml
index 2dfcb78..885489b 100644
--- a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseUnspecified.xml
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="rabbit"/>
+<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="unspecified"/>
diff --git a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseValueIllegal.xml
similarity index 85%
rename from opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
rename to opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseValueIllegal.xml
index 2dfcb78..6c6714e 100644
--- a/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorBadAttributes2.xml
+++ b/opensaml-saml-impl/src/test/resources/org/opensaml/saml/saml2/metadata/impl/KeyDescriptorUseValueIllegal.xml
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="rabbit"/>
+<md:KeyDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" use="foobar"/>
diff --git a/opensaml-security-api/src/main/java/org/opensaml/security/credential/UsageType.java b/opensaml-security-api/src/main/java/org/opensaml/security/credential/UsageType.java
index 073b9c2..66ac3d3 100644
--- a/opensaml-security-api/src/main/java/org/opensaml/security/credential/UsageType.java
+++ b/opensaml-security-api/src/main/java/org/opensaml/security/credential/UsageType.java
@@ -17,15 +17,39 @@
 
 package org.opensaml.security.credential;
 
+import javax.annotation.Nonnull;
+
 /** Credential usage types. */
 public enum UsageType {
     
     /** Key used for encryption processes. */
-    ENCRYPTION,
+    ENCRYPTION("encryption"),
     
     /** Key used for signature processes including TLS/SSL. */
-    SIGNING,
+    SIGNING("signing"),
     
     /** Denotes that the purpose of the key was not specified. */
-    UNSPECIFIED
+    UNSPECIFIED("unspecified");
+    
+    /** Enum string value. */
+    private String value;
+    
+    /**
+     * Constructor.
+     *
+     * @param v the enum string value
+     */
+    private UsageType(@Nonnull final String v) {
+        value = v;
+    }
+    
+    /**
+     * Get the enum string value.
+     * 
+     * @return the enum string value
+     */
+    @Nonnull public String getValue() {
+        return value;
+    }
+   
 }
\ No newline at end of file

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


More information about the commits mailing list