[java-opensaml COMMIT] in /trunk/opensaml-saml-api/src: main/java/org/opensaml/saml/common/binding/SAMLBindingSupport...

noreply at shibboleth.net noreply at shibboleth.net
Wed May 18 18:44:02 EDT 2016


Author: putmanb
Date: Wed May 18 18:44:02 2016
New Revision: 4456

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4456&view=rev
Log:
Add support method for converting SAML artifact endpoint index byte[] to int.

Added:
    trunk/opensaml-saml-api/src/test/java/org/opensaml/saml/common/
    trunk/opensaml-saml-api/src/test/java/org/opensaml/saml/common/binding/
    trunk/opensaml-saml-api/src/test/java/org/opensaml/saml/common/binding/SAMLBindingSupportTest.java   (with props)
Modified:
    trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/binding/SAMLBindingSupport.java

Modified: trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/binding/SAMLBindingSupport.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/binding/SAMLBindingSupport.java?rev=4456&r1=4455&r2=4456&view=diff
==============================================================================
--- trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/binding/SAMLBindingSupport.java	(original)
+++ trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/binding/SAMLBindingSupport.java	Wed May 18 18:44:02 2016
@@ -19,6 +19,8 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -36,10 +38,13 @@
 import org.opensaml.saml.common.messaging.context.SAMLEndpointContext;
 import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
 import org.opensaml.saml.saml2.metadata.Endpoint;
+import org.opensaml.saml.saml2.metadata.IndexedEndpoint;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Strings;
+import com.google.common.primitives.UnsignedBytes;
+import com.google.common.primitives.UnsignedInts;
 
 /** A support class for SAML binding operations. */
 public final class SAMLBindingSupport {
@@ -300,5 +305,26 @@
         
         return request.getRequestURL().toString();
     }
+    
+    /**
+     * Convert a 2-byte artifact endpoint index byte[] as typically used by SAML 2 artifact types to an integer,
+     * appropriate for use with {@link IndexedEndpoint} impls.
+     * 
+     * <p>
+     * The max input value supported is 0x7FFF (32767), which is the largest possible unsigned 16 bit value.
+     * This should be more than sufficient for typical SAML cases.
+     * </p>
+     * 
+     * @param artifactEndpointIndex the endpoint index byte array, must have length == 2, and big endian byte order.
+     * @return the convert integer value
+     */
+    @Nonnull public static int convertSAML2ArtifactEndpointIndex(@Nonnull byte[] artifactEndpointIndex) {
+        Constraint.isNotNull(artifactEndpointIndex, "Artifact endpoint index cannot be null");
+        Constraint.isTrue(artifactEndpointIndex.length == 2, "Artifact endpoint index length was not 2, was: "
+                + artifactEndpointIndex.length);
+        short value = ByteBuffer.wrap(artifactEndpointIndex).order(ByteOrder.BIG_ENDIAN).getShort();
+        return (int) Constraint.isGreaterThanOrEqual(0, value, 
+                "Input value was too large, resulting in a negative 16-bit short");
+    }
 
 }



More information about the commits mailing list